Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi-contiu committed Feb 28, 2025
1 parent fe0fcea commit aaff3f4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use function array_values;
use function preg_match;

class DiffGeneratorTest extends TestCase
{
private DBALConfiguration&MockObject $dbalConfiguration;
Expand Down Expand Up @@ -180,6 +183,51 @@ public function testGenerateFromEmptySchema(): void
self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
}

public function testGenerateAppliesDbalSchemaAssetsFilterOnQualifiedTableName(): void
{
// a standard Regex SchemaAssetsFilter already registered on the DBAL
$dbalSchemaAssetsFilter = static function ($assetName): bool {
return (bool) preg_match('~^some_schema\.~', $assetName);
};

$fromSchema = new Schema();

$toTable1 = new Table('some_schema.table1');
$toTable2 = new Table('some_schema.table2');
$toSchema = new Schema([$toTable1, $toTable2]);

$this->platform->expects(self::atLeast(2))
->method('supportsSchemas')
->willReturn(true);

$this->schemaManager->expects(self::once())
->method('introspectSchema')
->willReturn($fromSchema);

$this->schemaProvider->expects(self::once())
->method('createSchema')
->willReturn($toSchema);

$this->dbalConfiguration->expects(self::once())
->method('getSchemaAssetsFilter')
->willReturn($dbalSchemaAssetsFilter);

$schemaDiff = self::createStub(SchemaDiff::class);
$comparator = $this->mockComparator($schemaDiff);

$this->schemaManager->expects(self::once())
->method('createComparator')
->willReturn($comparator);

$this->migrationSqlGenerator->expects(self::exactly(2))
->method('generate')
->willReturnOnConsecutiveCalls('up', 'down');

$this->migrationDiffGenerator->generate('Version1234', null);

self::assertEquals([$toTable1, $toTable2], array_values($toSchema->getTables()));
}

protected function setUp(): void
{
$this->dbalConfiguration = $this->createMock(DBALConfiguration::class);
Expand Down

0 comments on commit aaff3f4

Please sign in to comment.