diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 10e1ea4d77..2e1bb0417b 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -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);