From 3e87bf26baa0597405406659c080789faa72a49c Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 8 Jun 2020 17:11:57 +0200 Subject: [PATCH] [GH-4052] Rename to PrimaryReadReplicaConnection --- UPGRADE.md | 6 ++-- .../Connections/MasterSlaveConnection.php | 6 ++-- ...n.php => PrimaryReadReplicaConnection.php} | 4 +-- ...p => PrimaryReadReplicaConnectionTest.php} | 34 +++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) rename lib/Doctrine/DBAL/Connections/{PrimaryReplicaConnection.php => PrimaryReadReplicaConnection.php} (98%) rename tests/Doctrine/Tests/DBAL/Functional/{PrimaryReplicaConnectionTest.php => PrimaryReadReplicaConnectionTest.php} (84%) diff --git a/UPGRADE.md b/UPGRADE.md index b0d559e0a3f..e69c41e563f 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,8 +1,8 @@ # Upgrade to 2.11 -## Deprecated `MasterSlaveConnection` use `PrimaryReplicaConnection` +## Deprecated `MasterSlaveConnection` use `PrimaryReadReplicaConnection` -The `Doctrine\DBAL\Connections\MasterSlaveConnection` class is renamed to `Doctrine\DBAL\Connections\PrimaryReplicaConnection`. +The `Doctrine\DBAL\Connections\MasterSlaveConnection` class is renamed to `Doctrine\DBAL\Connections\PrimaryReadReplicaConnection`. In addition its configuration parameters `master`, `slaves` and `keepSlave` are renamed to `primary`, `replica` and `keepReplica`. Before: @@ -24,7 +24,7 @@ Before: After: $connection = DriverManager::getConnection(array( - 'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReplicaConnection', + 'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReadReplicaConnection', 'driver' => 'pdo_mysql', 'primary' => array('user' => '', 'password' => '', 'host' => '', 'dbname' => ''), 'replica' => array( diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index 47dc99e74dd..5ecf0f68967 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -13,9 +13,9 @@ use const E_USER_DEPRECATED; /** - * @deprecated Use PrimaryReplicaConnection instead + * @deprecated Use PrimaryReadReplicaConnection instead */ -class MasterSlaveConnection extends PrimaryReplicaConnection +class MasterSlaveConnection extends PrimaryReadReplicaConnection { /** * Creates Primary Replica Connection. @@ -26,7 +26,7 @@ class MasterSlaveConnection extends PrimaryReplicaConnection */ public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null) { - $this->deprecated(self::class, PrimaryReplicaConnection::class); + $this->deprecated(self::class, PrimaryReadReplicaConnection::class); if (isset($params['master'])) { $this->deprecated('Params key "master"', '"primary"'); diff --git a/lib/Doctrine/DBAL/Connections/PrimaryReplicaConnection.php b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php similarity index 98% rename from lib/Doctrine/DBAL/Connections/PrimaryReplicaConnection.php rename to lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php index 473b669a95d..0b17b9f0264 100644 --- a/lib/Doctrine/DBAL/Connections/PrimaryReplicaConnection.php +++ b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php @@ -59,7 +59,7 @@ * @example * * $conn = DriverManager::getConnection(array( - * 'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReplicaConnection', + * 'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReadReplicaConnection', * 'driver' => 'pdo_mysql', * 'primary' => array('user' => '', 'password' => '', 'host' => '', 'dbname' => ''), * 'replica' => array( @@ -70,7 +70,7 @@ * * You can also pass 'driverOptions' and any other documented option to each of this drivers to pass additional information. */ -class PrimaryReplicaConnection extends Connection +class PrimaryReadReplicaConnection extends Connection { /** * Primary and Replica connection (one of the randomly picked replicas). diff --git a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReplicaConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php similarity index 84% rename from tests/Doctrine/Tests/DBAL/Functional/PrimaryReplicaConnectionTest.php rename to tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php index e5175dcf61b..f2c714940a6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReplicaConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional; -use Doctrine\DBAL\Connections\PrimaryReplicaConnection; +use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\Table; @@ -20,7 +20,7 @@ /** * @group DBAL-20 */ -class PrimaryReplicaConnectionTest extends DbalFunctionalTestCase +class PrimaryReadReplicaConnectionTest extends DbalFunctionalTestCase { protected function setUp(): void { @@ -47,21 +47,21 @@ protected function setUp(): void $this->connection->insert('primary_replica_table', ['test_int' => 1]); } - private function createPrimaryReplicaConnection(bool $keepReplica = false): PrimaryReplicaConnection + private function createPrimaryReadReplicaConnection(bool $keepReplica = false): PrimaryReadReplicaConnection { - return DriverManager::getConnection($this->createPrimaryReplicaConnectionParams($keepReplica)); + return DriverManager::getConnection($this->createPrimaryReadReplicaConnectionParams($keepReplica)); } /** * @return mixed[] */ - private function createPrimaryReplicaConnectionParams(bool $keepReplica = false): array + private function createPrimaryReadReplicaConnectionParams(bool $keepReplica = false): array { $params = $this->connection->getParams(); $params['primary'] = $params; $params['replica'] = [$params, $params]; $params['keepReplica'] = $keepReplica; - $params['wrapperClass'] = PrimaryReplicaConnection::class; + $params['wrapperClass'] = PrimaryReadReplicaConnection::class; return $params; } @@ -74,7 +74,7 @@ public function testInheritCharsetFromPrimary(): void ]; foreach ($charsets as $charset) { - $params = $this->createPrimaryReplicaConnectionParams(); + $params = $this->createPrimaryReadReplicaConnectionParams(); $params['primary']['charset'] = $charset; foreach ($params['replica'] as $index => $replicaParams) { @@ -86,7 +86,7 @@ public function testInheritCharsetFromPrimary(): void } $conn = DriverManager::getConnection($params); - self::assertInstanceOf(PrimaryReplicaConnection::class, $conn); + self::assertInstanceOf(PrimaryReadReplicaConnection::class, $conn); $conn->ensureConnectedToReplica(); self::assertFalse($conn->isConnectedToPrimary()); @@ -102,7 +102,7 @@ public function testInheritCharsetFromPrimary(): void public function testPrimaryOnConnect(): void { - $conn = $this->createPrimaryReplicaConnection(); + $conn = $this->createPrimaryReadReplicaConnection(); self::assertFalse($conn->isConnectedToPrimary()); $conn->ensureConnectedToReplica(); @@ -113,7 +113,7 @@ public function testPrimaryOnConnect(): void public function testNoPrimaryrOnExecuteQuery(): void { - $conn = $this->createPrimaryReplicaConnection(); + $conn = $this->createPrimaryReadReplicaConnection(); $sql = 'SELECT count(*) as num FROM primary_replica_table'; $data = $conn->fetchAll($sql); @@ -125,7 +125,7 @@ public function testNoPrimaryrOnExecuteQuery(): void public function testPrimaryOnWriteOperation(): void { - $conn = $this->createPrimaryReplicaConnection(); + $conn = $this->createPrimaryReadReplicaConnection(); $conn->insert('primary_replica_table', ['test_int' => 30]); self::assertTrue($conn->isConnectedToPrimary()); @@ -143,7 +143,7 @@ public function testPrimaryOnWriteOperation(): void */ public function testKeepReplicaBeginTransactionStaysOnPrimary(): void { - $conn = $this->createPrimaryReplicaConnection($keepReplica = true); + $conn = $this->createPrimaryReadReplicaConnection($keepReplica = true); $conn->ensureConnectedToReplica(); $conn->beginTransaction(); @@ -164,7 +164,7 @@ public function testKeepReplicaBeginTransactionStaysOnPrimary(): void */ public function testKeepReplicaInsertStaysOnPrimary(): void { - $conn = $this->createPrimaryReplicaConnection($keepReplica = true); + $conn = $this->createPrimaryReadReplicaConnection($keepReplica = true); $conn->ensureConnectedToReplica(); $conn->insert('primary_replica_table', ['test_int' => 30]); @@ -178,9 +178,9 @@ public function testKeepReplicaInsertStaysOnPrimary(): void self::assertFalse($conn->isConnectedToPrimary()); } - public function testPrimaryReplicaConnectionCloseAndReconnect(): void + public function testPrimaryReadReplicaConnectionCloseAndReconnect(): void { - $conn = $this->createPrimaryReplicaConnection(); + $conn = $this->createPrimaryReadReplicaConnection(); $conn->ensureConnectedToPrimary(); self::assertTrue($conn->isConnectedToPrimary()); @@ -193,7 +193,7 @@ public function testPrimaryReplicaConnectionCloseAndReconnect(): void public function testQueryOnPrimary(): void { - $conn = $this->createPrimaryReplicaConnection(); + $conn = $this->createPrimaryReadReplicaConnection(); $query = 'SELECT count(*) as num FROM primary_replica_table'; @@ -217,7 +217,7 @@ public function testQueryOnPrimary(): void public function testQueryOnReplica(): void { - $conn = $this->createPrimaryReplicaConnection(); + $conn = $this->createPrimaryReadReplicaConnection(); $conn->ensureConnectedToReplica(); $query = 'SELECT count(*) as num FROM primary_replica_table';