|
18 | 18 | use PHPUnit\Framework\MockObject\MockObject;
|
19 | 19 | use PHPUnit\Framework\TestCase;
|
20 | 20 |
|
| 21 | +use function array_map; |
| 22 | +use function array_values; |
| 23 | +use function preg_match; |
| 24 | + |
21 | 25 | class DiffGeneratorTest extends TestCase
|
22 | 26 | {
|
23 | 27 | private DBALConfiguration&MockObject $dbalConfiguration;
|
@@ -180,6 +184,49 @@ public function testGenerateFromEmptySchema(): void
|
180 | 184 | self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
|
181 | 185 | }
|
182 | 186 |
|
| 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 | + |
183 | 230 | protected function setUp(): void
|
184 | 231 | {
|
185 | 232 | $this->dbalConfiguration = $this->createMock(DBALConfiguration::class);
|
|
0 commit comments