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\"");
$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()
......
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