Skip to content

Commit

Permalink
merge 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed May 9, 2017
2 parents 21bc7ab + 3faa4f2 commit 4acebea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function createConnection(array $params, Configuration $config = null, Ev
/** @var Connection $connection */
$connection = new $connectionWrapperClass(
$connectionOriginalDriver->getParams(),
new StaticDriver($connectionOriginalDriver->getDriver()),
new StaticDriver($connectionOriginalDriver->getDriver(), $connectionOriginalDriver->getDatabasePlatform()),
$connectionOriginalDriver->getConfiguration(),
$connectionOriginalDriver->getEventManager()
);
Expand Down
17 changes: 10 additions & 7 deletions src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\VersionAwarePlatformDriver;

class StaticDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
Expand All @@ -25,9 +26,15 @@ class StaticDriver implements Driver, ExceptionConverterDriver, VersionAwarePlat
*/
private $underlyingDriver;

public function __construct(Driver $underlyingDriver)
/**
* @var AbstractPlatform
*/
private $platform;

public function __construct(Driver $underlyingDriver, AbstractPlatform $platform)
{
$this->underlyingDriver = $underlyingDriver;
$this->platform = $platform;
}

/**
Expand All @@ -54,7 +61,7 @@ public function connect(array $params, $username = null, $password = null, array
*/
public function getDatabasePlatform()
{
return $this->underlyingDriver->getDatabasePlatform();
return $this->platform;
}

/**
Expand Down Expand Up @@ -98,11 +105,7 @@ public function convertException($message, DriverException $exception)
*/
public function createDatabasePlatformForVersion($version)
{
if ($this->underlyingDriver instanceof VersionAwarePlatformDriver) {
return $this->underlyingDriver->createDatabasePlatformForVersion($version);
}

return $this->getDatabasePlatform();
return $this->platform;
}

/**
Expand Down
23 changes: 21 additions & 2 deletions tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticConnection;
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use PHPUnit\Framework\TestCase;

class StaticDriverTest extends TestCase
{
/**
* @var AbstractPlatform|\PHPUnit_Framework_MockObject_MockObject
*/
private $platform;

public function setUp()
{
$this->platform = $this->createMock(AbstractPlatform::class);
}

public function testReturnCorrectPlatform()
{
$driver = new StaticDriver(new MockDriver(), $this->platform);

$this->assertSame($this->platform, $driver->getDatabasePlatform());
$this->assertSame($this->platform, $driver->createDatabasePlatformForVersion(1));
}

public function testConnect()
{
$driver = new StaticDriver(new MockDriver());
$driver = new StaticDriver(new MockDriver(), $this->platform);

$driver::setKeepStaticConnections(true);

Expand All @@ -20,7 +39,7 @@ public function testConnect()
$this->assertInstanceOf(StaticConnection::class, $connection1);
$this->assertNotSame($connection1->getWrappedConnection(), $connection2->getWrappedConnection());

$driver = new StaticDriver(new MockDriver());
$driver = new StaticDriver(new MockDriver(), $this->platform);

$connectionNew1 = $driver->connect(['database_name' => 1], 'user1', 'pw1');
$connectionNew2 = $driver->connect(['database_name' => 2], 'user1', 'pw2');
Expand Down

0 comments on commit 4acebea

Please sign in to comment.