Skip to content

Commit bbb5b39

Browse files
committed
Generalize CustomIntrospectionTest
1 parent ebe1520 commit bbb5b39

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

tests/Functional/Schema/CustomIntrospectionTest.php

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
namespace Doctrine\DBAL\Tests\Functional\Schema;
66

7-
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
8-
use Doctrine\DBAL\Platforms\AbstractPlatform;
9-
use Doctrine\DBAL\Schema\AbstractSchemaManager;
10-
use Doctrine\DBAL\Schema\Comparator;
11-
use Doctrine\DBAL\Schema\Table;
7+
use Doctrine\DBAL\Schema\ColumnDiff;
8+
use Doctrine\DBAL\Schema\Schema;
129
use Doctrine\DBAL\Tests\Functional\Schema\Types\MoneyType;
1310
use Doctrine\DBAL\Tests\FunctionalTestCase;
1411
use Doctrine\DBAL\Types\Type;
@@ -25,33 +22,17 @@
2522
*/
2623
class CustomIntrospectionTest extends FunctionalTestCase
2724
{
28-
private AbstractSchemaManager $schemaManager;
29-
30-
private Comparator $comparator;
31-
32-
private AbstractPlatform $platform;
33-
3425
public static function setUpBeforeClass(): void
3526
{
3627
Type::addType('money', MoneyType::class);
3728
}
3829

39-
protected function setUp(): void
40-
{
41-
$this->platform = $this->connection->getDatabasePlatform();
42-
43-
if (! $this->platform instanceof AbstractMySQLPlatform) {
44-
self::markTestSkipped();
45-
}
46-
47-
$this->schemaManager = $this->connection->createSchemaManager();
48-
$this->comparator = $this->schemaManager->createComparator();
49-
}
50-
5130
public function testCustomColumnIntrospection(): void
5231
{
53-
$tableName = 'test_custom_column_introspection';
54-
$table = new Table($tableName);
32+
$tableName = 'test_custom_column_intro';
33+
$schemaManager = $this->connection->createSchemaManager();
34+
$schema = new Schema([], [], $schemaManager->createSchemaConfig());
35+
$table = $schema->createTable($tableName);
5536

5637
$table->addColumn('id', 'integer');
5738
$table->addColumn('quantity', 'decimal');
@@ -63,18 +44,20 @@ public function testCustomColumnIntrospection(): void
6344

6445
$this->dropAndCreateTable($table);
6546

66-
$onlineTable = $this->schemaManager->introspectTable($tableName);
67-
68-
$diff = $this->comparator->compareTables($table, $onlineTable);
69-
$changedCols = [];
47+
$onlineTable = $schemaManager->introspectTable($tableName);
48+
$diff = $schemaManager->createComparator()->compareTables($onlineTable, $table);
49+
$changedCols = array_map(
50+
static function (ColumnDiff $columnDiff): ?string {
51+
$column = $columnDiff->getOldColumn();
7052

71-
if (! $diff->isEmpty()) {
72-
$changedCols = array_map(static fn ($c) => $c->getOldColumnName()->getName(), $diff->getModifiedColumns());
73-
}
53+
return $column !== null ? $column->getName() : null;
54+
},
55+
$diff->getModifiedColumns(),
56+
);
7457

7558
self::assertTrue($diff->isEmpty(), sprintf(
7659
'Tables should be identical. Differences detected in %s.',
77-
implode(':', $changedCols),
60+
implode(', ', $changedCols),
7861
));
7962
}
8063
}

0 commit comments

Comments
 (0)