Skip to content

Commit 56b2aad

Browse files
committed
Cover scenario `BEGIN TRANSACTION; COMMIT; BEGIN TRANSACTION --failure;
#6545 (comment)
1 parent d360d4c commit 56b2aad

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/ConnectionTest.php

+30
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 */
@@ -455,6 +456,35 @@ public function testCommitStartsTransactionInNoAutoCommitMode(): void
455456
self::assertTrue($conn->isTransactionActive());
456457
}
457458

459+
public function testBeginTransactionFailureAfterCommitInNoAutoCommitMode(): void
460+
{
461+
$driverConnectionMock = $this->createMock(DriverConnection::class);
462+
$driverConnectionMock->expects(self::exactly(2))
463+
->method('beginTransaction')
464+
->willReturnOnConsecutiveCalls(
465+
true,
466+
self::throwException(new RuntimeException()),
467+
);
468+
469+
$driverMock = $this->createMock(Driver::class);
470+
$driverMock
471+
->method('connect')
472+
->willReturn(
473+
$driverConnectionMock,
474+
);
475+
$conn = new Connection([], $driverMock);
476+
477+
$conn->setAutoCommit(false);
478+
479+
$conn->connect();
480+
try {
481+
$conn->commit();
482+
} catch (RuntimeException $e) {
483+
}
484+
485+
self::assertTrue($conn->isTransactionActive());
486+
}
487+
458488
/** @dataProvider resultProvider */
459489
public function testCommitReturn(bool $expectedResult): void
460490
{

0 commit comments

Comments
 (0)