Skip to content

Commit

Permalink
Cover how transactional() behaves in different auto commit modes
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Oct 19, 2024
1 parent 590acd7 commit be31d7c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,48 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void
self::assertTrue($conn->isTransactionActive());
}

public function testTransactionIsNotActiveAfterTransactionalInAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
);

$conn = new Connection([], $driverMock);

$conn->setAutoCommit(true);

self::assertFalse($conn->isTransactionActive());

$conn->transactional(static function (Connection $connection): void {
});

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

public function testTransactionIsActiveAfterTransactionalInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
);

$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);

self::assertFalse($conn->isTransactionActive());

$conn->transactional(static function (Connection $connection): void {
});

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

public function testCommitStartsTransactionInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
Expand Down

0 comments on commit be31d7c

Please sign in to comment.