From e8f2effef5df84aca343bdd6c81a2d38c73b0fe1 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 --- tests/Transport/Mongo/IntegrationTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Transport/Mongo/IntegrationTest.php b/tests/Transport/Mongo/IntegrationTest.php index dae9979..a03bca6 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()); @@ -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());