Skip to content

Commit

Permalink
Ensure that a connection exists in rollback.
Browse files Browse the repository at this point in the history
Calling rollbackTransaction on a disconnected driver should not fatally error.
  • Loading branch information
markstory committed Mar 24, 2016
1 parent 51ce73f commit 8d61871
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Database/Driver/PDODriverTrait.php
Expand Up @@ -139,12 +139,13 @@ public function commitTransaction()
}

/**
* Rollsback a transaction
* Rollback a transaction
*
* @return bool true on success, false otherwise
*/
public function rollbackTransaction()
{
$this->connect();
if (!$this->_connection->inTransaction()) {
return false;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/Database/Driver/MysqlTest.php
Expand Up @@ -141,4 +141,23 @@ public function testIsConnected()
$connection->connect();
$this->assertTrue($connection->isConnected(), 'Should be connected.');
}

public function testRollbackTransactionAutoConnect()
{
$connection = ConnectionManager::get('test');
$connection->disconnect();

$driver = $connection->driver();
$this->assertFalse($driver->rollbackTransaction());
$this->assertTrue($driver->isConnected());
}

public function testCommitTransactionAutoConnect()
{
$connection = ConnectionManager::get('test');
$driver = $connection->driver();

$this->assertFalse($driver->commitTransaction());
$this->assertTrue($driver->isConnected());
}
}

0 comments on commit 8d61871

Please sign in to comment.