Skip to content

Commit

Permalink
Failing tests for doctrine#1487
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi-contiu committed Feb 27, 2025
1 parent fe0fcea commit 054f084
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,61 @@ public function testGenerateFromEmptySchema(): void
self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
}

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

$comparator = $this->createMock(Comparator::class);
$matcher = self::exactly(2);
$comparator->expects($matcher)
->method('compareSchemas')
->willReturnCallback(
function (Schema $oldSchema, Schema $newSchema) use ($matcher, $toTable1, $toTable2): SchemaDiff {
// assert that comparator is called with the expected schema
if ($matcher->numberOfInvocations() === 1) { // up
self::assertEquals([$toTable1, $toTable2], $newSchema->getTables());
}

if ($matcher->numberOfInvocations() === 2) { // down
self::assertEquals([$toTable1, $toTable2], $oldSchema->getTables());
}

return self::createStub(SchemaDiff::class);
}
);

$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);
}

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

0 comments on commit 054f084

Please sign in to comment.