1818use PHPUnit \Framework \MockObject \MockObject ;
1919use PHPUnit \Framework \TestCase ;
2020
21+ use function array_map ;
22+ use function array_values ;
23+ use function preg_match ;
24+
2125class DiffGeneratorTest extends TestCase
2226{
2327 private DBALConfiguration &MockObject $ dbalConfiguration ;
@@ -43,7 +47,7 @@ public function testGenerate(): void
4347 $ this ->dbalConfiguration ->expects (self ::once ())
4448 ->method ('getSchemaAssetsFilter ' )
4549 ->willReturn (
46- static fn ($ name ): bool => $ name === 'table_name1 ' ,
50+ static fn ($ name ): bool => $ name === 'schema. table_name1 ' ,
4751 );
4852
4953 $ table1 = $ this ->createMock (Table::class);
@@ -181,6 +185,49 @@ public function testGenerateFromEmptySchema(): void
181185 self ::assertSame ('path2 ' , $ this ->migrationDiffGenerator ->generate ('2345 ' , null , false , false , 120 , true , true ));
182186 }
183187
188+ public function testGenerateAppliesFilterOnMappedSchema (): void
189+ {
190+ // a standard Regex SchemaAssetsFilter already registered on the DBAL
191+ $ dbalSchemaAssetsFilter = static function ($ assetName ): bool {
192+ return (bool ) preg_match ('~^some_schema~ ' , $ assetName );
193+ };
194+
195+ $ fromSchema = new Schema ();
196+
197+ $ toTable1 = new Table ('some_schema.table1 ' );
198+ $ toTable2 = new Table ('some_schema.table2 ' );
199+ $ toSchema = new Schema ([$ toTable1 , $ toTable2 ]);
200+
201+ $ this ->schemaManager ->expects (self ::once ())
202+ ->method ('introspectSchema ' )
203+ ->willReturn ($ fromSchema );
204+
205+ $ this ->schemaProvider ->expects (self ::once ())
206+ ->method ('createSchema ' )
207+ ->willReturn ($ toSchema );
208+
209+ $ this ->dbalConfiguration ->expects (self ::once ())
210+ ->method ('getSchemaAssetsFilter ' )
211+ ->willReturn ($ dbalSchemaAssetsFilter );
212+
213+ $ schemaDiff = self ::createStub (SchemaDiff::class);
214+ $ comparator = $ this ->mockComparator ($ schemaDiff );
215+
216+ $ this ->schemaManager ->expects (self ::once ())
217+ ->method ('createComparator ' )
218+ ->willReturn ($ comparator );
219+
220+ $ this ->migrationSqlGenerator ->expects (self ::exactly (2 ))
221+ ->method ('generate ' )
222+ ->willReturnOnConsecutiveCalls ('up ' , 'down ' );
223+
224+ $ this ->migrationDiffGenerator ->generate ('Version1234 ' , null );
225+
226+ $ filteredTableNames = array_map (static fn (Table $ table ) => $ table ->getName (), $ toSchema ->getTables ());
227+
228+ self ::assertSame (['some_schema.table1 ' , 'some_schema.table2 ' ], array_values ($ filteredTableNames ));
229+ }
230+
184231 protected function setUp (): void
185232 {
186233 $ this ->dbalConfiguration = $ this ->createMock (DBALConfiguration::class);
0 commit comments