Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 58d74e3

Browse filesBrowse files
JeroenyTobion
authored andcommitted
[Cache] Support decorated Dbal drivers in PdoAdapter
1 parent ba7e97d commit 58d74e3
Copy full SHA for 58d74e3

File tree

Expand file treeCollapse file tree

4 files changed

+86
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+86
-0
lines changed

‎.github/patch-types.php

Copy file name to clipboardExpand all lines: .github/patch-types.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
case false !== strpos($file = realpath($file), '/vendor/'):
2626
case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'):
2727
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
28+
case false !== strpos($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'):
2829
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'):
2930
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php'):
3031
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/ParseError.php'):

‎src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use Doctrine\DBAL\Configuration;
15+
use Doctrine\DBAL\Driver\Middleware;
1416
use Doctrine\DBAL\DriverManager;
1517
use PHPUnit\Framework\SkippedTestSuiteError;
1618
use Psr\Cache\CacheItemPoolInterface;
1719
use Symfony\Component\Cache\Adapter\PdoAdapter;
20+
use Symfony\Component\Cache\Tests\Fixtures\DriverWrapper;
1821

1922
/**
2023
* @group time-sensitive
@@ -43,4 +46,29 @@ public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterfac
4346
{
4447
return new PdoAdapter(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]), '', $defaultLifetime);
4548
}
49+
50+
public function testConfigureSchemaDecoratedDbalDriver()
51+
{
52+
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]);
53+
if (!interface_exists(Middleware::class)) {
54+
$this->markTestSkipped('doctrine/dbal v2 does not support custom drivers using middleware');
55+
}
56+
57+
$middleware = $this->createMock(Middleware::class);
58+
$middleware
59+
->method('wrap')
60+
->willReturn(new DriverWrapper($connection->getDriver()));
61+
62+
$config = new Configuration();
63+
$config->setMiddlewares([$middleware]);
64+
65+
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $config);
66+
67+
$adapter = new PdoAdapter($connection);
68+
$adapter->createTable();
69+
70+
$item = $adapter->getItem('key');
71+
$item->set('value');
72+
$this->assertTrue($adapter->save($item));
73+
}
4674
}
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Fixtures;
13+
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Driver;
16+
use Doctrine\DBAL\Platforms\AbstractPlatform;
17+
use Doctrine\DBAL\Schema\AbstractSchemaManager;
18+
19+
class DriverWrapper implements Driver
20+
{
21+
/** @var Driver */
22+
private $driver;
23+
24+
public function __construct(Driver $driver)
25+
{
26+
$this->driver = $driver;
27+
}
28+
29+
public function connect(array $params, $username = null, $password = null, array $driverOptions = []): Driver\Connection
30+
{
31+
return $this->driver->connect($params, $username, $password, $driverOptions);
32+
}
33+
34+
public function getDatabasePlatform(): AbstractPlatform
35+
{
36+
return $this->driver->getDatabasePlatform();
37+
}
38+
39+
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
40+
{
41+
return $this->driver->getSchemaManager($conn, $platform);
42+
}
43+
44+
public function getExceptionConverter(): Driver\API\ExceptionConverter
45+
{
46+
return $this->driver->getExceptionConverter();
47+
}
48+
}

‎src/Symfony/Component/Cache/Traits/PdoTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/PdoTrait.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ private function getConnection()
448448
case $driver instanceof \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver:
449449
$this->driver = 'sqlsrv';
450450
break;
451+
case $driver instanceof \Doctrine\DBAL\Driver:
452+
$this->driver = [
453+
'mssql' => 'sqlsrv',
454+
'oracle' => 'oci',
455+
'postgresql' => 'pgsql',
456+
'sqlite' => 'sqlite',
457+
'mysql' => 'mysql',
458+
][$driver->getDatabasePlatform()->getName()] ?? \get_class($driver);
459+
break;
451460
default:
452461
$this->driver = \get_class($driver);
453462
break;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.