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 31, 2024
1 parent 9fca0ee commit 07a6d07
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,53 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void
self::assertTrue($conn->isTransactionActive());
}

public function testTransactionIsNotActiveAfterTransactionalInAutoCommitMode(): void
{
$driverMock = $this->createStub(Driver::class);
$driverMock
->method('connect')
->willReturn(
$this->createStub(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
->method('connect')
->willReturn(
$this->createStub(DriverConnection::class),
);

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

$conn->setAutoCommit(false);

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

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

public function testCommitStartsTransactionInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock);

Expand Down

0 comments on commit 07a6d07

Please sign in to comment.