From e388365143dc2770f2055951ea25cf8a717aaa09 Mon Sep 17 00:00:00 2001 From: Sergey Serbin Date: Mon, 28 Aug 2023 17:09:42 +0300 Subject: [PATCH] fix PrimaryReadReplica not initializing properly 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 --- src/EntityManagerFactory.php | 3 +++ tests/EntityManagerFactoryTest.php | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/EntityManagerFactory.php b/src/EntityManagerFactory.php index 1f9659da..377b2b23 100644 --- a/src/EntityManagerFactory.php +++ b/src/EntityManagerFactory.php @@ -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) { @@ -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; } } diff --git a/tests/EntityManagerFactoryTest.php b/tests/EntityManagerFactoryTest.php index f2026095..a3f2b868 100644 --- a/tests/EntityManagerFactoryTest.php +++ b/tests/EntityManagerFactoryTest.php @@ -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; @@ -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