From 9131fafb786091240938a458e29b8b4f593c510d Mon Sep 17 00:00:00 2001 From: Alexandr Zolotukhin Date: Wed, 2 Sep 2020 23:18:16 +0300 Subject: [PATCH 1/2] Add a test verifying that DBALException is thrown --- .../Connection/MasterSlaveConnectionTest.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Connection/MasterSlaveConnectionTest.php diff --git a/tests/Doctrine/Tests/DBAL/Connection/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Connection/MasterSlaveConnectionTest.php new file mode 100644 index 00000000000..07f2c99846c --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Connection/MasterSlaveConnectionTest.php @@ -0,0 +1,55 @@ +> + */ + public static function getQueryMethods(): iterable + { + return [ + ['exec'], + ['query'], + ['executeQuery'], + ['executeUpdate'], + ['prepare'], + ]; + } + + /** + * @requires extension pdo_sqlite + * @dataProvider getQueryMethods + */ + public function testDriverExceptionIsWrapped(string $method): void + { + $this->expectException(DBALException::class); + $this->expectExceptionMessage( + << MasterSlaveConnection::class, + 'memory' => true, + 'driver' => 'pdo_sqlite', + 'master' => [], + 'slaves' => ['slave1' => ['driver' => 'pdo_sqlite']], + ] + ); + + $connection->$method('MUUHAAAAHAAAA'); + } +} From fe7ef759b9af35848d8e4ee926b4f894e366c0c5 Mon Sep 17 00:00:00 2001 From: Alexandr Zolotukhin Date: Wed, 2 Sep 2020 23:22:26 +0300 Subject: [PATCH 2/2] Use parent method, which is logically identical, but converts exceptions --- .../Connections/MasterSlaveConnection.php | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index 2ba37bfad25..9296b5f9a04 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -12,7 +12,6 @@ use InvalidArgumentException; use function array_rand; -use function assert; use function count; use function func_get_args; @@ -354,24 +353,8 @@ public function rollbackSavepoint($savepoint) public function query() { $this->connect('master'); - assert($this->_conn instanceof DriverConnection); - $args = func_get_args(); - - $logger = $this->getConfiguration()->getSQLLogger(); - if ($logger) { - $logger->startQuery($args[0]); - } - - $statement = $this->_conn->query(...$args); - - $statement->setFetchMode($this->defaultFetchMode); - - if ($logger) { - $logger->stopQuery(); - } - - return $statement; + return parent::query(...func_get_args()); } /**