Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  stop using the deprecated schema synchronizer API
  • Loading branch information
xabbuh committed Aug 21, 2020
1 parent f794d67 commit 8eff8d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
18 changes: 4 additions & 14 deletions Tests/Transport/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
use Doctrine\DBAL\Statement;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
Expand All @@ -30,7 +29,6 @@ public function testGetAMessageWillChangeItsStatus()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$stmt = $this->getResultMock([
'id' => 1,
'body' => '{"message":"Hi"}',
Expand All @@ -53,7 +51,7 @@ public function testGetAMessageWillChangeItsStatus()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelope = $connection->get();
$this->assertEquals(1, $doctrineEnvelope['id']);
$this->assertEquals('{"message":"Hi"}', $doctrineEnvelope['body']);
Expand All @@ -64,7 +62,6 @@ public function testGetWithNoPendingMessageWillReturnNull()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$stmt = $this->getResultMock(false);

$queryBuilder
Expand All @@ -82,7 +79,7 @@ public function testGetWithNoPendingMessageWillReturnNull()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelope = $connection->get();
$this->assertNull($doctrineEnvelope);
}
Expand Down Expand Up @@ -155,11 +152,6 @@ private function getResultMock($expectedResult)
return $stmt;
}

private function getSchemaSynchronizerMock(): SchemaSynchronizer
{
return $this->createMock(SchemaSynchronizer::class);
}

/**
* @dataProvider buildConfigurationProvider
*/
Expand Down Expand Up @@ -264,7 +256,6 @@ public function testFind()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$id = 1;
$stmt = $this->getResultMock([
'id' => $id,
Expand All @@ -288,7 +279,7 @@ public function testFind()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelope = $connection->find($id);
$this->assertEquals(1, $doctrineEnvelope['id']);
$this->assertEquals('{"message":"Hi"}', $doctrineEnvelope['body']);
Expand All @@ -299,7 +290,6 @@ public function testFindAll()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$message1 = [
'id' => 1,
'body' => '{"message":"Hi"}',
Expand Down Expand Up @@ -335,7 +325,7 @@ public function testFindAll()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelopes = $connection->findAll();

$this->assertEquals(1, $doctrineEnvelopes[0]['id']);
Expand Down
26 changes: 23 additions & 3 deletions Transport/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function __construct(array $configuration, DBALConnection $driverConnecti
{
$this->configuration = array_replace_recursive(static::DEFAULT_OPTIONS, $configuration);
$this->driverConnection = $driverConnection;
$this->schemaSynchronizer = $schemaSynchronizer ?? new SingleDatabaseSynchronizer($this->driverConnection);
$this->schemaSynchronizer = $schemaSynchronizer;
$this->autoSetup = $this->configuration['auto_setup'];

if (null === self::$useDeprecatedConstants) {
Expand Down Expand Up @@ -248,7 +248,7 @@ public function setup(): void
$this->driverConnection->getConfiguration()->setFilterSchemaAssetsExpression(null);
}

$this->schemaSynchronizer->updateSchema($this->getSchema(), true);
$this->updateSchema();

if ($hasFilterCallback) {
$this->driverConnection->getConfiguration()->setSchemaAssetsFilter($assetFilter);
Expand Down Expand Up @@ -437,5 +437,25 @@ private function decodeEnvelopeHeaders(array $doctrineEnvelope): array

return $doctrineEnvelope;
}

private function updateSchema(): void
{
if (null !== $this->schemaSynchronizer) {
$this->schemaSynchronizer->updateSchema($this->getSchema(), true);

return;
}

$comparator = new Comparator();
$schemaDiff = $comparator->compare($this->driverConnection->getSchemaManager()->createSchema(), $this->getSchema());

foreach ($schemaDiff->toSaveSql($this->driverConnection->getDatabasePlatform()) as $sql) {
if (method_exists($this->driverConnection, 'executeStatement')) {
$this->driverConnection->executeStatement($sql);
} else {
$this->driverConnection->exec($sql);
}
}
}
}
class_alias(Connection::class, \Symfony\Component\Messenger\Transport\Doctrine\Connection::class);

0 comments on commit 8eff8d2

Please sign in to comment.