From 8c83fd5b0c351a6e71af80d77142dc3874a37610 Mon Sep 17 00:00:00 2001 From: Nick Howell Date: Mon, 19 Sep 2016 11:42:11 -0400 Subject: [PATCH] Fix DB connection tests testTransactionsDecrementedOnTransactionException() didn't actually test that the transaction level was decremented because the exception caused the test to end early. testCantSwapPDOWithOpenTransaction() changed to use @expectedException annotation, as is the convention, instead of $this->setExpectedException(). Also, use $connection->setPdo(null) instead of $connection->disconnect() which aligns better with the intent of the test. --- tests/Database/DatabaseConnectionTest.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/Database/DatabaseConnectionTest.php b/tests/Database/DatabaseConnectionTest.php index f96be3db30eb..97d71ef9f8b8 100755 --- a/tests/Database/DatabaseConnectionTest.php +++ b/tests/Database/DatabaseConnectionTest.php @@ -116,20 +116,23 @@ public function testTransactionsDecrementedOnTransactionException() $pdo = $this->getMock('DatabaseConnectionTestMockPDO'); $pdo->expects($this->once())->method('beginTransaction')->will($this->throwException(new ErrorException('MySQL server has gone away'))); $connection = $this->getMockConnection([], $pdo); - $this->setExpectedException('ErrorException', 'MySQL server has gone away'); - $connection->beginTransaction(); - $connection->disconnect(); - $this->assertNull($connection->getPdo()); + try { + $connection->beginTransaction(); + } catch (ErrorException $e) { + $this->assertEquals(0, $connection->transactionLevel()); + } } + /** + * @expectedException RuntimeException + */ public function testCantSwapPDOWithOpenTransaction() { $pdo = $this->getMock('DatabaseConnectionTestMockPDO'); $pdo->expects($this->once())->method('beginTransaction')->will($this->returnValue(true)); $connection = $this->getMockConnection([], $pdo); $connection->beginTransaction(); - $this->setExpectedException('RuntimeException', "Can't swap PDO instance while within transaction."); - $connection->disconnect(); + $connection->setPdo(null); } public function testBeganTransactionFiresEventsIfSet() @@ -203,7 +206,7 @@ public function testTransactionMethodDisallowPDOChanging() $mock = $this->getMockConnection([], $pdo); $mock->setReconnector(function ($connection) { - $connection->setPDO(null); + $connection->setPdo(null); }); $mock->transaction(function ($connection) {