File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55use PDOException ;
66use PHPUnit \Framework \TestCase ;
77use Utopia \Database \Adapter \MySQL ;
8+ use Utopia \Database \Exception \Transaction as TransactionException ;
89
910class SQLTransactionTest extends TestCase
1011{
@@ -34,4 +35,26 @@ public function testStartTransactionRecoversFromDesyncedRollback(): void
3435 $ this ->assertTrue ($ adapter ->startTransaction ());
3536 $ this ->assertTrue ($ adapter ->inTransaction ());
3637 }
38+
39+ public function testStartTransactionDoesNotMaskBeginFailureAfterDesyncedRollback (): void
40+ {
41+ $ pdo = $ this ->getMockBuilder (\PDO ::class)
42+ ->disableOriginalConstructor ()
43+ ->getMock ();
44+
45+ $ pdo ->method ('inTransaction ' )->willReturn (true );
46+ $ pdo ->method ('rollBack ' )->willThrowException (
47+ new PDOException ('There is no active transaction ' )
48+ );
49+ $ pdo ->expects ($ this ->once ())
50+ ->method ('beginTransaction ' )
51+ ->willThrowException (new PDOException ('Connection lost ' ));
52+
53+ $ adapter = new MySQL ($ pdo );
54+
55+ $ this ->expectException (TransactionException::class);
56+ $ this ->expectExceptionMessage ('Failed to start transaction: Connection lost ' );
57+
58+ $ adapter ->startTransaction ();
59+ }
3760}
You can’t perform that action at this time.
0 commit comments