From a32476fd41c4af7127a18af1d32327c4b7baba7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Thu, 12 May 2016 15:17:38 +0200 Subject: [PATCH 1/3] typo --- lib/Doctrine/DBAL/Connection.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index d3d7eb1ccc0..a60bc2f7a73 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -773,7 +773,7 @@ public function prepare($statement) { try { $stmt = new Statement($statement, $this); - } catch (\Exception $ex) { + } catch (Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); } @@ -824,7 +824,7 @@ public function executeQuery($query, array $params = array(), $types = array(), } else { $stmt = $this->_conn->query($query); } - } catch (\Exception $ex) { + } catch (Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); } @@ -933,7 +933,7 @@ public function query() $statement = call_user_func_array(array($this->_conn, 'query'), $args); break; } - } catch (\Exception $ex) { + } catch (Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]); } @@ -984,7 +984,7 @@ public function executeUpdate($query, array $params = array(), array $types = ar } else { $result = $this->_conn->exec($query); } - } catch (\Exception $ex) { + } catch (Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); } @@ -1015,7 +1015,7 @@ public function exec($statement) try { $result = $this->_conn->exec($statement); - } catch (\Exception $ex) { + } catch (Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); } From 54772655a6c80516baae9e28c5904bebb53bdec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Thu, 12 May 2016 15:19:35 +0200 Subject: [PATCH 2/3] Catch Throwable in Connection::transactional() --- lib/Doctrine/DBAL/Connection.php | 4 ++++ .../Tests/DBAL/Functional/ConnectionTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index a60bc2f7a73..b710b4a42e2 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -32,6 +32,7 @@ use Doctrine\DBAL\Cache\ArrayStatement; use Doctrine\DBAL\Cache\CacheException; use Doctrine\DBAL\Driver\PingableConnection; +use Throwable; /** * A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like @@ -1103,6 +1104,9 @@ public function transactional(Closure $func) } catch (Exception $e) { $this->rollBack(); throw $e; + } catch (Throwable $e) { + $this->rollBack(); + throw $e; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index bcb4b51f06a..0dd4a78239d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -201,6 +201,24 @@ public function testTransactionalWithException() } } + public function testTransactionalWithThrowable() + { + if (version_compare(PHP_VERSION, '7.0', '<')) { + $this->markTestSkipped('Only for PHP 7.0 and above.'); + } + + try { + $this->_conn->transactional(function($conn) { + /* @var $conn \Doctrine\DBAL\Connection */ + $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); + throw new \Error("Ooops!"); + }); + $this->fail('Expected exception'); + } catch (\Error $expected) { + $this->assertEquals(0, $this->_conn->getTransactionNestingLevel()); + } + } + public function testTransactional() { $this->_conn->transactional(function($conn) { From db06fceb26805db59c9d8551baaf18d55ee53c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Thu, 12 May 2016 15:35:26 +0200 Subject: [PATCH 3/3] testTransactionalWithException: if no exception is thrown, fail --- tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 0dd4a78239d..3f91e61d3e7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -196,6 +196,7 @@ public function testTransactionalWithException() $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); throw new \RuntimeException("Ooops!"); }); + $this->fail('Expected exception'); } catch (\RuntimeException $expected) { $this->assertEquals(0, $this->_conn->getTransactionNestingLevel()); }