Commit 54772655 authored by Filip Procházka's avatar Filip Procházka

Catch Throwable in Connection::transactional()

parent a32476fd
...@@ -32,6 +32,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; ...@@ -32,6 +32,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Cache\ArrayStatement; use Doctrine\DBAL\Cache\ArrayStatement;
use Doctrine\DBAL\Cache\CacheException; use Doctrine\DBAL\Cache\CacheException;
use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\PingableConnection;
use Throwable;
/** /**
* A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like * A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like
...@@ -1103,6 +1104,9 @@ class Connection implements DriverConnection ...@@ -1103,6 +1104,9 @@ class Connection implements DriverConnection
} catch (Exception $e) { } catch (Exception $e) {
$this->rollBack(); $this->rollBack();
throw $e; throw $e;
} catch (Throwable $e) {
$this->rollBack();
throw $e;
} }
} }
......
...@@ -201,6 +201,24 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -201,6 +201,24 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
} }
} }
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() public function testTransactional()
{ {
$this->_conn->transactional(function($conn) { $this->_conn->transactional(function($conn) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment