Skip to content

Commit

Permalink
fix PrimaryReadReplica not initializing properly (#561)
Browse files Browse the repository at this point in the history
this was accidentally passing the tests
(the configuration was still accepted even though it was just empty
and the EM was setup with a non primary read connection but a regular one)
which I've also made a fix for to verify the resulting connection is indeed a PrimaryReadReplicaConnection
  • Loading branch information
sserbin authored Aug 29, 2023
1 parent 8e6d22e commit c3f48a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ private function isPrimaryReadReplicaConfigured(array $driverConfig)
* Check if slave configuration is valid.
*
* @param array $driverConfig
* @return bool
*/
private function hasValidPrimaryReadReplicaConfig(array $driverConfig)
{
Expand All @@ -540,5 +541,7 @@ private function hasValidPrimaryReadReplicaConfig(array $driverConfig)
if (($key = array_search(0, array_map('count', $slaves))) !== false) {
throw new \InvalidArgumentException("Parameter 'read' config no. {$key} is empty.");
}

return true;
}
}
5 changes: 3 additions & 2 deletions tests/EntityManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\ORM\Cache\CacheFactory;
use Doctrine\ORM\Cache\RegionsConfiguration;
Expand Down Expand Up @@ -1172,9 +1173,9 @@ public function testPrimaryReadReplicaConnection(
}

$this->settings['connection'] = 'mysql';
$factory->create($this->settings);
$em = $factory->create($this->settings);

$this->assertTrue(true);
$this->assertInstanceOf(PrimaryReadReplicaConnection::class, $em->getConnection());
}

protected function tearDown(): void
Expand Down

0 comments on commit c3f48a9

Please sign in to comment.