Skip to content

Commit 054f084

Browse files
committed
Failing tests for #1487
1 parent fe0fcea commit 054f084

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/Generator/DiffGeneratorTest.php

+55
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,61 @@ public function testGenerateFromEmptySchema(): void
180180
self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
181181
}
182182

183+
public function testGenerateCallsComparatorWithExpectedSchemasWhenDbalHasSchemaAssetsFilter(): void
184+
{
185+
// a standard Regex SchemaAssetsFilter already registered on the DBAL
186+
$dbalSchemaAssetsFilter = static function ($assetName): bool {
187+
return (bool) preg_match('~^some_schema\.~', $assetName);
188+
};
189+
190+
$fromSchema = new Schema();
191+
192+
$toTable1 = new Table('some_schema.table1');
193+
$toTable2 = new Table('some_schema.table2');
194+
$toSchema = new Schema([$toTable1, $toTable2]);
195+
196+
$this->schemaManager->expects(self::once())
197+
->method('introspectSchema')
198+
->willReturn($fromSchema);
199+
200+
$this->schemaProvider->expects(self::once())
201+
->method('createSchema')
202+
->willReturn($toSchema);
203+
204+
$this->dbalConfiguration->expects(self::once())
205+
->method('getSchemaAssetsFilter')
206+
->willReturn($dbalSchemaAssetsFilter);
207+
208+
$comparator = $this->createMock(Comparator::class);
209+
$matcher = self::exactly(2);
210+
$comparator->expects($matcher)
211+
->method('compareSchemas')
212+
->willReturnCallback(
213+
function (Schema $oldSchema, Schema $newSchema) use ($matcher, $toTable1, $toTable2): SchemaDiff {
214+
// assert that comparator is called with the expected schema
215+
if ($matcher->numberOfInvocations() === 1) { // up
216+
self::assertEquals([$toTable1, $toTable2], $newSchema->getTables());
217+
}
218+
219+
if ($matcher->numberOfInvocations() === 2) { // down
220+
self::assertEquals([$toTable1, $toTable2], $oldSchema->getTables());
221+
}
222+
223+
return self::createStub(SchemaDiff::class);
224+
}
225+
);
226+
227+
$this->schemaManager->expects(self::once())
228+
->method('createComparator')
229+
->willReturn($comparator);
230+
231+
$this->migrationSqlGenerator->expects(self::exactly(2))
232+
->method('generate')
233+
->willReturnOnConsecutiveCalls('up', 'down');
234+
235+
$this->migrationDiffGenerator->generate('Version1234', null);
236+
}
237+
183238
protected function setUp(): void
184239
{
185240
$this->dbalConfiguration = $this->createMock(DBALConfiguration::class);

0 commit comments

Comments
 (0)