Skip to content

Commit 8d61871

Browse files
committed
Ensure that a connection exists in rollback.
Calling rollbackTransaction on a disconnected driver should not fatally error.
1 parent 51ce73f commit 8d61871

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Database/Driver/PDODriverTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ public function commitTransaction()
139139
}
140140

141141
/**
142-
* Rollsback a transaction
142+
* Rollback a transaction
143143
*
144144
* @return bool true on success, false otherwise
145145
*/
146146
public function rollbackTransaction()
147147
{
148+
$this->connect();
148149
if (!$this->_connection->inTransaction()) {
149150
return false;
150151
}

tests/TestCase/Database/Driver/MysqlTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,23 @@ public function testIsConnected()
141141
$connection->connect();
142142
$this->assertTrue($connection->isConnected(), 'Should be connected.');
143143
}
144+
145+
public function testRollbackTransactionAutoConnect()
146+
{
147+
$connection = ConnectionManager::get('test');
148+
$connection->disconnect();
149+
150+
$driver = $connection->driver();
151+
$this->assertFalse($driver->rollbackTransaction());
152+
$this->assertTrue($driver->isConnected());
153+
}
154+
155+
public function testCommitTransactionAutoConnect()
156+
{
157+
$connection = ConnectionManager::get('test');
158+
$driver = $connection->driver();
159+
160+
$this->assertFalse($driver->commitTransaction());
161+
$this->assertTrue($driver->isConnected());
162+
}
144163
}

0 commit comments

Comments
 (0)