Skip to content

Commit a9ff7d7

Browse files
authored
fix: support custom platforms (#254)
fixes #253
1 parent df1003f commit a9ff7d7

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function connect(array $params): DriverConnection
4747

4848
$connection = self::$connections[$key];
4949

50-
$platform = isset($params['serverVersion'])
50+
$platform = $params['platform'] ?? (isset($params['serverVersion'])
5151
? $this->createDatabasePlatformForVersion($params['serverVersion'])
52-
: $this->getDatabasePlatform();
52+
: $this->getDatabasePlatform());
5353

5454
if (!$platform->supportsSavepoints() || !$platform->supportsReleaseSavepoints()) {
5555
throw new \RuntimeException('This bundle only works for database platforms that support savepoints.');

tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriverTest.php

+61-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,67 @@ public function testConnect(): void
2323
'user' => 'user',
2424
'password' => 'password',
2525
'port' => 3306,
26-
'platform' => $this->createMock(AbstractPlatform::class),
26+
'dama.keep_static' => true,
27+
'dama.connection_name' => 'foo',
28+
'some_closure' => function (): void {},
29+
];
30+
31+
/** @var StaticConnection $connection1 */
32+
$connection1 = $driver->connect(['dama.connection_name' => 'foo'] + $params);
33+
/** @var StaticConnection $connection2 */
34+
$connection2 = $driver->connect(['dama.connection_name' => 'bar'] + $params);
35+
36+
$this->assertInstanceOf(StaticConnection::class, $connection1);
37+
$this->assertNotSame($connection1->getWrappedConnection(), $connection2->getWrappedConnection());
38+
39+
$driver = new StaticDriver(new MockDriver());
40+
41+
/** @var StaticConnection $connectionNew1 */
42+
$connectionNew1 = $driver->connect(['dama.connection_name' => 'foo'] + $params);
43+
/** @var StaticConnection $connectionNew2 */
44+
$connectionNew2 = $driver->connect(['dama.connection_name' => 'bar'] + $params);
45+
46+
$this->assertSame($connection1->getWrappedConnection(), $connectionNew1->getWrappedConnection());
47+
$this->assertSame($connection2->getWrappedConnection(), $connectionNew2->getWrappedConnection());
48+
49+
/** @var StaticConnection $connection1 */
50+
$connection1 = $driver->connect($params);
51+
/** @var StaticConnection $connection2 */
52+
$connection2 = $driver->connect($params);
53+
$this->assertSame($connection1->getWrappedConnection(), $connection2->getWrappedConnection());
54+
55+
/** @var StaticConnection $connection3 */
56+
$connection3 = $driver->connect(['host' => 'bar'] + $params);
57+
$this->assertNotSame($connection1->getWrappedConnection(), $connection3->getWrappedConnection());
58+
}
59+
60+
public function testConnectWithPlatform(): void
61+
{
62+
$driver = new StaticDriver(new MockDriver());
63+
64+
$driver::setKeepStaticConnections(true);
65+
66+
$platform = $this->createMock(AbstractPlatform::class);
67+
$platform
68+
->expects(self::exactly(7))
69+
->method('supportsSavepoints')
70+
->willReturn(true)
71+
;
72+
$platform
73+
->expects(self::exactly(7))
74+
->method('supportsReleaseSavepoints')
75+
->willReturn(true)
76+
;
77+
78+
$params = [
79+
'driver' => 'pdo_mysql',
80+
'charset' => 'UTF8',
81+
'host' => 'foo',
82+
'dbname' => 'doctrine_test_bundle',
83+
'user' => 'user',
84+
'password' => 'password',
85+
'port' => 3306,
86+
'platform' => $platform,
2787
'dama.keep_static' => true,
2888
'dama.connection_name' => 'foo',
2989
'some_closure' => function (): void {},

0 commit comments

Comments
 (0)