|
5 | 5 | namespace Doctrine\DBAL\Tests\Functional\Schema;
|
6 | 6 |
|
7 | 7 | use Doctrine\DBAL\Exception;
|
| 8 | +use Doctrine\DBAL\Platforms\SQLitePlatform; |
8 | 9 | use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
9 | 10 | use Doctrine\DBAL\Schema\Table;
|
10 | 11 | use Doctrine\DBAL\Tests\FunctionalTestCase;
|
11 | 12 | use Doctrine\DBAL\Types\Types;
|
| 13 | +use PHPUnit\Framework\Attributes\TestWith; |
12 | 14 |
|
13 | 15 | final class SchemaManagerTest extends FunctionalTestCase
|
14 | 16 | {
|
@@ -95,4 +97,56 @@ public static function dataDropIndexInAnotherSchema(): iterable
|
95 | 97 | 'reserved schema' => ['case.some_table'],
|
96 | 98 | ];
|
97 | 99 | }
|
| 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 | + } |
98 | 152 | }
|
0 commit comments