Commit d6a1237f authored by Andrej Hudec's avatar Andrej Hudec

Return result from commit()

parent 0152fbf4
......@@ -1266,6 +1266,8 @@ class Connection implements DriverConnection
throw ConnectionException::commitFailedRollbackOnly();
}
$result = true;
$connection = $this->getWrappedConnection();
$logger = $this->_config->getSQLLogger();
......@@ -1275,7 +1277,7 @@ class Connection implements DriverConnection
$logger->startQuery('"COMMIT"');
}
$connection->commit();
$result = $connection->commit();
if ($logger) {
$logger->stopQuery();
......@@ -1293,12 +1295,12 @@ class Connection implements DriverConnection
--$this->transactionNestingLevel;
if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) {
return true;
return $result;
}
$this->beginTransaction();
return true;
return $result;
}
/**
......
......@@ -297,6 +297,36 @@ class ConnectionTest extends DbalTestCase
self::assertTrue($conn->isTransactionActive());
}
/**
* @dataProvider resultProvider
*/
public function testCommitReturn(bool $expectedResult) : void
{
$driverConnection = $this->createMock(DriverConnection::class);
$driverConnection->expects($this->once())
->method('commit')->willReturn($expectedResult);
$driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue($driverConnection));
$conn = new Connection([], $driverMock);
$conn->connect();
$conn->beginTransaction();
self::assertSame($expectedResult, $conn->commit());
}
/**
* @return bool[][]
*/
public function resultProvider() : array
{
return [[true], [false]];
}
/**
* @group DBAL-81
*/
......
......@@ -88,7 +88,7 @@ class ConnectionTest extends DbalFunctionalTestCase
self::assertEquals(2, $this->connection->getTransactionNestingLevel());
$this->connection->beginTransaction();
self::assertEquals(3, $this->connection->getTransactionNestingLevel());
$this->connection->commit();
self::assertTrue($this->connection->commit());
self::assertEquals(2, $this->connection->getTransactionNestingLevel());
throw new Exception();
$this->connection->commit(); // never reached
......
<?php
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\Tests\DbalFunctionalTestCase;
use function sleep;
class TransactionTest extends DbalFunctionalTestCase
{
protected function setUp() : void
{
parent::setUp();
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
return;
}
$this->markTestSkipped('Restricted to MySQL.');
}
protected function tearDown() : void
{
$this->resetSharedConn();
parent::tearDown();
}
public function testCommitFalse() : void
{
$this->connection->query('SET SESSION wait_timeout=1');
$this->assertTrue($this->connection->beginTransaction());
sleep(2); // during the sleep mysql will close the connection
$this->assertFalse(@$this->connection->commit()); // we will ignore `MySQL server has gone away` warnings
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment