Commit 9d8be7b1 authored by Ryan Weaver's avatar Ryan Weaver

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.
parent d766fb4a
...@@ -401,22 +401,27 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); ...@@ -401,22 +401,27 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this->assertSame($result, $conn->fetchColumn($statement, $params, $column, $types)); $this->assertSame($result, $conn->fetchColumn($statement, $params, $column, $types));
} }
public function testConnectionIsClosed() public function testConnectionIsClosedButNotUnset()
{ {
// set the internal _conn to some value // mock Connection, and make connect() purposefully do nothing
$reflection = new \ReflectionObject($this->_conn); $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 = $reflection->getProperty('_conn');
$connProperty->setAccessible(true); $connProperty->setAccessible(true);
$connProperty->setValue($this->_conn, new \stdClass); $connProperty->setValue($connection, new \stdClass);
$connValue = $connProperty->getValue($this->_conn);
$this->assertInstanceOf('stdClass', $connValue);
// close the connection // close the connection (should nullify the wrapped connection)
$this->_conn->close(); $connection->close();
// make sure the _conn has be set to null (but not unset) // the wrapped connection should be null
$connNewValue = $connProperty->getValue($this->_conn); // (and since connect() does nothing, this will not reconnect)
$this->assertNull($connNewValue, 'Connection can\'t be closed.'); // this will also fail if this _conn property was unset instead of set to null
$this->assertNull($connection->getWrappedConnection());
} }
public function testFetchAll() public function testFetchAll()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment