Skip to content

Commit

Permalink
Catch Throwable in Connection::transactional()
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed May 12, 2016
1 parent a32476f commit 5477265
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1103,6 +1104,9 @@ public function transactional(Closure $func)
} catch (Exception $e) {
$this->rollBack();
throw $e;
} catch (Throwable $e) {
$this->rollBack();
throw $e;
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5477265

Please sign in to comment.