Skip to content

Commit

Permalink
Mock comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
wmouwen committed Mar 18, 2024
1 parent c946ff3 commit 2cd0397
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/Tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Cache\CacheFactory;
use Doctrine\ORM\Cache\DefaultCacheFactory;
Expand Down Expand Up @@ -156,6 +159,8 @@ private function createPlatformMock(): AbstractPlatform
$schemaManager = $this->createMock(AbstractSchemaManager::class);
$schemaManager->method('createSchemaConfig')
->willReturn(new SchemaConfig());
$schemaManager->method('createComparator')
->willReturn($this->mockComparator(new SchemaDiff()));

$platform = $this->getMockBuilder(AbstractPlatform::class)
->onlyMethods(['supportsIdentityColumns', 'createSchemaManager'])
Expand All @@ -168,6 +173,22 @@ private function createPlatformMock(): AbstractPlatform
return $platform;
}

private function mockComparator(SchemaDiff $schemaDiff): Comparator
{
$comparator = new class (self::createStub(AbstractPlatform::class)) extends Comparator {
public static SchemaDiff $schemaDiff;

public function compareSchemas(Schema $oldSchema, Schema $newSchema): SchemaDiff
{
return self::$schemaDiff;
}
};

$comparator::$schemaDiff = $schemaDiff;

return $comparator;
}

private function createDriverMock(AbstractPlatform $platform): Driver
{
$result = $this->createMock(Result::class);
Expand Down

0 comments on commit 2cd0397

Please sign in to comment.