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 aa874ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
13 changes: 5 additions & 8 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,30 +53,26 @@ 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

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup PHP with pecl extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.versions[0] }}
extensions: mongodb, :opcache
- name: Wait for mongo to be ready
uses: docker://toschneck/wait-for-it
with:
args: -q -t 60 mongo:27017
- uses: docker://mongo
if: matrix.versions[4]
with:
args: >
mongo --host mongo:27017 -u ${{ matrix.versions[4] }} -p ${{ matrix.versions[5] }} admin --eval "db = db.getSiblingDB('default'); db.createUser({ user: '${{ matrix.versions[4] }}', pwd: '${{ matrix.versions[5] }}', roles: [ { role: 'readWrite', db: 'default' }], passwordDigestor: 'server' })
mongosh --host mongo:27017 -u ${{ matrix.versions[4] }} -p ${{ matrix.versions[5] }} admin --eval "db = db.getSiblingDB('default'); db.createUser({ user: '${{ matrix.versions[4] }}', pwd: '${{ matrix.versions[5] }}', roles: [ { role: 'readWrite', db: 'default' }], passwordDigestor: 'server' })
- run: composer require --dev --no-update symfony/messenger=^${{ matrix.versions[1] }}
- run: composer remove --dev --no-update kcs/serializer
if: matrix.versions[3]
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 aa874ac

Please sign in to comment.