diff --git a/pkg/dbal/Tests/Functional/DbalConsumerTest.php b/pkg/dbal/Tests/Functional/DbalConsumerTest.php index c95ada687..f5b686cb9 100644 --- a/pkg/dbal/Tests/Functional/DbalConsumerTest.php +++ b/pkg/dbal/Tests/Functional/DbalConsumerTest.php @@ -173,7 +173,7 @@ private function getQuerySize(): int { return (int) $this->context->getDbalConnection() ->executeQuery('SELECT count(*) FROM '.$this->context->getTableName()) - ->fetchColumn(0) + ->fetchOne() ; } } diff --git a/pkg/enqueue-bundle/Consumption/Extension/DoctrinePingConnectionExtension.php b/pkg/enqueue-bundle/Consumption/Extension/DoctrinePingConnectionExtension.php index 77212508f..7cc53688d 100644 --- a/pkg/enqueue-bundle/Consumption/Extension/DoctrinePingConnectionExtension.php +++ b/pkg/enqueue-bundle/Consumption/Extension/DoctrinePingConnectionExtension.php @@ -6,6 +6,8 @@ use Doctrine\Persistence\ManagerRegistry; use Enqueue\Consumption\Context\MessageReceived; use Enqueue\Consumption\MessageReceivedExtensionInterface; +use ErrorException; +use Throwable; class DoctrinePingConnectionExtension implements MessageReceivedExtensionInterface { @@ -27,7 +29,7 @@ public function onMessageReceived(MessageReceived $context): void continue; } - if ($connection->ping()) { + if ($this->ping($connection)) { continue; } @@ -43,4 +45,23 @@ public function onMessageReceived(MessageReceived $context): void ); } } + + private function ping(Connection $connection): bool + { + set_error_handler(static function (int $severity, string $message, string $file, int $line): bool { + throw new ErrorException($message, $severity, $severity, $file, $line); + }); + + try { + $dummySelectSQL = $connection->getDatabasePlatform()->getDummySelectSQL(); + + $connection->executeQuery($dummySelectSQL); + + return true; + } catch (Throwable $exception) { + return false; + } finally { + restore_error_handler(); + } + } } diff --git a/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php b/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php index b740e64c1..341ca5c23 100644 --- a/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php @@ -3,6 +3,7 @@ namespace Enqueue\Bundle\Tests\Unit\Consumption\Extension; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\Persistence\ManagerRegistry; use Enqueue\Bundle\Consumption\Extension\DoctrinePingConnectionExtension; use Enqueue\Consumption\Context\MessageReceived; @@ -29,10 +30,17 @@ public function testShouldNotReconnectIfConnectionIsOK() ->method('isConnected') ->willReturn(true) ; + + $abstractPlatform = $this->createMock(AbstractPlatform::class); + $abstractPlatform->expects($this->once()) + ->method('getDummySelectSQL') + ->willReturn('dummy') + ; + $connection ->expects($this->once()) - ->method('ping') - ->willReturn(true) + ->method('getDatabasePlatform') + ->willReturn($abstractPlatform) ; $connection ->expects($this->never()) @@ -68,10 +76,11 @@ public function testShouldDoesReconnectIfConnectionFailed() ->method('isConnected') ->willReturn(true) ; + $connection ->expects($this->once()) - ->method('ping') - ->willReturn(false) + ->method('getDatabasePlatform') + ->willThrowException(new \Exception()) ; $connection ->expects($this->once()) @@ -118,7 +127,7 @@ public function testShouldSkipIfConnectionWasNotOpened() ; $connection1 ->expects($this->never()) - ->method('ping') + ->method('getDatabasePlatform') ; // 2nd connection was opened in the past @@ -128,10 +137,16 @@ public function testShouldSkipIfConnectionWasNotOpened() ->method('isConnected') ->willReturn(true) ; + $abstractPlatform = $this->createMock(AbstractPlatform::class); + $abstractPlatform->expects($this->once()) + ->method('getDummySelectSQL') + ->willReturn('dummy') + ; + $connection2 ->expects($this->once()) - ->method('ping') - ->willReturn(true) + ->method('getDatabasePlatform') + ->willReturn($abstractPlatform) ; $context = $this->createContext(); diff --git a/pkg/enqueue-bundle/composer.json b/pkg/enqueue-bundle/composer.json index 035dd2b1b..b7be27e25 100644 --- a/pkg/enqueue-bundle/composer.json +++ b/pkg/enqueue-bundle/composer.json @@ -20,6 +20,12 @@ "source": "https://github.com/php-enqueue/enqueue-dev", "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/andrewmy/php-rabbitmq-management-api.git" + } + ], "require-dev": { "phpunit/phpunit": "^9.5", "enqueue/stomp": "0.10.x-dev", diff --git a/pkg/job-queue/Tests/Functional/Entity/Job.php b/pkg/job-queue/Tests/Functional/Entity/Job.php index b6e0308a4..ccbf4fda9 100644 --- a/pkg/job-queue/Tests/Functional/Entity/Job.php +++ b/pkg/job-queue/Tests/Functional/Entity/Job.php @@ -95,7 +95,7 @@ class Job extends BaseJob /** * @var array * - * @ORM\Column(name="data", type="json_array", nullable=true) + * @ORM\Column(name="data", type="json", nullable=true) */ protected $data; diff --git a/pkg/null/.github/workflows/ci.yml b/pkg/null/.github/workflows/ci.yml index fd2ae7f2d..a168dca05 100644 --- a/pkg/null/.github/workflows/ci.yml +++ b/pkg/null/.github/workflows/ci.yml @@ -26,4 +26,4 @@ jobs: with: composer-options: "--prefer-source" - - run: vendor/bin/phpunit --exlude-group=functional + - run: vendor/bin/phpunit --exclude-group=functional