Skip to content

Commit 4ab7e80

Browse files
committed
Issue #1487
1 parent fe0fcea commit 4ab7e80

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/Generator/DiffGeneratorTest.php

+51
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,53 @@ 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->platform->expects(self::atLeast(2))
201+
->method('supportsSchemas')
202+
->willReturn(true);
203+
204+
$this->schemaManager->expects(self::once())
205+
->method('introspectSchema')
206+
->willReturn($fromSchema);
207+
208+
$this->schemaProvider->expects(self::once())
209+
->method('createSchema')
210+
->willReturn($toSchema);
211+
212+
$this->dbalConfiguration->expects(self::once())
213+
->method('getSchemaAssetsFilter')
214+
->willReturn($dbalSchemaAssetsFilter);
215+
216+
$schemaDiff = self::createStub(SchemaDiff::class);
217+
$comparator = $this->mockComparator($schemaDiff);
218+
219+
$this->schemaManager->expects(self::once())
220+
->method('createComparator')
221+
->willReturn($comparator);
222+
223+
$this->migrationSqlGenerator->expects(self::exactly(2))
224+
->method('generate')
225+
->willReturnOnConsecutiveCalls('up', 'down');
226+
227+
$this->migrationDiffGenerator->generate('Version1234', null);
228+
229+
$filteredTableNames = array_map(static fn (Table $table) => $table->getName(), $toSchema->getTables());
230+
231+
self::assertSame(['some_schema.table1', 'some_schema.table2'], array_values($filteredTableNames));
232+
}
233+
183234
protected function setUp(): void
184235
{
185236
$this->dbalConfiguration = $this->createMock(DBALConfiguration::class);

0 commit comments

Comments
 (0)