From 74a8d7be1c02a867314f36d3a798e9dd352ecfa6 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 | 5 +++-- tests/Transport/Mongo/IntegrationTest.php | 15 ++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6d7225f..4dfad77 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 @@ -52,11 +53,11 @@ jobs: MONGO_INITDB_ROOT_USERNAME: ${{ matrix.versions[4] }} MONGO_INITDB_ROOT_PASSWORD: ${{ matrix.versions[5] }} options: >- - --health-cmd "mongosh --eval 'db.stats()'" + --health-cmd 'mongosh --eval "db.stats()" -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD"' --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());