Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serverVersion to be explicitly unspecified (null) #814

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}
}
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/Mocks/VersionAwareDriverMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Doctrine\Tests\Mocks;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\VersionAwarePlatformDriver;

class VersionAwareDriverMock extends DriverMock implements VersionAwarePlatformDriver
{
/**
* Factory method for creating the appropriate platform instance for the given version.
*
* @param string $version The platform/server version string to evaluate. This should be given in the notation
* the underlying database vendor uses.
*
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*
* @throws DBALException if the given version string could not be evaluated.
*/
public function createDatabasePlatformForVersion($version)
{
throw new DBALException('PHPUnit');
}
}