Skip to content

Commit a76ce4d

Browse files
committed
Issue #1487
1 parent fe0fcea commit a76ce4d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/Generator/DiffGeneratorTest.php

+47
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
use PHPUnit\Framework\MockObject\MockObject;
1919
use PHPUnit\Framework\TestCase;
2020

21+
use function array_map;
22+
use function array_values;
23+
use function preg_match;
24+
2125
class DiffGeneratorTest extends TestCase
2226
{
2327
private DBALConfiguration&MockObject $dbalConfiguration;
@@ -180,6 +184,49 @@ public function testGenerateFromEmptySchema(): void
180184
self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
181185
}
182186

187+
public function testGenerateAppliesFilterOnMappedSchema(): void
188+
{
189+
// a standard Regex SchemaAssetsFilter already registered on the DBAL
190+
$dbalSchemaAssetsFilter = static function ($assetName): bool {
191+
return (bool) preg_match('~^some_schema~', $assetName);
192+
};
193+
194+
$fromSchema = new Schema();
195+
196+
$toTable1 = new Table('some_schema.table1');
197+
$toTable2 = new Table('some_schema.table2');
198+
$toSchema = new Schema([$toTable1, $toTable2]);
199+
200+
$this->schemaManager->expects(self::once())
201+
->method('introspectSchema')
202+
->willReturn($fromSchema);
203+
204+
$this->schemaProvider->expects(self::once())
205+
->method('createSchema')
206+
->willReturn($toSchema);
207+
208+
$this->dbalConfiguration->expects(self::once())
209+
->method('getSchemaAssetsFilter')
210+
->willReturn($dbalSchemaAssetsFilter);
211+
212+
$schemaDiff = self::createStub(SchemaDiff::class);
213+
$comparator = $this->mockComparator($schemaDiff);
214+
215+
$this->schemaManager->expects(self::once())
216+
->method('createComparator')
217+
->willReturn($comparator);
218+
219+
$this->migrationSqlGenerator->expects(self::exactly(2))
220+
->method('generate')
221+
->willReturnOnConsecutiveCalls('up', 'down');
222+
223+
$this->migrationDiffGenerator->generate('Version1234', null);
224+
225+
$filteredTableNames = array_map(static fn (Table $table) => $table->getName(), $toSchema->getTables());
226+
227+
self::assertSame(['some_schema.table1', 'some_schema.table2'], array_values($filteredTableNames));
228+
}
229+
183230
protected function setUp(): void
184231
{
185232
$this->dbalConfiguration = $this->createMock(DBALConfiguration::class);

0 commit comments

Comments
 (0)