From 7d9c7c295df886124fa41a34657bce319867bca5 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 23 Jan 2015 13:07:08 -0500 Subject: [PATCH 1/3] "Breaking" a test temporarily to show that it's not doing what is expected --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index bd6d123ac03..8d7eb1dd95b 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -405,7 +405,7 @@ public function testConnectionIsClosed() { $this->_conn->close(); - $this->setExpectedException('Doctrine\\DBAL\\Exception\\DriverException'); + //$this->setExpectedException('Doctrine\\DBAL\\Exception\\DriverException'); $this->_conn->quoteIdentifier('Bug'); } From d766fb4a632969f3ca831b338d363cac2c9221ef Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 19 Mar 2015 21:26:31 -0400 Subject: [PATCH 2/3] Re-working test to use reflection and simply check that the _conn property has be nullified --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 8d7eb1dd95b..8c572c49e01 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -403,11 +403,20 @@ public function testFetchColumn() public function testConnectionIsClosed() { + // set the internal _conn to some value + $reflection = new \ReflectionObject($this->_conn); + $connProperty = $reflection->getProperty('_conn'); + $connProperty->setAccessible(true); + $connProperty->setValue($this->_conn, new \stdClass); + $connValue = $connProperty->getValue($this->_conn); + $this->assertInstanceOf('stdClass', $connValue); + + // close the connection $this->_conn->close(); - //$this->setExpectedException('Doctrine\\DBAL\\Exception\\DriverException'); - - $this->_conn->quoteIdentifier('Bug'); + // make sure the _conn has be set to null (but not unset) + $connNewValue = $connProperty->getValue($this->_conn); + $this->assertNull($connNewValue, 'Connection can\'t be closed.'); } public function testFetchAll() From 9d8be7b10240203f057b015798d5ee2eb3096cf3 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 3 May 2015 16:23:11 -0400 Subject: [PATCH 3/3] Updating test to verify that the wrapped connection is set to null on close (not unset) This mocks connect(), sets the internal _conn to an object, then calls close, which should re-set _conn back to null. The getWrappedConnection() call gives us access to _conn, but does NOT trigger a re-connect, since we mocked connect() to do nothing. Ultimately, if _conn is unset, calling getWrappedConnection() will error. If _conn is not set to null, the test will fail. This tests all the cases. --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 27 ++++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 8c572c49e01..22d1b449f52 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -401,22 +401,27 @@ public function testFetchColumn() $this->assertSame($result, $conn->fetchColumn($statement, $params, $column, $types)); } - public function testConnectionIsClosed() + public function testConnectionIsClosedButNotUnset() { - // set the internal _conn to some value - $reflection = new \ReflectionObject($this->_conn); + // mock Connection, and make connect() purposefully do nothing + $connection = $this->getMockBuilder('Doctrine\DBAL\Connection') + ->disableOriginalConstructor() + ->setMethods(array('connect')) + ->getMock(); + + // artificially set the wrapped connection to non-null + $reflection = new \ReflectionObject($connection); $connProperty = $reflection->getProperty('_conn'); $connProperty->setAccessible(true); - $connProperty->setValue($this->_conn, new \stdClass); - $connValue = $connProperty->getValue($this->_conn); - $this->assertInstanceOf('stdClass', $connValue); + $connProperty->setValue($connection, new \stdClass); - // close the connection - $this->_conn->close(); + // close the connection (should nullify the wrapped connection) + $connection->close(); - // make sure the _conn has be set to null (but not unset) - $connNewValue = $connProperty->getValue($this->_conn); - $this->assertNull($connNewValue, 'Connection can\'t be closed.'); + // the wrapped connection should be null + // (and since connect() does nothing, this will not reconnect) + // this will also fail if this _conn property was unset instead of set to null + $this->assertNull($connection->getWrappedConnection()); } public function testFetchAll()