diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index fce265ae6c4..ce20235e49e 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1254,8 +1254,6 @@ public function beginTransaction() /** * {@inheritDoc} * - * @return bool - * * @throws ConnectionException If the commit failed due to no active transaction or * because the transaction was marked for rollback only. */ @@ -1326,8 +1324,6 @@ private function commitAll() /** * Cancels any database changes done during the current transaction. * - * @return bool - * * @throws ConnectionException If the rollback operation failed. */ public function rollBack() diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index b0067b4e331..7c6a96d7b1b 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -299,95 +299,55 @@ public function testCommitStartsTransactionInNoAutoCommitMode() : void } /** - * @group DBAL-81 + * @dataProvider resultProvider */ - public function testCommitReturnTrue() : void + public function testCommitReturn(bool $expectedResult) : void { - $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) - ->method('connect') - ->will($this->returnValue( - $this->createMock(DriverConnection::class) - )); $pdo = $this->createMock(PDO::class); $pdo->expects($this->once()) - ->method('commit')->willReturn(true); - - $conn = new Connection(['pdo' => $pdo], $driverMock); - - $conn->connect(); - $conn->beginTransaction(); - - self::assertTrue($conn->commit()); - } + ->method('commit')->willReturn($expectedResult); - /** - * @group DBAL-81 - */ - public function testCommitReturnFalse() : void - { $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue( - $this->createMock(DriverConnection::class) - )); - $pdo = $this->createMock(PDO::class); - $pdo->expects($this->once()) - ->method('commit')->willReturn(false); + ->will($this->returnValue($pdo)); - $conn = new Connection(['pdo' => $pdo], $driverMock); + $conn = new Connection([], $driverMock); $conn->connect(); $conn->beginTransaction(); - self::assertFalse($conn->commit()); + self::assertSame($expectedResult, $conn->commit()); } /** - * @group DBAL-81 + * @dataProvider resultProvider */ - public function testRollackReturnTrue() : void + public function testRollackReturn(bool $expectedResult) : void { + $pdo = $this->createMock(PDO::class); + $pdo->expects($this->once()) + ->method('rollback')->willReturn($expectedResult); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue( - $this->createMock(DriverConnection::class) - )); - $pdo = $this->createMock(PDO::class); - $pdo->expects($this->once()) - ->method('rollback')->willReturn(true); + ->will($this->returnValue($pdo)); - $conn = new Connection(['pdo' => $pdo], $driverMock); + $conn = new Connection([], $driverMock); $conn->connect(); $conn->beginTransaction(); - self::assertTrue($conn->rollback()); + self::assertSame($expectedResult, $conn->rollback()); } /** - * @group DBAL-81 + * @return bool[][] */ - public function testRollackReturnFalse() : void + public function resultProvider() : array { - $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) - ->method('connect') - ->will($this->returnValue( - $this->createMock(DriverConnection::class) - )); - $pdo = $this->createMock(PDO::class); - $pdo->expects($this->once()) - ->method('rollback')->willReturn(false); - - $conn = new Connection(['pdo' => $pdo], $driverMock); - - $conn->connect(); - $conn->beginTransaction(); - - self::assertFalse($conn->rollback()); + return [[true], [false]]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 5759f019b5f..b22d6b3e4d1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -63,7 +63,7 @@ public function testTransactionNestingBehavior() : void } self::assertTrue($this->connection->isRollbackOnly()); - self::assertTrue($this->connection->commit()); // should throw exception + $this->connection->commit(); // should throw exception $this->fail('Transaction commit after failed nested transaction should fail.'); } catch (ConnectionException $e) { self::assertEquals(1, $this->connection->getTransactionNestingLevel()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php index aca8055d37c..a31415901ec 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php @@ -2,10 +2,9 @@ namespace Doctrine\Tests\DBAL\Functional; -use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\Tests\DbalFunctionalTestCase; -use Throwable; -use function in_array; +use PHPUnit\Framework\Error\Warning; use function sleep; class TransactionTest extends DbalFunctionalTestCase @@ -14,7 +13,9 @@ protected function setUp() : void { parent::setUp(); - if (in_array($this->connection->getDatabasePlatform()->getName(), ['mysql'])) { + Warning::$enabled = false; // we will ignore `MySQL server has gone away` warnings + + if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) { return; } @@ -23,6 +24,7 @@ protected function setUp() : void protected function tearDown() : void { + Warning::$enabled = true; $this->resetSharedConn(); parent::tearDown(); @@ -32,22 +34,10 @@ public function testCommitFalse() : void { $this->connection->query('SET SESSION wait_timeout=1'); - $table = new Table('foo'); - $table->addColumn('id', 'integer'); - $table->setPrimaryKey(['id']); - - $this->connection->getSchemaManager()->createTable($table); + $this->assertTrue($this->connection->beginTransaction()); - self::assertEquals('foo', $table->getName()); - try { - $this->assertTrue($this->connection->beginTransaction()); - $this->connection->executeUpdate('INSERT INTO foo (id) VALUES(1)'); + sleep(2); // during the sleep mysql will close the connection - sleep(2); // during the sleep mysql will close the connection - - $this->assertFalse(@$this->connection->commit()); // we will ignore `MySQL server has gone away` warnings - } catch (Throwable $exception) { - $this->fail('Is the PHP/PDO bug https://bugs.php.net/bug.php?id=66528 fixed? Normally no exception is thrown.'); - } + $this->assertFalse($this->connection->commit()); } }