Skip to content

Commit 0e2fa82

Browse files
committed
Cover scenario BEGIN TRANSACTION; COMMIT; BEGIN TRANSACTION; --failure
#6545 (comment)
1 parent 9fca0ee commit 0e2fa82

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/ConnectionTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use PHPUnit\Framework\TestCase;
3333
use Psr\Cache\CacheItemInterface;
3434
use Psr\Cache\CacheItemPoolInterface;
35+
use RuntimeException;
3536
use stdClass;
3637

3738
/** @requires extension pdo_mysql */
@@ -413,6 +414,35 @@ public function testCommitStartsTransactionInNoAutoCommitMode(): void
413414
self::assertTrue($conn->isTransactionActive());
414415
}
415416

417+
public function testBeginTransactionFailureAfterCommitInNoAutoCommitMode(): void
418+
{
419+
$driverConnectionMock = $this->createMock(DriverConnection::class);
420+
$driverConnectionMock->expects(self::exactly(2))
421+
->method('beginTransaction')
422+
->willReturnOnConsecutiveCalls(
423+
true,
424+
self::throwException(new RuntimeException()),
425+
);
426+
427+
$driverMock = $this->createStub(Driver::class);
428+
$driverMock
429+
->method('connect')
430+
->willReturn(
431+
$driverConnectionMock,
432+
);
433+
$conn = new Connection([], $driverMock);
434+
435+
$conn->setAutoCommit(false);
436+
437+
$conn->connect();
438+
try {
439+
$conn->commit();
440+
} catch (RuntimeException $e) {
441+
}
442+
443+
self::assertTrue($conn->isTransactionActive());
444+
}
445+
416446
/** @dataProvider resultProvider */
417447
public function testCommitReturn(bool $expectedResult): void
418448
{

0 commit comments

Comments
 (0)