Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3.8 -> 4.0 merge #7

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Schema/SQLiteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function listTableForeignKeys(string $table): array
{
$table = $this->normalizeName($table);

$columns = $this->selectForeignKeyColumns($database ?? 'main', $table)
$columns = $this->selectForeignKeyColumns('main', $table)
->fetchAllAssociative();

if (count($columns) > 0) {
Expand Down
27 changes: 14 additions & 13 deletions tests/Functional/Schema/SqliteSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

use function array_keys;
use function array_shift;

class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
Expand Down Expand Up @@ -207,24 +210,22 @@ public function testNonSimpleAlterTableCreatedFromDDL(): void
self::assertSame(['name'], $index->getColumns());
}

public function testGeneratesAlterTableRenameColumnSQLWithSchema(): void
public function testAlterTableWithSchema(): void
{
$this->platform->disableSchemaEmulation();
$this->dropTableIfExists('t');

$table = new Table('main.t');
$table->addColumn('a', Types::INTEGER);
$this->schemaManager->createTable($table);

$tableDiff = new TableDiff('t');
$tableDiff->fromTable = $table;
$tableDiff->renamedColumns['a'] = new Column('b', Type::getType(Types::INTEGER));

self::assertSame([
'CREATE TEMPORARY TABLE __temp__t AS SELECT a FROM main.t',
'DROP TABLE main.t',
'CREATE TABLE main.t (b INTEGER NOT NULL)',
'INSERT INTO main.t (b) SELECT a FROM __temp__t',
'DROP TABLE __temp__t',
], $this->platform->getAlterTableSQL($tableDiff));
self::assertSame(['a'], array_keys($this->schemaManager->listTableColumns('t')));

$tableDiff = new TableDiff($table, [], [], [], [
'a' => new Column('b', Type::getType(Types::INTEGER)),
], [], [], [], [], [], [], []);
$this->schemaManager->alterTable($tableDiff);

self::assertSame(['b'], array_keys($this->schemaManager->listTableColumns('t')));
}

public function testIntrospectMultipleAnonymousForeignKeyConstraints(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/Platforms/SQLitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ public function testGeneratesAlterTableRenameColumnSQLWithSchema(): void
$table = new Table('main.t');
$table->addColumn('a', Types::INTEGER);

$tableDiff = new TableDiff('t');
$tableDiff->fromTable = $table;
$tableDiff->renamedColumns['a'] = new Column('b', Type::getType(Types::INTEGER));
$tableDiff = new TableDiff($table, [], [], [], [
'a' => new Column('b', Type::getType(Types::INTEGER)),
], [], [], [], [], [], [], []);

self::assertSame([
'CREATE TEMPORARY TABLE __temp__t AS SELECT a FROM main.t',
Expand Down
24 changes: 24 additions & 0 deletions tests/Schema/SQLiteSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\SQLiteSchemaManager;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -202,4 +203,27 @@ public static function getDataColumnComment(): iterable
],
];
}

/**
* TODO move to functional test once SqliteSchemaManager::selectForeignKeyColumns can honor database/schema name
* https://github.com/doctrine/dbal/blob/3.8.3/src/Schema/SqliteSchemaManager.php#L740
*/
public function testListTableForeignKeysDefaultDatabasePassing(): void
{
$conn = $this->createMock(Connection::class);

$manager = new class ($conn, new SQLitePlatform()) extends SQLiteSchemaManager {
public static string $passedDatabaseName;

protected function selectForeignKeyColumns(string $databaseName, ?string $tableName = null): Result
{
self::$passedDatabaseName = $databaseName;

return parent::selectForeignKeyColumns($databaseName, $tableName);
}
};

$manager->listTableForeignKeys('t');
self::assertSame('main', $manager::$passedDatabaseName);
}
}
Loading