diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index d3d7eb1ccc0..7ab06dac797 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -418,7 +418,7 @@ private function getDatabasePlatformVersion() } // Explicit platform version requested (supersedes auto-detection). - if (isset($this->_params['serverVersion'])) { + if (array_key_exists('serverVersion', $this->_params)) { return $this->_params['serverVersion']; } diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 188bb7af197..d11c7121ac0 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Events; use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\DriverMock; +use Doctrine\Tests\Mocks\VersionAwareDriverMock; class ConnectionTest extends \Doctrine\Tests\DbalTestCase { @@ -563,4 +564,23 @@ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() $this->assertSame($platformMock, $connection->getDatabasePlatform()); } + + public function testNullServerVersionDoesNotTriggerDatabaseConnect() + { + $driverMock = new VersionAwareDriverMock(); + $params = $this->params; + $params['serverVersion'] = null; + + $connection = $this->getMock( + 'Doctrine\DBAL\Connection', + array('connect'), + array($params, $driverMock) + ); + + $connection->expects($this->never()) + ->method('connect'); + + + $connection->getDatabasePlatform(); + } } diff --git a/tests/Doctrine/Tests/Mocks/VersionAwareDriverMock.php b/tests/Doctrine/Tests/Mocks/VersionAwareDriverMock.php new file mode 100644 index 00000000000..c88c49238e9 --- /dev/null +++ b/tests/Doctrine/Tests/Mocks/VersionAwareDriverMock.php @@ -0,0 +1,24 @@ +