From 16ccf486b11b7bbac79e2e8a3b7e87febe48f8ef Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Thu, 2 Oct 2014 12:30:58 +0300 Subject: [PATCH 1/2] Add tests for broken transaction logic when changing PDO --- tests/Database/DatabaseConnectionTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/Database/DatabaseConnectionTest.php b/tests/Database/DatabaseConnectionTest.php index 9aaff2bce914..7080c64a5985 100755 --- a/tests/Database/DatabaseConnectionTest.php +++ b/tests/Database/DatabaseConnectionTest.php @@ -182,6 +182,27 @@ public function testTransactionMethodRollsbackAndThrows() } } + /** + * @expectedException RuntimeException + * @expectedExceptionMessage Attempt to change PDO inside running transaction + */ + public function testTransactionMethodDisallowPDOChanging() + { + $pdo = $this->getMock('DatabaseConnectionTestMockPDO', array('beginTransaction', 'commit', 'rollBack')); + $pdo->expects($this->once())->method('beginTransaction'); + $pdo->expects($this->once())->method('rollBack'); + $pdo->expects($this->never())->method('commit'); + + $mock = $this->getMockConnection(array(), $pdo); + + $mock->setReconnector(function ($connection) + { + $connection->setPDO(null); + }); + + $mock->transaction(function ($connection) { $connection->reconnect(); }); + } + public function testFromCreatesNewQueryBuilder() { From d2b1bfbbe17bd06c5af8385d1c9e336bfabc834b Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Thu, 2 Oct 2014 12:31:41 +0300 Subject: [PATCH 2/2] Fix broken transaction logic when PDO changes --- src/Illuminate/Database/Connection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Illuminate/Database/Connection.php b/src/Illuminate/Database/Connection.php index 1e4b13bd65ff..4a9933d04520 100755 --- a/src/Illuminate/Database/Connection.php +++ b/src/Illuminate/Database/Connection.php @@ -831,6 +831,8 @@ public function getReadPdo() */ public function setPdo($pdo) { + if ($this->transactions >= 1) throw new \RuntimeException("Attempt to change PDO inside running transaction"); + $this->pdo = $pdo; return $this;