Skip to content

Commit

Permalink
Cover scenario `BEGIN TRANSACTION; COMMIT; BEGIN TRANSACTION --failure;
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Oct 19, 2024
1 parent be31d7c commit bebee42
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use RuntimeException;
use stdClass;

/** @requires extension pdo_mysql */
Expand Down Expand Up @@ -455,6 +456,35 @@ public function testCommitStartsTransactionInNoAutoCommitMode(): void
self::assertTrue($conn->isTransactionActive());
}

public function testCoverBeginTransactionFailureAfterCommitInNoAutoCommitMode(): void
{
$driverConnectionMock = $this->createMock(DriverConnection::class);
$driverConnectionMock->expects(self::exactly(2))
->method('beginTransaction')
->willReturnOnConsecutiveCalls(
true,
self::throwException(new RuntimeException()),
);

$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$driverConnectionMock,
);
$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);

$conn->connect();
try {
$conn->commit();
} catch (RuntimeException $e) {
}

self::assertTrue($conn->isTransactionActive());
}

/** @dataProvider resultProvider */
public function testCommitReturn(bool $expectedResult): void
{
Expand Down

0 comments on commit bebee42

Please sign in to comment.