From eacfedfa2fc777f5db135bb4ba19ceca3f0c6334 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 6 Jun 2023 12:31:50 +0200 Subject: [PATCH] Kill DBAL 2 support --- composer.json | 4 +- .../DataCollector/DoctrineDataCollector.php | 30 +---- .../Form/ChoiceList/ORMQueryBuilderLoader.php | 7 +- .../RememberMe/DoctrineTokenProvider.php | 37 ++---- .../DoctrineDataCollectorTest.php | 75 ++++++++++- .../DoctrineDataCollectorTestTrait.php | 88 ------------- .../Doctrine/Tests/DoctrineTestHelper.php | 4 +- .../ChoiceList/ORMQueryBuilderLoaderTest.php | 17 ++- .../DoctrinePingConnectionMiddlewareTest.php | 7 -- .../Tests/Middleware/Debug/MiddlewareTest.php | 4 +- .../PropertyInfo/DoctrineExtractorTest.php | 4 +- .../RememberMe/DoctrineTokenProviderTest.php | 13 +- .../Doctrine/Tests/Types/UlidTypeTest.php | 8 +- .../Doctrine/Tests/Types/UuidTypeTest.php | 9 +- .../Bridge/Doctrine/Types/AbstractUidType.php | 7 +- src/Symfony/Bridge/Doctrine/composer.json | 4 +- .../Cache/Adapter/DoctrineDbalAdapter.php | 45 +++---- .../Tests/Adapter/DoctrineDbalAdapterTest.php | 15 ++- .../Cache/Tests/Fixtures/DriverWrapper.php | 48 ------- src/Symfony/Component/Cache/composer.json | 4 +- .../Storage/Handler/SessionHandlerFactory.php | 6 +- .../Component/HttpFoundation/composer.json | 3 +- .../Store/DoctrineDbalPostgreSqlStore.php | 30 ++--- .../Lock/Store/DoctrineDbalStore.php | 43 +++---- .../Store/DoctrineDbalPostgreSqlStoreTest.php | 6 +- .../Tests/Store/DoctrineDbalStoreTest.php | 8 +- src/Symfony/Component/Lock/composer.json | 4 +- .../Tests/Transport/ConnectionTest.php | 68 ++++------ .../Transport/DoctrineIntegrationTest.php | 22 +--- .../DoctrinePostgreSqlIntegrationTest.php | 12 +- .../Tests/Transport/DoctrineReceiverTest.php | 11 +- .../DoctrineTransportFactoryTest.php | 13 -- .../Transport/PostgreSqlConnectionTest.php | 34 ++--- .../Bridge/Doctrine/Transport/Connection.php | 119 +++++------------- .../Messenger/Bridge/Doctrine/composer.json | 2 +- 35 files changed, 247 insertions(+), 564 deletions(-) delete mode 100644 src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTestTrait.php delete mode 100644 src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php diff --git a/composer.json b/composer.json index b088b44081615..8144b42e051ad 100644 --- a/composer.json +++ b/composer.json @@ -129,7 +129,7 @@ "doctrine/annotations": "^1.13.1|^2", "doctrine/collections": "^1.0|^2.0", "doctrine/data-fixtures": "^1.1", - "doctrine/dbal": "^2.13.1|^3.0", + "doctrine/dbal": "^3.6", "doctrine/orm": "^2.15", "dragonmantank/cron-expression": "^3", "egulias/email-validator": "^2.1.10|^3.1|^4", @@ -161,7 +161,7 @@ "ext-psr": "<1.1|>=2", "async-aws/core": "<1.5", "doctrine/annotations": "<1.13.1", - "doctrine/dbal": "<2.13.1", + "doctrine/dbal": "<3.6", "doctrine/orm": "<2.15", "egulias/email-validator": "~3.0.0", "masterminds/html5": "<2.6", diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index f127a38708f29..c61c28a147a72 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -11,7 +11,6 @@ namespace Symfony\Bridge\Doctrine\DataCollector; -use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\Persistence\ManagerRegistry; @@ -32,11 +31,6 @@ class DoctrineDataCollector extends DataCollector private array $connections; private array $managers; - /** - * @var array - */ - private array $loggers = []; - public function __construct( private ManagerRegistry $registry, private DebugDataHolder $debugDataHolder, @@ -61,16 +55,8 @@ private function collectQueries(): array { $queries = []; - if (null !== $this->debugDataHolder) { - foreach ($this->debugDataHolder->getData() as $name => $data) { - $queries[$name] = $this->sanitizeQueries($name, $data); - } - - return $queries; - } - - foreach ($this->loggers as $name => $logger) { - $queries[$name] = $this->sanitizeQueries($name, $logger->queries); + foreach ($this->debugDataHolder->getData() as $name => $data) { + $queries[$name] = $this->sanitizeQueries($name, $data); } return $queries; @@ -82,17 +68,7 @@ private function collectQueries(): array public function reset() { $this->data = []; - - if (null !== $this->debugDataHolder) { - $this->debugDataHolder->reset(); - - return; - } - - foreach ($this->loggers as $logger) { - $logger->queries = []; - $logger->currentQuery = 0; - } + $this->debugDataHolder->reset(); } public function getManagers() diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index e3a4c021f0ce2..f8cf68d75feff 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -12,7 +12,6 @@ namespace Symfony\Bridge\Doctrine\Form\ChoiceList; use Doctrine\DBAL\ArrayParameterType; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\QueryBuilder; @@ -71,13 +70,13 @@ public function getEntitiesByIds(string $identifier, array $values): array $entity = current($qb->getRootEntities()); $metadata = $qb->getEntityManager()->getClassMetadata($entity); if (\in_array($type = $metadata->getTypeOfField($identifier), ['integer', 'bigint', 'smallint'])) { - $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY; + $parameterType = ArrayParameterType::INTEGER; // Filter out non-integer values (e.g. ""). If we don't, some // databases such as PostgreSQL fail. $values = array_values(array_filter($values, fn ($v) => (string) $v === (string) (int) $v || ctype_digit($v))); } elseif (\in_array($type, ['ulid', 'uuid', 'guid'])) { - $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY; + $parameterType = ArrayParameterType::STRING; // Like above, but we just filter out empty strings. $values = array_values(array_filter($values, fn ($v) => '' !== (string) $v)); @@ -96,7 +95,7 @@ public function getEntitiesByIds(string $identifier, array $values): array unset($value); } } else { - $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY; + $parameterType = ArrayParameterType::STRING; } if (!$values) { return []; diff --git a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php index 3af51ffd60deb..f4fb8173e85ff 100644 --- a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php @@ -12,9 +12,7 @@ namespace Symfony\Bridge\Doctrine\Security\RememberMe; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\Result as DriverResult; use Doctrine\DBAL\ParameterType; -use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Types\Types; use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken; @@ -43,11 +41,9 @@ */ class DoctrineTokenProvider implements TokenProviderInterface, TokenVerifierInterface { - private Connection $conn; - - public function __construct(Connection $conn) - { - $this->conn = $conn; + public function __construct( + private Connection $conn, + ) { } public function loadTokenBySeries(string $series): PersistentTokenInterface @@ -57,13 +53,9 @@ public function loadTokenBySeries(string $series): PersistentTokenInterface $paramValues = ['series' => $series]; $paramTypes = ['series' => ParameterType::STRING]; $stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes); - $row = $stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC); - - if ($row) { - return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['last_used'])); - } + $row = $stmt->fetchAssociative() ?: throw new TokenNotFoundException('No token found.'); - throw new TokenNotFoundException('No token found.'); + return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['last_used'])); } /** @@ -74,11 +66,7 @@ public function deleteTokenBySeries(string $series) $sql = 'DELETE FROM rememberme_token WHERE series=:series'; $paramValues = ['series' => $series]; $paramTypes = ['series' => ParameterType::STRING]; - if (method_exists($this->conn, 'executeStatement')) { - $this->conn->executeStatement($sql, $paramValues, $paramTypes); - } else { - $this->conn->executeUpdate($sql, $paramValues, $paramTypes); - } + $this->conn->executeStatement($sql, $paramValues, $paramTypes); } /** @@ -97,11 +85,8 @@ public function updateToken(string $series, #[\SensitiveParameter] string $token 'lastUsed' => Types::DATETIME_IMMUTABLE, 'series' => ParameterType::STRING, ]; - if (method_exists($this->conn, 'executeStatement')) { - $updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes); - } else { - $updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes); - } + $updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes); + if ($updated < 1) { throw new TokenNotFoundException('No token found.'); } @@ -127,11 +112,7 @@ public function createNewToken(PersistentTokenInterface $token) 'value' => ParameterType::STRING, 'lastUsed' => Types::DATETIME_IMMUTABLE, ]; - if (method_exists($this->conn, 'executeStatement')) { - $this->conn->executeStatement($sql, $paramValues, $paramTypes); - } else { - $this->conn->executeUpdate($sql, $paramValues, $paramTypes); - } + $this->conn->executeStatement($sql, $paramValues, $paramTypes); } public function verifyToken(PersistentTokenInterface $token, #[\SensitiveParameter] string $tokenValue): bool diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php index 8146adb9f8e87..11ce08c81190c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -25,19 +25,84 @@ use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Dumper\CliDumper; -// Doctrine DBAL 2 compatibility -class_exists(\Doctrine\DBAL\Platforms\MySqlPlatform::class); - class DoctrineDataCollectorTest extends TestCase { - use DoctrineDataCollectorTestTrait; - protected function setUp(): void { ClockMock::register(self::class); ClockMock::withClockMock(1500000000); } + public function testCollectConnections() + { + $c = $this->createCollector([]); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + $this->assertEquals(['default' => 'doctrine.dbal.default_connection'], $c->getConnections()); + } + + public function testCollectManagers() + { + $c = $this->createCollector([]); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + $this->assertEquals(['default' => 'doctrine.orm.default_entity_manager'], $c->getManagers()); + } + + public function testCollectQueryCount() + { + $c = $this->createCollector([]); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + $this->assertEquals(0, $c->getQueryCount()); + + $queries = [ + ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 0], + ]; + $c = $this->createCollector($queries); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + $this->assertEquals(1, $c->getQueryCount()); + } + + public function testCollectTime() + { + $c = $this->createCollector([]); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + $this->assertEquals(0, $c->getTime()); + + $queries = [ + ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1], + ]; + $c = $this->createCollector($queries); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + $this->assertEquals(1, $c->getTime()); + + $queries = [ + ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1], + ['sql' => 'SELECT * FROM table2', 'params' => [], 'types' => [], 'executionMS' => 2], + ]; + $c = $this->createCollector($queries); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + $this->assertEquals(3, $c->getTime()); + } + + public function testCollectQueryWithNoTypes() + { + $queries = [ + ['sql' => 'SET sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))', 'params' => [], 'types' => null, 'executionMS' => 1], + ]; + $c = $this->createCollector($queries); + $c->collect(new Request(), new Response()); + $c = unserialize(serialize($c)); + + $collectedQueries = $c->getQueries(); + $this->assertSame([], $collectedQueries['default'][0]['types']); + } + public function testReset() { $queries = [ diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTestTrait.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTestTrait.php deleted file mode 100644 index 4ca941f10094d..0000000000000 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTestTrait.php +++ /dev/null @@ -1,88 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\Doctrine\Tests\DataCollector; - -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; - -trait DoctrineDataCollectorTestTrait -{ - public function testCollectConnections() - { - $c = $this->createCollector([]); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - $this->assertEquals(['default' => 'doctrine.dbal.default_connection'], $c->getConnections()); - } - - public function testCollectManagers() - { - $c = $this->createCollector([]); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - $this->assertEquals(['default' => 'doctrine.orm.default_entity_manager'], $c->getManagers()); - } - - public function testCollectQueryCount() - { - $c = $this->createCollector([]); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - $this->assertEquals(0, $c->getQueryCount()); - - $queries = [ - ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 0], - ]; - $c = $this->createCollector($queries); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - $this->assertEquals(1, $c->getQueryCount()); - } - - public function testCollectTime() - { - $c = $this->createCollector([]); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - $this->assertEquals(0, $c->getTime()); - - $queries = [ - ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1], - ]; - $c = $this->createCollector($queries); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - $this->assertEquals(1, $c->getTime()); - - $queries = [ - ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1], - ['sql' => 'SELECT * FROM table2', 'params' => [], 'types' => [], 'executionMS' => 2], - ]; - $c = $this->createCollector($queries); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - $this->assertEquals(3, $c->getTime()); - } - - public function testCollectQueryWithNoTypes() - { - $queries = [ - ['sql' => 'SET sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))', 'params' => [], 'types' => null, 'executionMS' => 1], - ]; - $c = $this->createCollector($queries); - $c->collect(new Request(), new Response()); - $c = unserialize(serialize($c)); - - $collectedQueries = $c->getQueries(); - $this->assertSame([], $collectedQueries['default'][0]['types']); - } -} diff --git a/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php b/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php index 14d677414ed20..3b9d93fc1f85e 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php @@ -58,9 +58,7 @@ public static function createTestConfiguration(): Configuration $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('SymfonyTests\Doctrine'); $config->setMetadataDriverImpl(new AttributeDriver([__DIR__.'/../Tests/Fixtures' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'], true)); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); return $config; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php index c1cef742e3d28..3566469367e60 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php @@ -12,7 +12,6 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList; use Doctrine\DBAL\ArrayParameterType; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\Result; use Doctrine\DBAL\Types\GuidType; use Doctrine\DBAL\Types\Type; @@ -38,12 +37,12 @@ protected function tearDown(): void public function testIdentifierTypeIsStringArray() { - $this->checkIdentifierType(SingleStringIdEntity::class, class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY); + $this->checkIdentifierType(SingleStringIdEntity::class, ArrayParameterType::STRING); } public function testIdentifierTypeIsIntegerArray() { - $this->checkIdentifierType(SingleIntIdEntity::class, class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY); + $this->checkIdentifierType(SingleIntIdEntity::class, ArrayParameterType::INTEGER); } protected function checkIdentifierType($classname, $expectedType) @@ -93,7 +92,7 @@ public function testFilterNonIntegerValues() $query->expects($this->once()) ->method('setParameter') - ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [1, 2, 3, '9223372036854775808'], class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY) + ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [1, 2, 3, '9223372036854775808'], ArrayParameterType::INTEGER) ->willReturn($query); $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) @@ -129,7 +128,7 @@ public function testFilterEmptyUuids($entityClass) $query->expects($this->once()) ->method('setParameter') - ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d', 'b98e8e11-2897-44df-ad24-d2627eb7f499'], class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY) + ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d', 'b98e8e11-2897-44df-ad24-d2627eb7f499'], ArrayParameterType::STRING) ->willReturn($query); $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) @@ -174,7 +173,7 @@ public function testFilterUid($entityClass) $query->expects($this->once()) ->method('setParameter') - ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [Uuid::fromString('71c5fd46-3f16-4abb-bad7-90ac1e654a2d')->toBinary(), Uuid::fromString('b98e8e11-2897-44df-ad24-d2627eb7f499')->toBinary()], class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY) + ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [Uuid::fromString('71c5fd46-3f16-4abb-bad7-90ac1e654a2d')->toBinary(), Uuid::fromString('b98e8e11-2897-44df-ad24-d2627eb7f499')->toBinary()], ArrayParameterType::STRING) ->willReturn($query); $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) @@ -242,7 +241,7 @@ public function testEmbeddedIdentifierName() $query->expects($this->once()) ->method('setParameter') - ->with('ORMQueryBuilderLoader_getEntitiesByIds_id_value', [1, 2, 3], class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY) + ->with('ORMQueryBuilderLoader_getEntitiesByIds_id_value', [1, 2, 3], ArrayParameterType::INTEGER) ->willReturn($query); $qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class) @@ -260,7 +259,7 @@ public function testEmbeddedIdentifierName() $loader->getEntitiesByIds('id.value', [1, '', 2, 3, 'foo']); } - public static function provideGuidEntityClasses() + public static function provideGuidEntityClasses(): array { return [ ['Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity'], @@ -268,7 +267,7 @@ public static function provideGuidEntityClasses() ]; } - public static function provideUidEntityClasses() + public static function provideUidEntityClasses(): array { return [ ['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'], diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php index 6c7bf67bc08af..c3f60421ebe16 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php @@ -102,13 +102,6 @@ public function testInvalidEntityManagerThrowsException() public function testMiddlewareNoPingInNonWorkerContext() { - // This method has been removed in DBAL 3.0 - if (method_exists(Connection::class, 'ping')) { - $this->connection->expects($this->never()) - ->method('ping') - ->willReturn(false); - } - $this->connection->expects($this->never()) ->method('close') ; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php index 84e48fbdf44df..f4f7075dff7ed 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php @@ -52,9 +52,7 @@ private function init(bool $withStopwatch = true): void $this->stopwatch = $withStopwatch ? new Stopwatch() : null; $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $this->debugDataHolder = new DebugDataHolder(); $config->setMiddlewares([new Middleware($this->debugDataHolder, $this->stopwatch)]); diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index 3e6eeaea0f76d..57ec2550b9e19 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -38,9 +38,7 @@ private function createExtractor(): DoctrineExtractor { $config = ORMSetup::createConfiguration(true); $config->setMetadataDriverImpl(new AttributeDriver([__DIR__.'/../Tests/Fixtures' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'], true)); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $eventManager = new EventManager(); $entityManager = new EntityManager(DriverManager::getConnection(['driver' => 'pdo_sqlite'], $config, $eventManager), $config, $eventManager); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php index 5aecb27d870a4..0da435a36ba2d 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php @@ -118,21 +118,16 @@ public function testVerifyOutdatedTokenAfterParallelRequestFailsAfter60Seconds() $this->assertFalse($provider->verifyToken($token, $oldValue)); } - /** - * @return DoctrineTokenProvider - */ - private function bootstrapProvider() + private function bootstrapProvider(): DoctrineTokenProvider { $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $connection = DriverManager::getConnection([ 'driver' => 'pdo_sqlite', 'memory' => true, ], $config); - $connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<< 'SQL' + $connection->executeStatement(<<< 'SQL' CREATE TABLE rememberme_token ( series char(88) UNIQUE PRIMARY KEY NOT NULL, value char(88) NOT NULL, @@ -140,7 +135,7 @@ private function bootstrapProvider() class varchar(100) NOT NULL, username varchar(200) NOT NULL ); -SQL + SQL ); return new DoctrineTokenProvider($connection); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Types/UlidTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Types/UlidTypeTest.php index c1db2bbe70124..d86511d5883ab 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Types/UlidTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Types/UlidTypeTest.php @@ -23,9 +23,6 @@ use Symfony\Component\Uid\AbstractUid; use Symfony\Component\Uid\Ulid; -// DBAL 2 compatibility -class_exists('Doctrine\DBAL\Platforms\PostgreSqlPlatform'); - final class UlidTypeTest extends TestCase { private const DUMMY_ULID = '01EEDQEK6ZAZE93J8KG5B4MBJC'; @@ -146,10 +143,7 @@ public static function provideSqlDeclarations(): \Generator yield [new PostgreSQLPlatform(), 'UUID']; yield [new SqlitePlatform(), 'BLOB']; yield [new MySQLPlatform(), 'BINARY(16)']; - - if (class_exists(MariaDBPlatform::class)) { - yield [new MariaDBPlatform(), 'BINARY(16)']; - } + yield [new MariaDBPlatform(), 'BINARY(16)']; } public function testRequiresSQLCommentHint() diff --git a/src/Symfony/Bridge/Doctrine/Tests/Types/UuidTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Types/UuidTypeTest.php index 120887ef3653a..e4dfdedec5b28 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Types/UuidTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Types/UuidTypeTest.php @@ -23,10 +23,6 @@ use Symfony\Component\Uid\AbstractUid; use Symfony\Component\Uid\Uuid; -// DBAL 2 compatibility -class_exists('Doctrine\DBAL\Platforms\MySqlPlatform'); -class_exists('Doctrine\DBAL\Platforms\PostgreSqlPlatform'); - final class UuidTypeTest extends TestCase { private const DUMMY_UUID = '9f755235-5a2d-4aba-9605-e9962b312e50'; @@ -158,10 +154,7 @@ public static function provideSqlDeclarations(): \Generator yield [new PostgreSQLPlatform(), 'UUID']; yield [new SqlitePlatform(), 'BLOB']; yield [new MySQLPlatform(), 'BINARY(16)']; - - if (class_exists(MariaDBPlatform::class)) { - yield [new MariaDBPlatform(), 'BINARY(16)']; - } + yield [new MariaDBPlatform(), 'BINARY(16)']; } public function testRequiresSQLCommentHint() diff --git a/src/Symfony/Bridge/Doctrine/Types/AbstractUidType.php b/src/Symfony/Bridge/Doctrine/Types/AbstractUidType.php index 6d7aac1487704..a461a5f501d76 100644 --- a/src/Symfony/Bridge/Doctrine/Types/AbstractUidType.php +++ b/src/Symfony/Bridge/Doctrine/Types/AbstractUidType.php @@ -88,11 +88,6 @@ public function requiresSQLCommentHint(AbstractPlatform $platform): bool private function hasNativeGuidType(AbstractPlatform $platform): bool { - // Compatibility with DBAL < 3.4 - $method = method_exists($platform, 'getStringTypeDeclarationSQL') - ? 'getStringTypeDeclarationSQL' - : 'getVarcharTypeDeclarationSQL'; - - return $platform->getGuidTypeDeclarationSQL([]) !== $platform->$method(['fixed' => true, 'length' => 36]); + return $platform->getGuidTypeDeclarationSQL([]) !== $platform->getStringTypeDeclarationSQL(['fixed' => true, 'length' => 36]); } } diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index ac4c06083cec2..34846fc393fee 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -44,13 +44,13 @@ "doctrine/annotations": "^1.13.1|^2", "doctrine/collections": "^1.0|^2.0", "doctrine/data-fixtures": "^1.1", - "doctrine/dbal": "^2.13.1|^3.0", + "doctrine/dbal": "^3.6", "doctrine/orm": "^2.15", "psr/log": "^1|^2|^3" }, "conflict": { "doctrine/annotations": "<1.13.1", - "doctrine/dbal": "<2.13.1", + "doctrine/dbal": "<3.6", "doctrine/lexer": "<1.1", "doctrine/orm": "<2.15", "symfony/cache": "<6.4", diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php index 377291e2f0e43..4fa9797da7b9f 100644 --- a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php @@ -71,26 +71,20 @@ public function __construct(Connection|string $connOrDsn, string $namespace = '' if (!class_exists(DriverManager::class)) { throw new InvalidArgumentException('Failed to parse DSN. Try running "composer require doctrine/dbal".'); } - if (class_exists(DsnParser::class)) { - $params = (new DsnParser([ - 'db2' => 'ibm_db2', - 'mssql' => 'pdo_sqlsrv', - 'mysql' => 'pdo_mysql', - 'mysql2' => 'pdo_mysql', - 'postgres' => 'pdo_pgsql', - 'postgresql' => 'pdo_pgsql', - 'pgsql' => 'pdo_pgsql', - 'sqlite' => 'pdo_sqlite', - 'sqlite3' => 'pdo_sqlite', - ]))->parse($connOrDsn); - } else { - $params = ['url' => $connOrDsn]; - } + $params = (new DsnParser([ + 'db2' => 'ibm_db2', + 'mssql' => 'pdo_sqlsrv', + 'mysql' => 'pdo_mysql', + 'mysql2' => 'pdo_mysql', + 'postgres' => 'pdo_pgsql', + 'postgresql' => 'pdo_pgsql', + 'pgsql' => 'pdo_pgsql', + 'sqlite' => 'pdo_sqlite', + 'sqlite3' => 'pdo_sqlite', + ]))->parse($connOrDsn); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $this->conn = DriverManager::getConnection($params, $config); } @@ -173,7 +167,7 @@ protected function doFetch(array $ids): iterable $ids, ], [ ParameterType::INTEGER, - class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY, + ArrayParameterType::STRING, ])->iterateNumeric(); foreach ($result as $row) { @@ -191,7 +185,7 @@ class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connectio $expired, ], [ ParameterType::INTEGER, - class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY, + ArrayParameterType::STRING, ]); } } @@ -234,7 +228,7 @@ protected function doDelete(array $ids): bool { $sql = "DELETE FROM $this->table WHERE $this->idCol IN (?)"; try { - $this->conn->executeStatement($sql, [array_values($ids)], [class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY]); + $this->conn->executeStatement($sql, [array_values($ids)], [ArrayParameterType::STRING]); } catch (TableNotFoundException) { } @@ -371,14 +365,11 @@ private function getPlatformName(): string $platform = $this->conn->getDatabasePlatform(); return $this->platformName = match (true) { - $platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform => 'mysql', + $platform instanceof \Doctrine\DBAL\Platforms\AbstractMySQLPlatform => 'mysql', $platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => 'sqlite', - $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform => 'pgsql', + $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform => 'pgsql', $platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => 'oci', - $platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform => 'sqlsrv', + $platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => 'sqlsrv', default => $platform::class, }; } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php index 7f250f7b53596..e1e409ddd5007 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php @@ -15,13 +15,14 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\AbstractMySQLDriver; use Doctrine\DBAL\Driver\Middleware; +use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; use Doctrine\DBAL\Schema\Schema; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\SkippedTestSuiteError; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter; -use Symfony\Component\Cache\Tests\Fixtures\DriverWrapper; /** * @group time-sensitive @@ -59,7 +60,7 @@ public function testConfigureSchemaDecoratedDbalDriver() $middleware = $this->createMock(Middleware::class); $middleware ->method('wrap') - ->willReturn(new DriverWrapper($connection->getDriver())); + ->willReturn(new class($connection->getDriver()) extends AbstractDriverMiddleware {}); $config = $this->getDbalConfig(); $config->setMiddlewares([$middleware]); @@ -125,7 +126,7 @@ public function testDsn(string $dsn, string $file = null) } } - public static function provideDsn() + public static function provideDsn(): \Generator { $dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); yield ['sqlite://localhost/'.$dbFile.'1', $dbFile.'1']; @@ -145,7 +146,7 @@ protected function isPruned(DoctrineDbalAdapter $cache, string $name): bool return 1 !== (int) $result->fetchOne(); } - private function createConnectionMock() + private function createConnectionMock(): Connection&MockObject { $connection = $this->createMock(Connection::class); $driver = $this->createMock(AbstractMySQLDriver::class); @@ -156,12 +157,10 @@ private function createConnectionMock() return $connection; } - private function getDbalConfig() + private function getDbalConfig(): Configuration { $config = new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); return $config; } diff --git a/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php b/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php deleted file mode 100644 index bb73d8d0cf240..0000000000000 --- a/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Cache\Tests\Fixtures; - -use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\AbstractSchemaManager; - -class DriverWrapper implements Driver -{ - /** @var Driver */ - private $driver; - - public function __construct(Driver $driver) - { - $this->driver = $driver; - } - - public function connect(array $params, $username = null, $password = null, array $driverOptions = []): Driver\Connection - { - return $this->driver->connect($params, $username, $password, $driverOptions); - } - - public function getDatabasePlatform(): AbstractPlatform - { - return $this->driver->getDatabasePlatform(); - } - - public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager - { - return $this->driver->getSchemaManager($conn, $platform); - } - - public function getExceptionConverter(): Driver\API\ExceptionConverter - { - return $this->driver->getExceptionConverter(); - } -} diff --git a/src/Symfony/Component/Cache/composer.json b/src/Symfony/Component/Cache/composer.json index 6e59022bf756b..2668ac85e2cc3 100644 --- a/src/Symfony/Component/Cache/composer.json +++ b/src/Symfony/Component/Cache/composer.json @@ -30,7 +30,7 @@ }, "require-dev": { "cache/integration-tests": "dev-master", - "doctrine/dbal": "^2.13.1|^3.0", + "doctrine/dbal": "^3.6", "predis/predis": "^1.1|^2.0", "psr/simple-cache": "^1.0|^2.0|^3.0", "symfony/config": "^6.4|^7.0", @@ -41,7 +41,7 @@ "symfony/var-dumper": "^6.4|^7.0" }, "conflict": { - "doctrine/dbal": "<2.13.1", + "doctrine/dbal": "<3.6", "symfony/dependency-injection": "<6.4", "symfony/http-kernel": "<6.4", "symfony/var-dumper": "<6.4" diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php index 7550002bdd19b..47af5d895dc2f 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php @@ -72,11 +72,9 @@ public static function createHandler(object|string $connection, array $options = throw new \InvalidArgumentException('Unsupported PDO OCI DSN. Try running "composer require doctrine/dbal".'); } $connection[3] = '-'; - $params = class_exists(DsnParser::class) ? (new DsnParser())->parse($connection) : ['url' => $connection]; + $params = (new DsnParser())->parse($connection); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $connection = DriverManager::getConnection($params, $config); $connection = method_exists($connection, 'getNativeConnection') ? $connection->getNativeConnection() : $connection->getWrappedConnection(); diff --git a/src/Symfony/Component/HttpFoundation/composer.json b/src/Symfony/Component/HttpFoundation/composer.json index a2f01f3b1e31c..ae25848cd590d 100644 --- a/src/Symfony/Component/HttpFoundation/composer.json +++ b/src/Symfony/Component/HttpFoundation/composer.json @@ -22,7 +22,7 @@ "symfony/polyfill-php83": "^1.27" }, "require-dev": { - "doctrine/dbal": "^2.13.1|^3.0", + "doctrine/dbal": "^3.6", "predis/predis": "^1.1|^2.0", "symfony/cache": "^6.4|^7.0", "symfony/dependency-injection": "^6.4|^7.0", @@ -32,6 +32,7 @@ "symfony/rate-limiter": "^6.4|^7.0" }, "conflict": { + "doctrine/dbal": "<3.6", "symfony/cache": "<6.4" }, "autoload": { diff --git a/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php b/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php index e6525b59f3a8b..55fffc301b3b1 100644 --- a/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php +++ b/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php @@ -53,26 +53,20 @@ public function __construct(#[\SensitiveParameter] Connection|string $connOrUrl) if (!class_exists(DriverManager::class)) { throw new InvalidArgumentException('Failed to parse DSN. Try running "composer require doctrine/dbal".'); } - if (class_exists(DsnParser::class)) { - $params = (new DsnParser([ - 'db2' => 'ibm_db2', - 'mssql' => 'pdo_sqlsrv', - 'mysql' => 'pdo_mysql', - 'mysql2' => 'pdo_mysql', - 'postgres' => 'pdo_pgsql', - 'postgresql' => 'pdo_pgsql', - 'pgsql' => 'pdo_pgsql', - 'sqlite' => 'pdo_sqlite', - 'sqlite3' => 'pdo_sqlite', - ]))->parse($this->filterDsn($connOrUrl)); - } else { - $params = ['url' => $this->filterDsn($connOrUrl)]; - } + $params = (new DsnParser([ + 'db2' => 'ibm_db2', + 'mssql' => 'pdo_sqlsrv', + 'mysql' => 'pdo_mysql', + 'mysql2' => 'pdo_mysql', + 'postgres' => 'pdo_pgsql', + 'postgresql' => 'pdo_pgsql', + 'pgsql' => 'pdo_pgsql', + 'sqlite' => 'pdo_sqlite', + 'sqlite3' => 'pdo_sqlite', + ]))->parse($this->filterDsn($connOrUrl)); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $this->conn = DriverManager::getConnection($params, $config); } diff --git a/src/Symfony/Component/Lock/Store/DoctrineDbalStore.php b/src/Symfony/Component/Lock/Store/DoctrineDbalStore.php index e915f30a795cb..e6a588ff4c61a 100644 --- a/src/Symfony/Component/Lock/Store/DoctrineDbalStore.php +++ b/src/Symfony/Component/Lock/Store/DoctrineDbalStore.php @@ -72,26 +72,20 @@ public function __construct(Connection|string $connOrUrl, array $options = [], f if (!class_exists(DriverManager::class)) { throw new InvalidArgumentException('Failed to parse the DSN. Try running "composer require doctrine/dbal".'); } - if (class_exists(DsnParser::class)) { - $params = (new DsnParser([ - 'db2' => 'ibm_db2', - 'mssql' => 'pdo_sqlsrv', - 'mysql' => 'pdo_mysql', - 'mysql2' => 'pdo_mysql', - 'postgres' => 'pdo_pgsql', - 'postgresql' => 'pdo_pgsql', - 'pgsql' => 'pdo_pgsql', - 'sqlite' => 'pdo_sqlite', - 'sqlite3' => 'pdo_sqlite', - ]))->parse($connOrUrl); - } else { - $params = ['url' => $connOrUrl]; - } + $params = (new DsnParser([ + 'db2' => 'ibm_db2', + 'mssql' => 'pdo_sqlsrv', + 'mysql' => 'pdo_mysql', + 'mysql2' => 'pdo_mysql', + 'postgres' => 'pdo_pgsql', + 'postgresql' => 'pdo_pgsql', + 'pgsql' => 'pdo_pgsql', + 'sqlite' => 'pdo_sqlite', + 'sqlite3' => 'pdo_sqlite', + ]))->parse($connOrUrl); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $this->conn = DriverManager::getConnection($params, $config); } @@ -255,14 +249,11 @@ private function getCurrentTimestampStatement(): string $platform = $this->conn->getDatabasePlatform(); return match (true) { - $platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform => 'UNIX_TIMESTAMP()', + $platform instanceof \Doctrine\DBAL\Platforms\AbstractMySQLPlatform => 'UNIX_TIMESTAMP()', $platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => 'strftime(\'%s\',\'now\')', - $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)', + $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)', $platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600', - $platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())', + $platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())', default => (string) time(), }; } @@ -276,10 +267,8 @@ private function platformSupportsTableCreationInTransaction(): bool return match (true) { $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform, $platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform, - $platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform, - $platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform => true, + $platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => true, default => false, }; } diff --git a/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalPostgreSqlStoreTest.php b/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalPostgreSqlStoreTest.php index 893902f52ac58..1ea55bfbe99ce 100644 --- a/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalPostgreSqlStoreTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalPostgreSqlStoreTest.php @@ -172,11 +172,9 @@ public function testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore() private static function getDbalConnection(string $dsn): Connection { - $params = class_exists(DsnParser::class) ? (new DsnParser(['sqlite' => 'pdo_sqlite']))->parse($dsn) : ['url' => $dsn]; + $params = (new DsnParser(['sqlite' => 'pdo_sqlite']))->parse($dsn); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); return DriverManager::getConnection($params, $config); } diff --git a/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalStoreTest.php b/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalStoreTest.php index 830e18ce5b26f..d125d36dc3eda 100644 --- a/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalStoreTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/DoctrineDbalStoreTest.php @@ -23,8 +23,6 @@ use Symfony\Component\Lock\PersistingStoreInterface; use Symfony\Component\Lock\Store\DoctrineDbalStore; -class_exists(\Doctrine\DBAL\Platforms\PostgreSqlPlatform::class); - /** * @author Jérémy Derussé * @@ -41,9 +39,7 @@ public static function setUpBeforeClass(): void self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_lock'); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $store = new DoctrineDbalStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $config)); $store->createTable(); @@ -146,7 +142,7 @@ public function testCreatesTableInTransaction(string $platform) $store->save($key); } - public static function providePlatforms() + public static function providePlatforms(): \Generator { yield [\Doctrine\DBAL\Platforms\PostgreSQLPlatform::class]; yield [\Doctrine\DBAL\Platforms\PostgreSQL94Platform::class]; diff --git a/src/Symfony/Component/Lock/composer.json b/src/Symfony/Component/Lock/composer.json index ce4b074b7a30e..f9d53d036c667 100644 --- a/src/Symfony/Component/Lock/composer.json +++ b/src/Symfony/Component/Lock/composer.json @@ -21,11 +21,11 @@ "symfony/deprecation-contracts": "^2.5|^3" }, "require-dev": { - "doctrine/dbal": "^2.13|^3.0", + "doctrine/dbal": "^3.6", "predis/predis": "^1.1|^2.0" }, "conflict": { - "doctrine/dbal": "<2.13", + "doctrine/dbal": "<3.6", "symfony/cache": "<6.4" }, "autoload": { diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php index 3dae29a4cbd66..6bbe0ae551718 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php @@ -12,18 +12,18 @@ namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport; use Doctrine\DBAL\Connection as DBALConnection; -use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MariaDBPlatform; -use Doctrine\DBAL\Platforms\MySQL57Platform; +use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; -use Doctrine\DBAL\Platforms\SQLServer2012Platform; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage; use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection; @@ -128,11 +128,7 @@ private function getDBALConnectionMock() $schemaConfig->method('getMaxIdentifierLength')->willReturn(63); $schemaConfig->method('getDefaultTableOptions')->willReturn([]); $schemaManager->method('createSchemaConfig')->willReturn($schemaConfig); - if (method_exists(DBALConnection::class, 'createSchemaManager')) { - $driverConnection->method('createSchemaManager')->willReturn($schemaManager); - } else { - $driverConnection->method('getSchemaManager')->willReturn($schemaManager); - } + $driverConnection->method('createSchemaManager')->willReturn($schemaManager); return $driverConnection; } @@ -155,12 +151,12 @@ private function getQueryBuilderMock() return $queryBuilder; } - private function getResultMock($expectedResult) + private function getResultMock($expectedResult): Result&MockObject { - $stmt = $this->createMock(class_exists(Result::class) ? Result::class : ResultStatement::class); + $stmt = $this->createMock(Result::class); $stmt->expects($this->once()) - ->method(class_exists(Result::class) ? 'fetchAssociative' : 'fetch') + ->method('fetchAssociative') ->willReturn($expectedResult); return $stmt; @@ -316,9 +312,9 @@ public function testFindAll() 'headers' => json_encode(['type' => DummyMessage::class]), ]; - $stmt = $this->createMock(class_exists(Result::class) ? Result::class : ResultStatement::class); + $stmt = $this->createMock(Result::class); $stmt->expects($this->once()) - ->method(class_exists(Result::class) ? 'fetchAllAssociative' : 'fetchAll') + ->method('fetchAllAssociative') ->willReturn([$message1, $message2]); $driverConnection @@ -361,13 +357,8 @@ public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql $driverConnection->method('getDatabasePlatform')->willReturn($platform); $driverConnection->method('createQueryBuilder')->willReturnCallback(fn () => new QueryBuilder($driverConnection)); - if (class_exists(Result::class)) { - $result = $this->createMock(Result::class); - $result->method('fetchAssociative')->willReturn(false); - } else { - $result = $this->createMock(ResultStatement::class); - $result->method('fetch')->willReturn(false); - } + $result = $this->createMock(Result::class); + $result->method('fetchAssociative')->willReturn(false); $driverConnection->expects($this->once())->method('beginTransaction'); $driverConnection @@ -385,19 +376,17 @@ public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql public static function providePlatformSql(): iterable { yield 'MySQL' => [ - new MySQL57Platform(), + new MySQLPlatform(), 'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC LIMIT 1 FOR UPDATE', ]; - if (class_exists(MariaDBPlatform::class)) { - yield 'MariaDB' => [ - new MariaDBPlatform(), - 'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC LIMIT 1 FOR UPDATE', - ]; - } + yield 'MariaDB' => [ + new MariaDBPlatform(), + 'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC LIMIT 1 FOR UPDATE', + ]; yield 'SQL Server' => [ - new SQLServer2012Platform(), + new SQLServerPlatform(), 'SELECT m.* FROM messenger_messages m WITH (UPDLOCK, ROWLOCK) WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY ', ]; @@ -451,13 +440,8 @@ public function testFindAllSqlGenerated(AbstractPlatform $platform, string $expe return new QueryBuilder($driverConnection); }); - if (class_exists(Result::class)) { - $result = $this->createMock(Result::class); - $result->method('fetchAllAssociative')->willReturn([]); - } else { - $result = $this->createMock(ResultStatement::class); - $result->method('fetchAll')->willReturn([]); - } + $result = $this->createMock(Result::class); + $result->method('fetchAllAssociative')->willReturn([]); $driverConnection ->expects($this->once()) @@ -473,19 +457,17 @@ public function testFindAllSqlGenerated(AbstractPlatform $platform, string $expe public function provideFindAllSqlGeneratedByPlatform(): iterable { yield 'MySQL' => [ - new MySQL57Platform(), + new MySQLPlatform(), 'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) LIMIT 50', ]; - if (class_exists(MariaDBPlatform::class)) { - yield 'MariaDB' => [ - new MariaDBPlatform(), - 'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) LIMIT 50', - ]; - } + yield 'MariaDB' => [ + new MariaDBPlatform(), + 'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) LIMIT 50', + ]; yield 'SQL Server' => [ - new SQLServer2012Platform(), + new SQLServerPlatform(), 'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY', ]; diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineIntegrationTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineIntegrationTest.php index 847036f20c799..bb93e98fde7da 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineIntegrationTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineIntegrationTest.php @@ -14,7 +14,6 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Result; -use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; use Doctrine\DBAL\Tools\DsnParser; use Doctrine\ORM\ORMSetup; @@ -27,19 +26,15 @@ */ class DoctrineIntegrationTest extends TestCase { - /** @var \Doctrine\DBAL\Connection */ - private $driverConnection; - /** @var Connection */ - private $connection; + private \Doctrine\DBAL\Connection $driverConnection; + private Connection $connection; protected function setUp(): void { $dsn = getenv('MESSENGER_DOCTRINE_DSN') ?: 'pdo-sqlite://:memory:'; - $params = class_exists(DsnParser::class) ? (new DsnParser())->parse($dsn) : ['url' => $dsn]; + $params = (new DsnParser())->parse($dsn); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } + $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); $this->driverConnection = DriverManager::getConnection($params, $config); $this->connection = new Connection([], $this->driverConnection); @@ -181,7 +176,7 @@ public function testItRetrieveTheMessageThatIsOlderThanRedeliverTimeout() public function testTheTransportIsSetupOnGet() { - $this->assertFalse($this->createSchemaManager()->tablesExist(['messenger_messages'])); + $this->assertFalse($this->driverConnection->createSchemaManager()->tablesExist(['messenger_messages'])); $this->assertNull($this->connection->get()); $this->connection->send('the body', ['my' => 'header']); @@ -193,11 +188,4 @@ private function formatDateTime(\DateTimeImmutable $dateTime) { return $dateTime->format($this->driverConnection->getDatabasePlatform()->getDateTimeFormatString()); } - - private function createSchemaManager(): AbstractSchemaManager - { - return method_exists($this->driverConnection, 'createSchemaManager') - ? $this->driverConnection->createSchemaManager() - : $this->driverConnection->getSchemaManager(); - } } diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrinePostgreSqlIntegrationTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrinePostgreSqlIntegrationTest.php index 2a0df10975239..018320102affe 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrinePostgreSqlIntegrationTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrinePostgreSqlIntegrationTest.php @@ -14,7 +14,6 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; -use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; use Doctrine\DBAL\Tools\DsnParser; use Doctrine\ORM\ORMSetup; @@ -41,7 +40,7 @@ protected function setUp(): void } $url = "pdo-pgsql://postgres:password@$host"; - $params = class_exists(DsnParser::class) ? (new DsnParser())->parse($url) : ['url' => $url]; + $params = (new DsnParser())->parse($url); $config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration(); if (class_exists(DefaultSchemaManagerFactory::class)) { $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); @@ -54,7 +53,7 @@ protected function setUp(): void protected function tearDown(): void { - $this->createSchemaManager()->dropTable('queue_table'); + $this->driverConnection->createSchemaManager()->dropTable('queue_table'); $this->driverConnection->close(); } @@ -68,11 +67,4 @@ public function testPostgreSqlConnectionSendAndGet() $this->assertNull($this->connection->get()); } - - private function createSchemaManager(): AbstractSchemaManager - { - return method_exists($this->driverConnection, 'createSchemaManager') - ? $this->driverConnection->createSchemaManager() - : $this->driverConnection->getSchemaManager(); - } } diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineReceiverTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineReceiverTest.php index 43a0772371a97..3ec11c6c99d8c 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineReceiverTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineReceiverTest.php @@ -12,9 +12,7 @@ namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport; use Doctrine\DBAL\Driver\PDO\Exception; -use Doctrine\DBAL\Driver\PDOException; use Doctrine\DBAL\Exception\DeadlockException; -use Doctrine\DBAL\Version; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage; use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection; @@ -77,15 +75,8 @@ public function testOccursRetryableExceptionFromConnection() { $serializer = $this->createSerializer(); $connection = $this->createMock(Connection::class); - $driverException = class_exists(Exception::class) ? Exception::new(new \PDOException('Deadlock', 40001)) : new PDOException(new \PDOException('Deadlock', 40001)); - if (!class_exists(Version::class)) { - // This is doctrine/dbal 3.x - $deadlockException = new DeadlockException($driverException, null); - } else { - $deadlockException = new DeadlockException('Deadlock', $driverException); - } + $connection->method('get')->willThrowException(new DeadlockException(Exception::new(new \PDOException('Deadlock', 40001)), null)); - $connection->method('get')->willThrowException($deadlockException); $receiver = new DoctrineReceiver($connection, $serializer); $this->assertSame([], $receiver->get()); $this->assertSame([], $receiver->get()); diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php index 6ef1734e6745b..f12f84ea2a658 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php @@ -13,8 +13,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; -use Doctrine\DBAL\Schema\AbstractSchemaManager; -use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\Persistence\ConnectionRegistry; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection; @@ -24,9 +22,6 @@ use Symfony\Component\Messenger\Exception\TransportException; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; -// Doctrine DBAL 2 compatibility -class_exists(\Doctrine\DBAL\Platforms\PostgreSqlPlatform::class); - class DoctrineTransportFactoryTest extends TestCase { public function testSupports() @@ -42,11 +37,7 @@ public function testSupports() public function testCreateTransport() { $driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class); - $schemaManager = $this->createMock(AbstractSchemaManager::class); - $schemaConfig = $this->createMock(SchemaConfig::class); $platform = $this->createMock(AbstractPlatform::class); - $schemaManager->method('createSchemaConfig')->willReturn($schemaConfig); - $driverConnection->method('getSchemaManager')->willReturn($schemaManager); $driverConnection->method('getDatabasePlatform')->willReturn($platform); $registry = $this->createMock(ConnectionRegistry::class); @@ -66,11 +57,7 @@ public function testCreateTransport() public function testCreateTransportNotifyWithPostgreSQLPlatform() { $driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class); - $schemaManager = $this->createMock(AbstractSchemaManager::class); - $schemaConfig = $this->createMock(SchemaConfig::class); $platform = $this->createMock(PostgreSQLPlatform::class); - $schemaManager->method('createSchemaConfig')->willReturn($schemaConfig); - $driverConnection->method('getSchemaManager')->willReturn($schemaManager); $driverConnection->method('getDatabasePlatform')->willReturn($platform); $driverConnection->method('executeStatement')->willReturn(1); $registry = $this->createMock(ConnectionRegistry::class); diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/PostgreSqlConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/PostgreSqlConnectionTest.php index 74357dc461e2a..5063a6fa6c6f5 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/PostgreSqlConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/PostgreSqlConnectionTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport; use Doctrine\DBAL\Cache\ArrayResult; -use Doctrine\DBAL\Cache\ArrayStatement; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Result; @@ -80,29 +79,16 @@ public function countNotifyCalls() } }; - // dbal 2.x - if (interface_exists(Result::class)) { - $driverConnection - ->expects(self::exactly(2)) - ->method('getWrappedConnection') - ->willReturn($wrappedConnection); - - $driverConnection - ->expects(self::any()) - ->method('executeQuery') - ->willReturn(new ArrayStatement([])); - } else { - // dbal 3.x - $driverConnection - ->expects(self::exactly(2)) - ->method('getNativeConnection') - ->willReturn($wrappedConnection); - - $driverConnection - ->expects(self::any()) - ->method('executeQuery') - ->willReturn(new Result(new ArrayResult([]), $driverConnection)); - } + $driverConnection + ->expects(self::exactly(2)) + ->method('getNativeConnection') + ->willReturn($wrappedConnection); + + $driverConnection + ->expects(self::any()) + ->method('executeQuery') + ->willReturn(new Result(new ArrayResult([]), $driverConnection)); + $connection = new PostgreSqlConnection(['table_name' => 'queue_table'], $driverConnection); $connection->get(); // first time we have queueEmptiedAt === null, fallback on the parent implementation diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php index 6643ec67695e6..f10012e25928f 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php @@ -11,22 +11,16 @@ namespace Symfony\Component\Messenger\Bridge\Doctrine\Transport; -use Doctrine\DBAL\Abstraction\Result as AbstractionResult; use Doctrine\DBAL\Connection as DBALConnection; use Doctrine\DBAL\Driver\Exception as DriverException; -use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Exception\TableNotFoundException; use Doctrine\DBAL\LockMode; -use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Result; -use Doctrine\DBAL\Schema\AbstractSchemaManager; -use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; -use Doctrine\DBAL\Schema\SchemaDiff; -use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Types; use Symfony\Component\Messenger\Exception\InvalidArgumentException; @@ -64,14 +58,12 @@ class Connection implements ResetInterface protected $configuration = []; protected $driverConnection; protected $queueEmptiedAt; - private ?SchemaSynchronizer $schemaSynchronizer; private bool $autoSetup; - public function __construct(array $configuration, DBALConnection $driverConnection, SchemaSynchronizer $schemaSynchronizer = null) + public function __construct(array $configuration, DBALConnection $driverConnection) { $this->configuration = array_replace_recursive(static::DEFAULT_OPTIONS, $configuration); $this->driverConnection = $driverConnection; - $this->schemaSynchronizer = $schemaSynchronizer; $this->autoSetup = $this->configuration['auto_setup']; } @@ -157,7 +149,7 @@ public function send(string $body, array $headers, int $delay = 0): string public function get(): ?array { - if ($this->driverConnection->getDatabasePlatform() instanceof MySQLPlatform) { + if ($this->driverConnection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { try { $this->driverConnection->delete($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59']); } catch (DriverException $e) { @@ -198,12 +190,11 @@ public function get(): ?array } // use SELECT ... FOR UPDATE to lock table - $stmt = $this->executeQuery( + $doctrineEnvelope = $this->executeQuery( $sql.' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(), $query->getParameters(), $query->getParameterTypes() - ); - $doctrineEnvelope = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch(); + )->fetchAssociative(); if (false === $doctrineEnvelope) { $this->driverConnection->commit(); @@ -247,7 +238,7 @@ public function get(): ?array public function ack(string $id): bool { try { - if ($this->driverConnection->getDatabasePlatform() instanceof MySQLPlatform) { + if ($this->driverConnection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { return $this->driverConnection->update($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59'], ['id' => $id]) > 0; } @@ -260,7 +251,7 @@ public function ack(string $id): bool public function reject(string $id): bool { try { - if ($this->driverConnection->getDatabasePlatform() instanceof MySQLPlatform) { + if ($this->driverConnection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { return $this->driverConnection->update($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59'], ['id' => $id]) > 0; } @@ -286,9 +277,7 @@ public function getMessageCount(): int ->select('COUNT(m.id) AS message_count') ->setMaxResults(1); - $stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes()); - - return $stmt instanceof Result ? $stmt->fetchOne() : $stmt->fetchColumn(); + return $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes())->fetchOne(); } public function findAll(int $limit = null): array @@ -299,10 +288,10 @@ public function findAll(int $limit = null): array $queryBuilder->setMaxResults($limit); } - $stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes()); - $data = $stmt instanceof Result ? $stmt->fetchAllAssociative() : $stmt->fetchAll(); - - return array_map(fn ($doctrineEnvelope) => $this->decodeEnvelopeHeaders($doctrineEnvelope), $data); + return array_map( + $this->decodeEnvelopeHeaders(...), + $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes())->fetchAllAssociative() + ); } public function find(mixed $id): ?array @@ -310,8 +299,7 @@ public function find(mixed $id): ?array $queryBuilder = $this->createQueryBuilder() ->where('m.id = ? and m.queue_name = ?'); - $stmt = $this->executeQuery($queryBuilder->getSQL(), [$id, $this->configuration['queue_name']]); - $data = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch(); + $data = $this->executeQuery($queryBuilder->getSQL(), [$id, $this->configuration['queue_name']])->fetchAssociative(); return false === $data ? null : $this->decodeEnvelopeHeaders($data); } @@ -380,55 +368,45 @@ private function createQueryBuilder(string $alias = 'm'): QueryBuilder )); } - private function executeQuery(string $sql, array $parameters = [], array $types = []): Result|AbstractionResult|ResultStatement + private function executeQuery(string $sql, array $parameters = [], array $types = []): Result { try { - $stmt = $this->driverConnection->executeQuery($sql, $parameters, $types); + return $this->driverConnection->executeQuery($sql, $parameters, $types); } catch (TableNotFoundException $e) { if ($this->driverConnection->isTransactionActive()) { throw $e; } + } - // create table - if ($this->autoSetup) { - $this->setup(); - } - $stmt = $this->driverConnection->executeQuery($sql, $parameters, $types); + // create table + if ($this->autoSetup) { + $this->setup(); } - return $stmt; + return $this->driverConnection->executeQuery($sql, $parameters, $types); } protected function executeStatement(string $sql, array $parameters = [], array $types = []): int|string { try { - if (method_exists($this->driverConnection, 'executeStatement')) { - $stmt = $this->driverConnection->executeStatement($sql, $parameters, $types); - } else { - $stmt = $this->driverConnection->executeUpdate($sql, $parameters, $types); - } + return $this->driverConnection->executeStatement($sql, $parameters, $types); } catch (TableNotFoundException $e) { if ($this->driverConnection->isTransactionActive()) { throw $e; } + } - // create table - if ($this->autoSetup) { - $this->setup(); - } - if (method_exists($this->driverConnection, 'executeStatement')) { - $stmt = $this->driverConnection->executeStatement($sql, $parameters, $types); - } else { - $stmt = $this->driverConnection->executeUpdate($sql, $parameters, $types); - } + // create table + if ($this->autoSetup) { + $this->setup(); } - return $stmt; + return $this->driverConnection->executeStatement($sql, $parameters, $types); } private function getSchema(): Schema { - $schema = new Schema([], [], $this->createSchemaManager()->createSchemaConfig()); + $schema = new Schema([], [], $this->driverConnection->createSchemaManager()->createSchemaConfig()); $this->addTableToSchema($schema); return $schema; @@ -470,45 +448,10 @@ private function decodeEnvelopeHeaders(array $doctrineEnvelope): array private function updateSchema(): void { - if (null !== $this->schemaSynchronizer) { - $this->schemaSynchronizer->updateSchema($this->getSchema(), true); - - return; - } - - $schemaManager = $this->createSchemaManager(); - $comparator = $this->createComparator($schemaManager); - $schemaDiff = $this->compareSchemas($comparator, method_exists($schemaManager, 'introspectSchema') ? $schemaManager->introspectSchema() : $schemaManager->createSchema(), $this->getSchema()); - $platform = $this->driverConnection->getDatabasePlatform(); - $queries = method_exists($platform, 'getAlterSchemaSQL') ? $platform->getAlterSchemaSQL($schemaDiff) : $schemaDiff->toSaveSql($platform); - - foreach ($queries as $sql) { - if (method_exists($this->driverConnection, 'executeStatement')) { - $this->driverConnection->executeStatement($sql); - } else { - $this->driverConnection->exec($sql); - } - } - } - - private function createSchemaManager(): AbstractSchemaManager - { - return method_exists($this->driverConnection, 'createSchemaManager') - ? $this->driverConnection->createSchemaManager() - : $this->driverConnection->getSchemaManager(); - } - - private function createComparator(AbstractSchemaManager $schemaManager): Comparator - { - return method_exists($schemaManager, 'createComparator') - ? $schemaManager->createComparator() - : new Comparator(); - } + $schemaManager = $this->driverConnection->createSchemaManager(); + $schemaDiff = $schemaManager->createComparator() + ->compareSchemas($schemaManager->introspectSchema(), $this->getSchema()); - private function compareSchemas(Comparator $comparator, Schema $from, Schema $to): SchemaDiff - { - return method_exists($comparator, 'compareSchemas') || method_exists($comparator, 'doCompareSchemas') - ? $comparator->compareSchemas($from, $to) - : $comparator->compare($from, $to); + $schemaManager->alterSchema($schemaDiff); } } diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json b/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json index 195b2f7882089..b1fa103a9bf07 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=8.2", - "doctrine/dbal": "^2.13|^3.0", + "doctrine/dbal": "^3.6", "symfony/messenger": "^6.4|^7.0", "symfony/service-contracts": "^2.5|^3" }, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy