Skip to content

Commit 4df329d

Browse files
authored
Merge pull request #333 from letsdrink/bug/fix-db-run-in-transaction
Catch Throwable instead of Exception in Db::runInTransaction()
2 parents a869eec + 641263e commit 4df329d

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/Ouzo/Core/Db.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
namespace Ouzo;
88

99
use Closure;
10-
use Exception;
1110
use Ouzo\Db\PDOExceptionExtractor;
1211
use Ouzo\Db\StatementExecutor;
1312
use Ouzo\Db\TransactionalProxy;
1413
use Ouzo\Utilities\Arrays;
1514
use PDO;
1615
use PDOException;
16+
use Throwable;
1717

1818

1919
class Db
@@ -90,7 +90,7 @@ public function runInTransaction(Closure $callable): mixed
9090
$result = call_user_func($callable);
9191
$this->commitTransaction();
9292
return $result;
93-
} catch (Exception $e) {
93+
} catch (Throwable $e) {
9494
$this->rollbackTransactionSilently();
9595
throw $e;
9696
}
@@ -126,7 +126,7 @@ private function rollbackTransactionSilently(): void
126126
{
127127
try {
128128
$this->rollbackTransaction();
129-
} catch (Exception) {
129+
} catch (Throwable) {
130130
}
131131
}
132132

test/src/Ouzo/Core/DbTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public function runInTransactionShouldInvokeRollbackOnFailure()
6262
$db->dbHandle = $dbHandle;
6363

6464
//when
65-
CatchException::when($db)->runInTransaction(fn() => throw new InvalidArgumentException());
65+
CatchException::when($db)->runInTransaction(fn() => throw new Error());
6666

6767
//then
68-
CatchException::assertThat()->isInstanceOf('InvalidArgumentException');
68+
CatchException::assertThat()->isInstanceOf('Error');
6969
Mock::verify($dbHandle)->beginTransaction();
7070
Mock::verify($dbHandle)->neverReceived()->commitTransaction();
7171
Mock::verify($dbHandle)->rollBack();

0 commit comments

Comments
 (0)