Skip to content

Commit

Permalink
Cover how transactional() behaves in different auto commit modes (d…
Browse files Browse the repository at this point in the history
…octrine#6563)

|      Q       |   A
|------------- | -----------
| Type         | improvement
| Fixed issues | <!-- use #NUM format to reference an issue -->

#### Summary

Covers the concern expressed by @greg0ire
doctrine#6545 (comment)

This ensures the transaction is (not)active based on `autocommmit` mode
when interacting with `transactional()`.
  • Loading branch information
simPod authored Oct 31, 2024
1 parent 19a5a35 commit 976f3f3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,46 @@ 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
{
$driver = $this->createStub(Driver::class);
Expand Down

0 comments on commit 976f3f3

Please sign in to comment.