Skip to content

Commit ea2e620

Browse files
authored
Merge pull request #6848 from morozov/auto-increment-introspection-testing
Rework auto-increment introspection tests
2 parents d6bcc1b + a4777d3 commit ea2e620

File tree

3 files changed

+54
-48
lines changed

3 files changed

+54
-48
lines changed

tests/Functional/Schema/PostgreSQLSchemaManagerTest.php

-11
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ public function testSupportDomainTypeFallback(): void
5959
self::assertInstanceOf(MoneyType::class, $table->getColumn('value')->getType());
6060
}
6161

62-
public function testDetectsAutoIncrement(): void
63-
{
64-
$autoincTable = new Table('autoinc_table');
65-
$column = $autoincTable->addColumn('id', Types::INTEGER);
66-
$column->setAutoincrement(true);
67-
$this->dropAndCreateTable($autoincTable);
68-
$autoincTable = $this->schemaManager->introspectTable('autoinc_table');
69-
70-
self::assertTrue($autoincTable->getColumn('id')->getAutoincrement());
71-
}
72-
7362
public function testAlterTableAutoIncrementAdd(): void
7463
{
7564
$tableFrom = new Table('autoinc_table_add');

tests/Functional/Schema/SchemaManagerFunctionalTestCase.php

-37
Original file line numberDiff line numberDiff line change
@@ -693,43 +693,6 @@ public function testCreateAndListViews(): void
693693
self::assertStringContainsString('view_test_table', $filtered[0]->getSql());
694694
}
695695

696-
public function testAutoincrementDetection(): void
697-
{
698-
if (! $this->connection->getDatabasePlatform()->supportsIdentityColumns()) {
699-
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
700-
}
701-
702-
$table = new Table('test_autoincrement');
703-
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
704-
$table->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
705-
$table->setPrimaryKey(['id']);
706-
707-
$this->schemaManager->createTable($table);
708-
709-
$inferredTable = $this->schemaManager->introspectTable('test_autoincrement');
710-
self::assertTrue($inferredTable->hasColumn('id'));
711-
self::assertTrue($inferredTable->getColumn('id')->getAutoincrement());
712-
}
713-
714-
public function testAutoincrementDetectionMulticolumns(): void
715-
{
716-
if (! $this->connection->getDatabasePlatform()->supportsIdentityColumns()) {
717-
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
718-
}
719-
720-
$table = new Table('test_not_autoincrement');
721-
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
722-
$table->addColumn('id', Types::INTEGER);
723-
$table->addColumn('other_id', Types::INTEGER);
724-
$table->setPrimaryKey(['id', 'other_id']);
725-
726-
$this->schemaManager->createTable($table);
727-
728-
$inferredTable = $this->schemaManager->introspectTable('test_not_autoincrement');
729-
self::assertTrue($inferredTable->hasColumn('id'));
730-
self::assertFalse($inferredTable->getColumn('id')->getAutoincrement());
731-
}
732-
733696
public function testUpdateSchemaWithForeignKeyRenaming(): void
734697
{
735698
$table = new Table('test_fk_base');

tests/Functional/Schema/SchemaManagerTest.php

+54
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
namespace Doctrine\DBAL\Tests\Functional\Schema;
66

77
use Doctrine\DBAL\Exception;
8+
use Doctrine\DBAL\Platforms\SQLitePlatform;
89
use Doctrine\DBAL\Schema\AbstractSchemaManager;
910
use Doctrine\DBAL\Schema\Table;
1011
use Doctrine\DBAL\Tests\FunctionalTestCase;
1112
use Doctrine\DBAL\Types\Types;
13+
use PHPUnit\Framework\Attributes\TestWith;
1214

1315
final class SchemaManagerTest extends FunctionalTestCase
1416
{
@@ -95,4 +97,56 @@ public static function dataDropIndexInAnotherSchema(): iterable
9597
'reserved schema' => ['case.some_table'],
9698
];
9799
}
100+
101+
#[TestWith([false])]
102+
#[TestWith([true])]
103+
public function testAutoIncrementColumnIntrospection(bool $autoincrement): void
104+
{
105+
$platform = $this->connection->getDatabasePlatform();
106+
107+
if (! $platform->supportsIdentityColumns()) {
108+
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
109+
}
110+
111+
if (! $autoincrement && $platform instanceof SQLitePlatform) {
112+
self::markTestIncomplete('See https://github.com/doctrine/dbal/issues/6844');
113+
}
114+
115+
$table = new Table('test_autoincrement');
116+
$table->addColumn('id', Types::INTEGER, ['autoincrement' => $autoincrement]);
117+
$table->setPrimaryKey(['id']);
118+
$this->dropAndCreateTable($table);
119+
120+
$table = $this->schemaManager->introspectTable('test_autoincrement');
121+
122+
self::assertSame($autoincrement, $table->getColumn('id')->getAutoincrement());
123+
}
124+
125+
#[TestWith([false])]
126+
#[TestWith([true])]
127+
public function testAutoIncrementColumnInCompositePrimaryKeyIntrospection(bool $autoincrement): void
128+
{
129+
$platform = $this->connection->getDatabasePlatform();
130+
131+
if (! $platform->supportsIdentityColumns()) {
132+
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
133+
}
134+
135+
if ($autoincrement && $platform instanceof SQLitePlatform) {
136+
self::markTestSkipped(
137+
'SQLite does not support auto-increment columns as part of composite primary key constraint',
138+
);
139+
}
140+
141+
$table = new Table('test_autoincrement');
142+
$table->addColumn('id1', Types::INTEGER, ['autoincrement' => $autoincrement]);
143+
$table->addColumn('id2', Types::INTEGER);
144+
$table->setPrimaryKey(['id1', 'id2']);
145+
$this->dropAndCreateTable($table);
146+
147+
$table = $this->schemaManager->introspectTable('test_autoincrement');
148+
149+
self::assertSame($autoincrement, $table->getColumn('id1')->getAutoincrement());
150+
self::assertFalse($table->getColumn('id2')->getAutoincrement());
151+
}
98152
}

0 commit comments

Comments
 (0)