Commit de755610 authored by Steve Müller's avatar Steve Müller

Merge pull request #781 from rosier/detect-database-platform

Call detectDatabasePlatform only once

fixes #1068
parents 61f09cef 6fcdafe7
......@@ -324,7 +324,7 @@ class Connection implements DriverConnection
*/
public function getDatabasePlatform()
{
if (null == $this->platform) {
if (null === $this->platform) {
$this->detectDatabasePlatform();
}
......@@ -362,10 +362,6 @@ class Connection implements DriverConnection
$this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
$this->_isConnected = true;
if (null === $this->platform) {
$this->detectDatabasePlatform();
}
if (false === $this->autoCommit) {
$this->beginTransaction();
}
......
......@@ -527,4 +527,40 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
call_user_func_array(array($conn, $method), $params);
}
/**
* @group DBAL-1127
*/
public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform()
{
/** @var \Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock|\PHPUnit_Framework_MockObject_MockObject $driverMock */
$driverMock = $this->getMock('Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock');
/** @var \Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock|\PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */
$driverConnectionMock = $this->getMock('Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock');
/** @var \Doctrine\DBAL\Platforms\AbstractPlatform|\PHPUnit_Framework_MockObject_MockObject $platformMock */
$platformMock = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform');
$connection = new Connection(array(), $driverMock);
$driverMock->expects($this->once())
->method('connect')
->will($this->returnValue($driverConnectionMock));
$driverConnectionMock->expects($this->once())
->method('requiresQueryForServerVersion')
->will($this->returnValue(false));
$driverConnectionMock->expects($this->once())
->method('getServerVersion')
->will($this->returnValue('6.6.6'));
$driverMock->expects($this->once())
->method('createDatabasePlatformForVersion')
->with('6.6.6')
->will($this->returnValue($platformMock));
$this->assertSame($platformMock, $connection->getDatabasePlatform());
}
}
<?php
namespace Doctrine\Tests\Mocks;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
interface ServerInfoAwareConnectionMock extends Connection, ServerInfoAwareConnection
{
}
<?php
namespace Doctrine\Tests\Mocks;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\VersionAwarePlatformDriver;
interface VersionAwarePlatformDriverMock extends Driver, VersionAwarePlatformDriver
{
}
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