Skip to content

Rework auto-increment introspection tests #6848

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

Merged
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
11 changes: 0 additions & 11 deletions tests/Functional/Schema/PostgreSQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ public function testSupportDomainTypeFallback(): void
self::assertInstanceOf(MoneyType::class, $table->getColumn('value')->getType());
}

public function testDetectsAutoIncrement(): void
{
$autoincTable = new Table('autoinc_table');
$column = $autoincTable->addColumn('id', Types::INTEGER);
$column->setAutoincrement(true);
$this->dropAndCreateTable($autoincTable);
$autoincTable = $this->schemaManager->introspectTable('autoinc_table');

self::assertTrue($autoincTable->getColumn('id')->getAutoincrement());
}

public function testAlterTableAutoIncrementAdd(): void
{
$tableFrom = new Table('autoinc_table_add');
Expand Down
37 changes: 0 additions & 37 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,43 +693,6 @@ public function testCreateAndListViews(): void
self::assertStringContainsString('view_test_table', $filtered[0]->getSql());
}

public function testAutoincrementDetection(): void
{
if (! $this->connection->getDatabasePlatform()->supportsIdentityColumns()) {
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

$table = new Table('test_autoincrement');
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
$table->setPrimaryKey(['id']);

$this->schemaManager->createTable($table);

$inferredTable = $this->schemaManager->introspectTable('test_autoincrement');
self::assertTrue($inferredTable->hasColumn('id'));
self::assertTrue($inferredTable->getColumn('id')->getAutoincrement());
}

public function testAutoincrementDetectionMulticolumns(): void
{
if (! $this->connection->getDatabasePlatform()->supportsIdentityColumns()) {
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

$table = new Table('test_not_autoincrement');
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table->addColumn('id', Types::INTEGER);
$table->addColumn('other_id', Types::INTEGER);
$table->setPrimaryKey(['id', 'other_id']);

$this->schemaManager->createTable($table);

$inferredTable = $this->schemaManager->introspectTable('test_not_autoincrement');
self::assertTrue($inferredTable->hasColumn('id'));
self::assertFalse($inferredTable->getColumn('id')->getAutoincrement());
}

public function testUpdateSchemaWithForeignKeyRenaming(): void
{
$table = new Table('test_fk_base');
Expand Down
54 changes: 54 additions & 0 deletions tests/Functional/Schema/SchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Doctrine\DBAL\Tests\Functional\Schema;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\Attributes\TestWith;

final class SchemaManagerTest extends FunctionalTestCase
{
Expand Down Expand Up @@ -95,4 +97,56 @@ public static function dataDropIndexInAnotherSchema(): iterable
'reserved schema' => ['case.some_table'],
];
}

#[TestWith([false])]
#[TestWith([true])]
public function testAutoIncrementColumnIntrospection(bool $autoincrement): void
{
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsIdentityColumns()) {
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

if (! $autoincrement && $platform instanceof SQLitePlatform) {
self::markTestIncomplete('See https://github.com/doctrine/dbal/issues/6844');
}

$table = new Table('test_autoincrement');
$table->addColumn('id', Types::INTEGER, ['autoincrement' => $autoincrement]);
$table->setPrimaryKey(['id']);
$this->dropAndCreateTable($table);

$table = $this->schemaManager->introspectTable('test_autoincrement');

self::assertSame($autoincrement, $table->getColumn('id')->getAutoincrement());
}

#[TestWith([false])]
#[TestWith([true])]
public function testAutoIncrementColumnInCompositePrimaryKeyIntrospection(bool $autoincrement): void
{
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsIdentityColumns()) {
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

if ($autoincrement && $platform instanceof SQLitePlatform) {
self::markTestSkipped(
'SQLite does not support auto-increment columns as part of composite primary key constraint',
);
}

$table = new Table('test_autoincrement');
$table->addColumn('id1', Types::INTEGER, ['autoincrement' => $autoincrement]);
$table->addColumn('id2', Types::INTEGER);
$table->setPrimaryKey(['id1', 'id2']);
$this->dropAndCreateTable($table);

$table = $this->schemaManager->introspectTable('test_autoincrement');

self::assertSame($autoincrement, $table->getColumn('id1')->getAutoincrement());
self::assertFalse($table->getColumn('id2')->getAutoincrement());
}
}