Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi-contiu committed Feb 27, 2025
1 parent fadaf5a commit 7e79213
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use function array_values;
use function preg_match;

class DiffGeneratorTest extends TestCase
Expand Down Expand Up @@ -195,7 +196,7 @@ public function testGenerateCallsComparatorWithExpectedSchemasWhenDbalHasSchemaA
$toTable2 = new Table('some_schema.table2');
$toSchema = new Schema([$toTable1, $toTable2]);

$this->platform->expects(self::exactly(3))
$this->platform->expects(self::atLeast(2))
->method('supportsSchemas')
->willReturn(true);

Expand All @@ -211,24 +212,8 @@ public function testGenerateCallsComparatorWithExpectedSchemasWhenDbalHasSchemaA
->method('getSchemaAssetsFilter')
->willReturn($dbalSchemaAssetsFilter);

$comparator = $this->createMock(Comparator::class);
$matcher = self::exactly(2);
$comparator->expects($matcher)
->method('compareSchemas')
->willReturnCallback(
static function (Schema $oldSchema, Schema $newSchema) use ($matcher, $toTable1, $toTable2): SchemaDiff {
// assert that comparator is called with the expected schema
if ($matcher->numberOfInvocations() === 1) { // up
self::assertEquals([$toTable1, $toTable2], $newSchema->getTables());
}

if ($matcher->numberOfInvocations() === 2) { // down
self::assertEquals([$toTable1, $toTable2], $oldSchema->getTables());
}

return self::createStub(SchemaDiff::class);
},
);
$schemaDiff = self::createStub(SchemaDiff::class);
$comparator = $this->mockComparator($schemaDiff);

$this->schemaManager->expects(self::once())
->method('createComparator')
Expand All @@ -239,6 +224,8 @@ static function (Schema $oldSchema, Schema $newSchema) use ($matcher, $toTable1,
->willReturnOnConsecutiveCalls('up', 'down');

$this->migrationDiffGenerator->generate('Version1234', null);

self::assertEquals([$toTable1, $toTable2], array_values($toSchema->getTables()));
}

protected function setUp(): void
Expand Down

0 comments on commit 7e79213

Please sign in to comment.