Skip to content

Commit b48de03

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: fix Doctrine deprecations fix merge Fix Doctrine deprecations [Validator] Remove internal from methods on non-internal interfaces [PhpUnitBridge] Fix support for the NO_COLOR env var
2 parents e7ada2e + c968672 commit b48de03

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

Store/DoctrineDbalPostgreSqlStore.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111

1212
namespace Symfony\Component\Lock\Store;
1313

14+
use Doctrine\DBAL\Configuration;
1415
use Doctrine\DBAL\Connection;
1516
use Doctrine\DBAL\DriverManager;
1617
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
18+
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
19+
use Doctrine\DBAL\Tools\DsnParser;
20+
use Doctrine\ORM\ORMSetup;
1721
use Symfony\Component\Lock\BlockingSharedLockStoreInterface;
1822
use Symfony\Component\Lock\BlockingStoreInterface;
1923
use Symfony\Component\Lock\Exception\InvalidArgumentException;
@@ -49,7 +53,28 @@ public function __construct(#[\SensitiveParameter] Connection|string $connOrUrl)
4953
if (!class_exists(DriverManager::class)) {
5054
throw new InvalidArgumentException('Failed to parse DSN. Try running "composer require doctrine/dbal".');
5155
}
52-
$this->conn = DriverManager::getConnection(['url' => $this->filterDsn($connOrUrl)]);
56+
if (class_exists(DsnParser::class)) {
57+
$params = (new DsnParser([
58+
'db2' => 'ibm_db2',
59+
'mssql' => 'pdo_sqlsrv',
60+
'mysql' => 'pdo_mysql',
61+
'mysql2' => 'pdo_mysql',
62+
'postgres' => 'pdo_pgsql',
63+
'postgresql' => 'pdo_pgsql',
64+
'pgsql' => 'pdo_pgsql',
65+
'sqlite' => 'pdo_sqlite',
66+
'sqlite3' => 'pdo_sqlite',
67+
]))->parse($this->filterDsn($connOrUrl));
68+
} else {
69+
$params = ['url' => $this->filterDsn($connOrUrl)];
70+
}
71+
72+
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration();
73+
if (class_exists(DefaultSchemaManagerFactory::class)) {
74+
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
75+
}
76+
77+
$this->conn = DriverManager::getConnection($params, $config);
5378
}
5479
}
5580

Store/DoctrineDbalStore.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
namespace Symfony\Component\Lock\Store;
1313

14+
use Doctrine\DBAL\Configuration;
1415
use Doctrine\DBAL\Connection;
1516
use Doctrine\DBAL\DriverManager;
1617
use Doctrine\DBAL\Exception as DBALException;
1718
use Doctrine\DBAL\Exception\TableNotFoundException;
1819
use Doctrine\DBAL\ParameterType;
20+
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
1921
use Doctrine\DBAL\Schema\Schema;
22+
use Doctrine\DBAL\Tools\DsnParser;
23+
use Doctrine\ORM\ORMSetup;
2024
use Symfony\Component\Lock\Exception\InvalidArgumentException;
2125
use Symfony\Component\Lock\Exception\InvalidTtlException;
2226
use Symfony\Component\Lock\Exception\LockConflictedException;
@@ -68,7 +72,28 @@ public function __construct(Connection|string $connOrUrl, array $options = [], f
6872
if (!class_exists(DriverManager::class)) {
6973
throw new InvalidArgumentException('Failed to parse the DSN. Try running "composer require doctrine/dbal".');
7074
}
71-
$this->conn = DriverManager::getConnection(['url' => $connOrUrl]);
75+
if (class_exists(DsnParser::class)) {
76+
$params = (new DsnParser([
77+
'db2' => 'ibm_db2',
78+
'mssql' => 'pdo_sqlsrv',
79+
'mysql' => 'pdo_mysql',
80+
'mysql2' => 'pdo_mysql',
81+
'postgres' => 'pdo_pgsql',
82+
'postgresql' => 'pdo_pgsql',
83+
'pgsql' => 'pdo_pgsql',
84+
'sqlite' => 'pdo_sqlite',
85+
'sqlite3' => 'pdo_sqlite',
86+
]))->parse($connOrUrl);
87+
} else {
88+
$params = ['url' => $connOrUrl];
89+
}
90+
91+
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration();
92+
if (class_exists(DefaultSchemaManagerFactory::class)) {
93+
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
94+
}
95+
96+
$this->conn = DriverManager::getConnection($params, $config);
7297
}
7398
}
7499

Tests/Store/DoctrineDbalPostgreSqlStoreTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Doctrine\DBAL\Configuration;
1415
use Doctrine\DBAL\Connection;
1516
use Doctrine\DBAL\DriverManager;
1617
use Doctrine\DBAL\Exception as DBALException;
18+
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
19+
use Doctrine\DBAL\Tools\DsnParser;
20+
use Doctrine\ORM\ORMSetup;
1721
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1822
use Symfony\Component\Lock\Exception\LockConflictedException;
1923
use Symfony\Component\Lock\Key;
@@ -38,7 +42,7 @@ public function createPostgreSqlConnection(): Connection
3842
$this->markTestSkipped('Missing POSTGRES_HOST env variable');
3943
}
4044

41-
return DriverManager::getConnection(['url' => 'pgsql://postgres:password@'.getenv('POSTGRES_HOST')]);
45+
return self::getDbalConnection('pdo-pgsql://postgres:password@'.getenv('POSTGRES_HOST'));
4246
}
4347

4448
public function getStore(): PersistingStoreInterface
@@ -65,7 +69,7 @@ public function testInvalidDriver($connOrDsn)
6569
public static function getInvalidDrivers()
6670
{
6771
yield ['sqlite:///tmp/foo.db'];
68-
yield [DriverManager::getConnection(['url' => 'sqlite:///tmp/foo.db'])];
72+
yield [self::getDbalConnection('sqlite:///tmp/foo.db')];
6973
}
7074

7175
public function testSaveAfterConflict()
@@ -165,4 +169,15 @@ public function testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore()
165169

166170
$this->assertTrue($store2->exists($store2Key));
167171
}
172+
173+
private static function getDbalConnection(string $dsn): Connection
174+
{
175+
$params = class_exists(DsnParser::class) ? (new DsnParser(['sqlite' => 'pdo_sqlite']))->parse($dsn) : ['url' => $dsn];
176+
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
177+
if (class_exists(DefaultSchemaManagerFactory::class)) {
178+
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
179+
}
180+
181+
return DriverManager::getConnection($params, $config);
182+
}
168183
}

Tests/Store/DoctrineDbalStoreTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Doctrine\DBAL\Configuration;
1415
use Doctrine\DBAL\Connection;
1516
use Doctrine\DBAL\DriverManager;
1617
use Doctrine\DBAL\Exception\TableNotFoundException;
1718
use Doctrine\DBAL\Platforms\AbstractPlatform;
1819
use Doctrine\DBAL\Schema\Schema;
20+
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
21+
use Doctrine\ORM\ORMSetup;
1922
use Symfony\Component\Lock\Key;
2023
use Symfony\Component\Lock\PersistingStoreInterface;
2124
use Symfony\Component\Lock\Store\DoctrineDbalStore;
@@ -37,7 +40,12 @@ public static function setUpBeforeClass(): void
3740
{
3841
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_lock');
3942

40-
$store = new DoctrineDbalStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]));
43+
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
44+
if (class_exists(DefaultSchemaManagerFactory::class)) {
45+
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
46+
}
47+
48+
$store = new DoctrineDbalStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $config));
4149
$store->createTable();
4250
}
4351

@@ -53,7 +61,12 @@ protected function getClockDelay()
5361

5462
public function getStore(): PersistingStoreInterface
5563
{
56-
return new DoctrineDbalStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]));
64+
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
65+
if (class_exists(DefaultSchemaManagerFactory::class)) {
66+
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
67+
}
68+
69+
return new DoctrineDbalStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $config));
5770
}
5871

5972
public function testAbortAfterExpiration()

0 commit comments

Comments
 (0)