Skip to content

Commit c86e909

Browse files
authored
Generalize CustomIntrospectionTest (#6210)
| Q | A |------------- | ----------- | Type | improvement | Fixed issues | Follows #6189 #### Summary This PR improves the test added in #6189 by allowing it to run on other platforms than MySQL/MariaDB and by using non-deprecated APIs only. This should make it easier to merge this test and later changes to it up to the 4.0.x branch. I've skipped Oracle though because I currently don't have a local Oracle setup to test against.
1 parent ebe1520 commit c86e909

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

tests/Functional/Schema/CustomIntrospectionTest.php

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
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;
11+
use Doctrine\DBAL\Tests\TestUtil;
1412
use Doctrine\DBAL\Types\Type;
1513

1614
use function array_map;
@@ -25,33 +23,21 @@
2523
*/
2624
class CustomIntrospectionTest extends FunctionalTestCase
2725
{
28-
private AbstractSchemaManager $schemaManager;
29-
30-
private Comparator $comparator;
31-
32-
private AbstractPlatform $platform;
33-
3426
public static function setUpBeforeClass(): void
3527
{
36-
Type::addType('money', MoneyType::class);
37-
}
38-
39-
protected function setUp(): void
40-
{
41-
$this->platform = $this->connection->getDatabasePlatform();
42-
43-
if (! $this->platform instanceof AbstractMySQLPlatform) {
44-
self::markTestSkipped();
28+
if (TestUtil::isDriverOneOf('oci8', 'pdo_oci')) {
29+
self::markTestSkipped('Skip on Oracle');
4530
}
4631

47-
$this->schemaManager = $this->connection->createSchemaManager();
48-
$this->comparator = $this->schemaManager->createComparator();
32+
Type::addType('money', MoneyType::class);
4933
}
5034

5135
public function testCustomColumnIntrospection(): void
5236
{
53-
$tableName = 'test_custom_column_introspection';
54-
$table = new Table($tableName);
37+
$tableName = 'test_custom_column_introspection';
38+
$schemaManager = $this->connection->createSchemaManager();
39+
$schema = new Schema([], [], $schemaManager->createSchemaConfig());
40+
$table = $schema->createTable($tableName);
5541

5642
$table->addColumn('id', 'integer');
5743
$table->addColumn('quantity', 'decimal');
@@ -63,18 +49,20 @@ public function testCustomColumnIntrospection(): void
6349

6450
$this->dropAndCreateTable($table);
6551

66-
$onlineTable = $this->schemaManager->introspectTable($tableName);
52+
$onlineTable = $schemaManager->introspectTable($tableName);
53+
$diff = $schemaManager->createComparator()->compareTables($onlineTable, $table);
54+
$changedCols = array_map(
55+
static function (ColumnDiff $columnDiff): ?string {
56+
$column = $columnDiff->getOldColumn();
6757

68-
$diff = $this->comparator->compareTables($table, $onlineTable);
69-
$changedCols = [];
70-
71-
if (! $diff->isEmpty()) {
72-
$changedCols = array_map(static fn ($c) => $c->getOldColumnName()->getName(), $diff->getModifiedColumns());
73-
}
58+
return $column !== null ? $column->getName() : null;
59+
},
60+
$diff->getModifiedColumns(),
61+
);
7462

7563
self::assertTrue($diff->isEmpty(), sprintf(
7664
'Tables should be identical. Differences detected in %s.',
77-
implode(':', $changedCols),
65+
implode(', ', $changedCols),
7866
));
7967
}
8068
}

0 commit comments

Comments
 (0)