From 2ff77fdc2e02ec403f0e4c565502817952afeca1 Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 22 Jun 2026 15:31:59 +0200 Subject: [PATCH] chore: Compatibility with SF 8 and doctrine dbal 4 (#FRAM-228) --- composer.json | 12 ++++++------ src/Connection/Doctrine/DoctrineConnection.php | 2 +- src/Connection/Doctrine/DoctrineQueue.php | 7 +++++-- tests/Console/Command/BindCommandTest.php | 4 +++- tests/Console/Command/ConsumeCommandTest.php | 6 ++++-- tests/Console/Command/InfoCommandTest.php | 6 ++++-- tests/Console/Command/ProduceCommandTest.php | 4 +++- tests/Console/Command/SetupCommandTest.php | 4 +++- 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index db9830f..dd81087 100644 --- a/composer.json +++ b/composer.json @@ -26,12 +26,12 @@ "ext-pcntl": "*", "b2pweb/bdf-dsn": "~1.0", "b2pweb/bdf-instantiator": "~1.0", - "symfony/console": "~5.4|~6.0|~7.0", - "symfony/messenger": "~5.4|~6.0|~7.0" + "symfony/console": "~5.4|~6.0|~7.0|~8.0", + "symfony/messenger": "~5.4|~6.0|~7.0|~8.0" }, "require-dev": { "b2pweb/bdf-serializer": "~1.0", - "doctrine/dbal": "~2.5|~3.0", + "doctrine/dbal": "~2.5|~3.0|~4.0", "ramsey/uuid": "~3.0|~4.0", "enqueue/enqueue": "~0.9", "enqueue/fs": "~0.9", @@ -41,9 +41,9 @@ "php-amqplib/php-amqplib": "~3.0", "phpbench/phpbench": "~0.0|~1.0", "phpunit/phpunit": "~9.6", - "symfony/error-handler": "~5.4|~6.0|~7.0", - "symfony/phpunit-bridge": "~5.4|~6.0|~7.0", - "symfony/var-dumper": "~5.4|~6.0|~7.0", + "symfony/error-handler": "~5.4|~6.0|~7.0|~8.0", + "symfony/phpunit-bridge": "~5.4|~6.0|~7.0|~8.0", + "symfony/var-dumper": "~5.4|~6.0|~7.0|~8.0", "vimeo/psalm": "~5.22 | ~6.0", "predis/predis": "~1.1.0", "friendsofphp/php-cs-fixer": "^3.0" diff --git a/src/Connection/Doctrine/DoctrineConnection.php b/src/Connection/Doctrine/DoctrineConnection.php index cdbb217..b36e3d2 100755 --- a/src/Connection/Doctrine/DoctrineConnection.php +++ b/src/Connection/Doctrine/DoctrineConnection.php @@ -63,7 +63,7 @@ public function connection(): Connection if ($this->connection === null) { try { $this->connection = DriverManager::getConnection($this->config); - $this->connection->connect(); + $this->connection->executeQuery('SELECT 1'); } catch (Exception $e) { throw new ConnectionFailedException($e->getMessage(), $e->getCode(), $e); } diff --git a/src/Connection/Doctrine/DoctrineQueue.php b/src/Connection/Doctrine/DoctrineQueue.php index 07447c0..eecf801 100755 --- a/src/Connection/Doctrine/DoctrineQueue.php +++ b/src/Connection/Doctrine/DoctrineQueue.php @@ -14,9 +14,11 @@ use Bdf\Queue\Message\Message; use Bdf\Queue\Message\QueuedMessage; use DateTime; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\ConnectionLost; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Types\Types; use Ramsey\Uuid\Uuid; @@ -105,11 +107,12 @@ public function pop(string $queue, int $duration = ConnectionDriverInterface::DU public function reserve(int $number, string $queue, int $duration = ConnectionDriverInterface::DURATION): array { $doctrine = $this->connection->connection(); + $forUpdate = $doctrine->getDatabasePlatform() instanceof SqlitePlatform ? '' : 'FOR UPDATE'; // The query builder of Doctrine does not manage the lock for update. $sql = 'SELECT * FROM '.$doctrine->quoteIdentifier($this->connection->table()).' WHERE queue = :queue AND reserved = :reserved AND available_at <= :available_at - ORDER BY available_at, created_at LIMIT '.((int)$number).' '.$doctrine->getDatabasePlatform()->getForUpdateSql(); + ORDER BY available_at, created_at LIMIT '.((int)$number).' '.$forUpdate; $task = function () use ($sql, $queue, $doctrine) { $dbJobs = $doctrine->executeQuery( @@ -142,7 +145,7 @@ public function reserve(int $number, string $queue, int $duration = ConnectionDr ->andWhere('id IN (:ids)') ->setParameter('reserved', true, Types::BOOLEAN) ->setParameter('reserved_at', new DateTime(), Types::DATETIME_MUTABLE) - ->setParameter('ids', $ids, Connection::PARAM_STR_ARRAY); + ->setParameter('ids', $ids, ArrayParameterType::STRING); // Doctrine 3 compatibility if (method_exists($updateQuery, 'executeStatement')) { diff --git a/tests/Console/Command/BindCommandTest.php b/tests/Console/Command/BindCommandTest.php index e55b530..908ba06 100644 --- a/tests/Console/Command/BindCommandTest.php +++ b/tests/Console/Command/BindCommandTest.php @@ -10,6 +10,8 @@ use Symfony\Component\Console\Tester\CommandCompletionTester; use Symfony\Component\Console\Tester\CommandTester; +use function method_exists; + /** * */ @@ -75,7 +77,7 @@ public function test_complete(array $input, array $expectedSuggestions) $command = new BindCommand($factory); $application = new Application(); - $application->add($command); + method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command); $tester = new CommandCompletionTester($application->get('queue:bind')); $suggestions = $tester->complete($input); diff --git a/tests/Console/Command/ConsumeCommandTest.php b/tests/Console/Command/ConsumeCommandTest.php index aa13f2b..477b2a7 100644 --- a/tests/Console/Command/ConsumeCommandTest.php +++ b/tests/Console/Command/ConsumeCommandTest.php @@ -21,6 +21,8 @@ use Symfony\Component\Console\Tester\CommandCompletionTester; use Symfony\Component\Console\Tester\CommandTester; +use function method_exists; + /** * @group Bdf_Queue * @group Bdf_Queue_Console @@ -393,7 +395,7 @@ public function test_complete(array $input, array $expectedSuggestions) $command = new ConsumeCommand($this->manager, $this->container->get(ReceiverLoader::class)); $application = new Application(); - $application->add($command); + method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command); $tester = new CommandCompletionTester($application->get('queue:consume')); $suggestions = $tester->complete($input); @@ -467,4 +469,4 @@ public function wait() { sleep(self::$sleep); } -} \ No newline at end of file +} diff --git a/tests/Console/Command/InfoCommandTest.php b/tests/Console/Command/InfoCommandTest.php index 2f6a552..ccf0f36 100755 --- a/tests/Console/Command/InfoCommandTest.php +++ b/tests/Console/Command/InfoCommandTest.php @@ -14,6 +14,8 @@ use Symfony\Component\Console\Tester\CommandCompletionTester; use Symfony\Component\Console\Tester\CommandTester; +use function method_exists; + /** * @group Bdf_Queue * @group Bdf_Queue_Console @@ -118,7 +120,7 @@ public function test_complete(array $input, array $expectedSuggestions) $command = new InfoCommand($this->container->get(ConnectionDriverFactoryInterface::class)); $application = new Application(); - $application->add($command); + method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command); $tester = new CommandCompletionTester($application->get('queue:info')); $suggestions = $tester->complete($input); @@ -165,4 +167,4 @@ public function test_json_format() $this->assertSame($expected, json_decode($tester->getDisplay(), true)); } -} \ No newline at end of file +} diff --git a/tests/Console/Command/ProduceCommandTest.php b/tests/Console/Command/ProduceCommandTest.php index 0e504b8..6d53581 100644 --- a/tests/Console/Command/ProduceCommandTest.php +++ b/tests/Console/Command/ProduceCommandTest.php @@ -15,6 +15,8 @@ use Symfony\Component\Console\Tester\CommandCompletionTester; use Symfony\Component\Console\Tester\CommandTester; +use function method_exists; + /** * @group Bdf_Queue * @group Bdf_Queue_Console @@ -156,7 +158,7 @@ public function test_complete(array $input, array $expectedSuggestions) $command = new ProduceCommand($this->manager); $application = new Application(); - $application->add($command); + method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command); $tester = new CommandCompletionTester($application->get('queue:produce')); $suggestions = $tester->complete($input); diff --git a/tests/Console/Command/SetupCommandTest.php b/tests/Console/Command/SetupCommandTest.php index 906b6df..03c9a59 100644 --- a/tests/Console/Command/SetupCommandTest.php +++ b/tests/Console/Command/SetupCommandTest.php @@ -14,6 +14,8 @@ use Symfony\Component\Console\Tester\CommandCompletionTester; use Symfony\Component\Console\Tester\CommandTester; +use function method_exists; + /** * */ @@ -162,7 +164,7 @@ public function test_complete(array $input, array $expectedSuggestions) $command = new SetupCommand($this->manager); $application = new Application(); - $application->add($command); + method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command); $tester = new CommandCompletionTester($application->get('queue:setup')); $suggestions = $tester->complete($input);