Skip to content

Commit

Permalink
Test column diff on all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
bigfoot90 committed Mar 26, 2024
1 parent c48fdd9 commit 29f5dcb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/Types/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Doctrine\DBAL\Types\Exception\InvalidType;
use Doctrine\DBAL\Types\Exception\ValueNotConvertible;
use ReflectionClass;
use StringBackedEnum;
use Throwable;
use UnitEnum;

Expand Down
9 changes: 9 additions & 0 deletions tests/Functional/Schema/ComparatorTestUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public static function diffFromDesiredToActualTable(
);
}

public static function assertNoDiffDetected(Connection $connection, Comparator $comparator, Table $table): void
{
$schemaManager = $connection->createSchemaManager();

$diff = self::diffFromActualToDesiredTable($schemaManager, $comparator, $table);

TestCase::assertTrue($diff->isEmpty());
}

public static function assertDiffNotEmpty(Connection $connection, Comparator $comparator, Table $table): void
{
$schemaManager = $connection->createSchemaManager();
Expand Down
31 changes: 3 additions & 28 deletions tests/Functional/Schema/MySQL/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\Functional\Schema\ComparatorTestUtils;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\Types\EnumObject;
use Doctrine\DBAL\Tests\Types\EnumNative;
use Doctrine\DBAL\Tests\Types\EnumNativeBacked;
use Doctrine\DBAL\Types\EnumType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\Attributes\DataProvider;

Expand Down Expand Up @@ -220,36 +215,16 @@ public function testMariaDb1043NativeJsonUpgradeDetected(): void
ComparatorTestUtils::assertDiffNotEmpty($this->connection, $this->comparator, $table);
}

public function testEnumDiffEmpty(): void
{
if (! $this->platform instanceof MySQLPlatform) {
self::markTestSkipped();
}

$table = new Table('enum_test_table');

$table->addColumn('enum_col', Types::ENUM, ['members' => ['a', 'b']]);
$this->dropAndCreateTable($table);

// Revert column to previous ENUM declaration
$sql = 'ALTER TABLE enum_test_table CHANGE enum_col enum_col ENUM(\'a\', \'b\') NOT NULL';
$this->connection->executeStatement($sql);

ComparatorTestUtils::assertDiffNotEmpty($this->connection, $this->comparator, $table);
}

public function testEnumDiffDetected(): void
{
if (! $this->platform instanceof MySQLPlatform) {
self::markTestSkipped();
}

$table = new Table('enum_test_table');

$table->addColumn('enum_col', Types::ENUM, ['members' => ['a', 'b']]);
$this->dropAndCreateTable($table);

// Revert column to previous ENUM declaration
ComparatorTestUtils::assertNoDiffDetected($this->connection, $this->comparator, $table);

// Alter column to previous state and check diff
$sql = 'ALTER TABLE enum_test_table CHANGE enum_col enum_col ENUM(\'NOT_A_MEMBER_ANYMORE\') NOT NULL';
$this->connection->executeStatement($sql);

Expand Down
16 changes: 16 additions & 0 deletions tests/Functional/Schema/Oracle/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,20 @@ public function testChangeBinaryColumnFixed(): void
$table,
)->isEmpty());
}

public function testEnumDiffDetected(): void
{
$table = new Table('enum_test_table');

$table->addColumn('enum_col', Types::ENUM, ['members' => ['a', 'b']]);
$this->dropAndCreateTable($table);

ComparatorTestUtils::assertNoDiffDetected($this->connection, $this->comparator, $table);

// Alter column to previous state and check diff
$sql = 'ALTER TABLE enum_test_table CHANGE enum_col enum_col ENUM(\'NOT_A_MEMBER_ANYMORE\') NOT NULL';
$this->connection->executeStatement($sql);

ComparatorTestUtils::assertDiffNotEmpty($this->connection, $this->comparator, $table);
}
}
16 changes: 16 additions & 0 deletions tests/Functional/Schema/PostgreSQL/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,20 @@ private function testColumnModification(callable $addColumn, callable $modifyCol
$table,
)->isEmpty());
}

public function testEnumDiffDetected(): void
{
$table = new Table('enum_test_table');

$table->addColumn('enum_col', Types::ENUM, ['members' => ['a', 'b']]);
$this->dropAndCreateTable($table);

ComparatorTestUtils::assertNoDiffDetected($this->connection, $this->comparator, $table);

// Alter column to previous state and check diff
$sql = 'ALTER TABLE enum_test_table CHANGE enum_col enum_col ENUM(\'NOT_A_MEMBER_ANYMORE\') NOT NULL';
$this->connection->executeStatement($sql);

ComparatorTestUtils::assertDiffNotEmpty($this->connection, $this->comparator, $table);
}
}
16 changes: 16 additions & 0 deletions tests/Functional/Schema/SQLite/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ public function testChangeTableCollation(): void
$column->setPlatformOption('collation', 'NOCASE');
ComparatorTestUtils::assertDiffNotEmpty($this->connection, $this->comparator, $table);
}

public function testEnumDiffDetected(): void
{
$table = new Table('enum_test_table');

$table->addColumn('enum_col', Types::ENUM, ['members' => ['a', 'b']]);
$this->dropAndCreateTable($table);

ComparatorTestUtils::assertNoDiffDetected($this->connection, $this->comparator, $table);

// Alter column to previous state and check diff
$sql = 'ALTER TABLE enum_test_table ALTER COLUMN enum_col enum_col ENUM(\'NOT_A_MEMBER_ANYMORE\') NOT NULL';
$this->connection->executeStatement($sql);

ComparatorTestUtils::assertDiffNotEmpty($this->connection, $this->comparator, $table);
}
}

0 comments on commit 29f5dcb

Please sign in to comment.