Skip to content

Commit

Permalink
fix(tests): fixed tests for mongo on phpunit 10
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Apr 17, 2024
1 parent c49c4b7 commit 74a8d7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
versions:
# PHP, SF, DB, Ser, MongoDB
Expand Down Expand Up @@ -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

Expand Down
15 changes: 8 additions & 7 deletions tests/Transport/Mongo/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,15 +109,15 @@ 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;
$workerClass = new \ReflectionClass(Worker::class);
$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());
Expand Down Expand Up @@ -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);
}

Expand All @@ -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());
Expand Down

0 comments on commit 74a8d7b

Please sign in to comment.