diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 16d9c8a51d..eb34a9bcaa 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -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);