From 23b706374c56bf0e6accb6594d01713d419e3381 Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Wed, 17 Apr 2024 16:49:13 +0200 Subject: [PATCH] fix(tests): fixed tests for mongo on phpunit 10 --- .github/workflows/tests.yml | 3 ++- tests/Transport/Mongo/IntegrationTest.php | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6d7225f..d22c5d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,6 +8,7 @@ jobs: build: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: versions: # PHP, SF, DB, Ser, MongoDB @@ -56,7 +57,7 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - --health-start-period 30s + --health-start-period 40s ports: - 27017:27017 diff --git a/tests/Transport/Mongo/IntegrationTest.php b/tests/Transport/Mongo/IntegrationTest.php index dae9979..a9d04f8 100644 --- a/tests/Transport/Mongo/IntegrationTest.php +++ b/tests/Transport/Mongo/IntegrationTest.php @@ -12,6 +12,7 @@ use MongoDB\Client; use MongoDB\Driver\Exception\ConnectionTimeoutException; use PHPUnit\Framework\TestCase; +use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Messenger\Envelope; @@ -108,7 +109,7 @@ public function testCorrectlyHandlesRejections(): void $messageBus->dispatch(new DummyMessage('First')); $messageBus->dispatch(new DummyMessage('Second')); - self::assertCount(2, $this->transport->all()); + self::assertCount(2, iterator_to_array($this->transport->all())); self::assertEquals(2, $this->transport->getMessageCount()); $receivedMessages = 0; @@ -116,7 +117,7 @@ public function testCorrectlyHandlesRejections(): void $thirdArgument = $workerClass->getConstructor()->getParameters()[2]; $type = $thirdArgument->getType(); - if ($type instanceof \ReflectionNamedType && EventDispatcherInterface::class === $type->getName()) { + if ($type instanceof \ReflectionNamedType && in_array($type->getName(), [EventDispatcherInterface::class, PsrEventDispatcherInterface::class], true)) { $worker = new Worker(['dummy_transport' => $this->transport], $messageBus, $eventDispatcher = new EventDispatcher()); } else { $worker = new Worker(['dummy_transport' => $this->transport], $messageBus, [], $eventDispatcher = new EventDispatcher()); @@ -158,8 +159,8 @@ static function () use (&$receivedMessages, $worker) { $worker->run(); - self::assertCount(0, $this->transport->all()); - self::assertCount(1, $this->failureTransport->all()); + self::assertCount(0, iterator_to_array($this->transport->all())); + self::assertCount(1, iterator_to_array($this->failureTransport->all())); self::assertEquals(4, $receivedMessages); } @@ -171,14 +172,14 @@ public function testSendsAndReceivesMessages(): void $this->transport->send(new Envelope($first = new DummyMessage('First'))); $this->transport->send(new Envelope($second = new DummyMessage('Second'))); - self::assertCount(2, $this->transport->all()); + self::assertCount(2, iterator_to_array($this->transport->all())); self::assertEquals(2, $this->transport->getMessageCount()); $receivedMessages = 0; $workerClass = new \ReflectionClass(Worker::class); $thirdArgument = $workerClass->getConstructor()->getParameters()[2]; - $argumentType = $thirdArgument->getType(); - if (EventDispatcherInterface::class === ($argumentType ? $argumentType->getName() : null)) { + $type = $thirdArgument->getType(); + if ($type instanceof \ReflectionNamedType && in_array($type->getName(), [EventDispatcherInterface::class, PsrEventDispatcherInterface::class], true)) { $worker = new Worker([$this->transport], new MessageBus(), $eventDispatcher = new EventDispatcher()); } else { $worker = new Worker([$this->transport], new MessageBus(), [], $eventDispatcher = new EventDispatcher());