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 a938f5f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use function array_map;
use function array_values;
use function preg_match;

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

public function testGenerateAppliesFilterOnMappedSchema(): 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->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);

$filteredTableNames = array_map(static fn (Table $table) => $table->getName(), $toSchema->getTables());

self::assertSame(['some_schema.table1', 'some_schema.table2'], array_values($filteredTableNames));
}

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

0 comments on commit a938f5f

Please sign in to comment.