Skip to content

Commit

Permalink
Merge branch '4.4' into 5.3
Browse files Browse the repository at this point in the history
* 4.4:
  Fix tests failing with DBAL 3

Signed-off-by: Alexander M. Turek <[email protected]>
  • Loading branch information
derrabus committed Sep 1, 2021
1 parent 3d7d247 commit e11b875
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Tests/Transport/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ private function getDBALConnectionMock()
$schemaConfig->method('getMaxIdentifierLength')->willReturn(63);
$schemaConfig->method('getDefaultTableOptions')->willReturn([]);
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
if (method_exists(DBALConnection::class, 'createSchemaManager')) {
$driverConnection->method('createSchemaManager')->willReturn($schemaManager);
} else {
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
}

return $driverConnection;
}
Expand Down Expand Up @@ -430,7 +434,11 @@ public function testSetupIndices(string $platformClass, array $expectedIndices)
$expectedTable->addIndex($indexColumns);
}
$schemaManager->method('createSchema')->willReturn($schema);
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
if (method_exists(DBALConnection::class, 'createSchemaManager')) {
$driverConnection->method('createSchemaManager')->willReturn($schemaManager);
} else {
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
}

$platformMock = $this->createMock($platformClass);
$platformMock
Expand Down
10 changes: 9 additions & 1 deletion Tests/Transport/DoctrineIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
Expand Down Expand Up @@ -175,7 +176,7 @@ public function testItRetrieveTheMessageThatIsOlderThanRedeliverTimeout()

public function testTheTransportIsSetupOnGet()
{
$this->assertFalse($this->driverConnection->getSchemaManager()->tablesExist('messenger_messages'));
$this->assertFalse($this->createSchemaManager()->tablesExist('messenger_messages'));
$this->assertNull($this->connection->get());

$this->connection->send('the body', ['my' => 'header']);
Expand All @@ -187,4 +188,11 @@ private function formatDateTime(\DateTime $dateTime)
{
return $dateTime->format($this->driverConnection->getDatabasePlatform()->getDateTimeFormatString());
}

private function createSchemaManager(): AbstractSchemaManager
{
return method_exists($this->driverConnection, 'createSchemaManager')
? $this->driverConnection->createSchemaManager()
: $this->driverConnection->getSchemaManager();
}
}
12 changes: 10 additions & 2 deletions Transport/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
Expand Down Expand Up @@ -386,7 +387,7 @@ protected function executeStatement(string $sql, array $parameters = [], array $

private function getSchema(): Schema
{
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
$schema = new Schema([], [], $this->createSchemaManager()->createSchemaConfig());
$this->addTableToSchema($schema);

return $schema;
Expand Down Expand Up @@ -437,7 +438,7 @@ private function updateSchema(): void
}

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

foreach ($schemaDiff->toSaveSql($this->driverConnection->getDatabasePlatform()) as $sql) {
if (method_exists($this->driverConnection, 'executeStatement')) {
Expand All @@ -447,6 +448,13 @@ private function updateSchema(): void
}
}
}

private function createSchemaManager(): AbstractSchemaManager
{
return method_exists($this->driverConnection, 'createSchemaManager')
? $this->driverConnection->createSchemaManager()
: $this->driverConnection->getSchemaManager();
}
}

if (!class_exists(\Symfony\Component\Messenger\Transport\Doctrine\Connection::class, false)) {
Expand Down

0 comments on commit e11b875

Please sign in to comment.