Skip to content

Commit

Permalink
Generalize CustomIntrospectionTest (#6210)
Browse files Browse the repository at this point in the history
|      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.
  • Loading branch information
derrabus committed Nov 5, 2023
1 parent ebe1520 commit c86e909
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions tests/Functional/Schema/CustomIntrospectionTest.php
Expand Up @@ -4,13 +4,11 @@

namespace Doctrine\DBAL\Tests\Functional\Schema;

use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Tests\Functional\Schema\Types\MoneyType;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\Type;

use function array_map;
Expand All @@ -25,33 +23,21 @@
*/
class CustomIntrospectionTest extends FunctionalTestCase
{
private AbstractSchemaManager $schemaManager;

private Comparator $comparator;

private AbstractPlatform $platform;

public static function setUpBeforeClass(): void
{
Type::addType('money', MoneyType::class);
}

protected function setUp(): void
{
$this->platform = $this->connection->getDatabasePlatform();

if (! $this->platform instanceof AbstractMySQLPlatform) {
self::markTestSkipped();
if (TestUtil::isDriverOneOf('oci8', 'pdo_oci')) {
self::markTestSkipped('Skip on Oracle');
}

$this->schemaManager = $this->connection->createSchemaManager();
$this->comparator = $this->schemaManager->createComparator();
Type::addType('money', MoneyType::class);
}

public function testCustomColumnIntrospection(): void
{
$tableName = 'test_custom_column_introspection';
$table = new Table($tableName);
$tableName = 'test_custom_column_introspection';
$schemaManager = $this->connection->createSchemaManager();
$schema = new Schema([], [], $schemaManager->createSchemaConfig());
$table = $schema->createTable($tableName);

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

$this->dropAndCreateTable($table);

$onlineTable = $this->schemaManager->introspectTable($tableName);
$onlineTable = $schemaManager->introspectTable($tableName);
$diff = $schemaManager->createComparator()->compareTables($onlineTable, $table);
$changedCols = array_map(
static function (ColumnDiff $columnDiff): ?string {
$column = $columnDiff->getOldColumn();

$diff = $this->comparator->compareTables($table, $onlineTable);
$changedCols = [];

if (! $diff->isEmpty()) {
$changedCols = array_map(static fn ($c) => $c->getOldColumnName()->getName(), $diff->getModifiedColumns());
}
return $column !== null ? $column->getName() : null;
},
$diff->getModifiedColumns(),
);

self::assertTrue($diff->isEmpty(), sprintf(
'Tables should be identical. Differences detected in %s.',
implode(':', $changedCols),
implode(', ', $changedCols),
));
}
}

0 comments on commit c86e909

Please sign in to comment.