diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36c3d5d90..52e438f8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,9 +9,9 @@ jobs: name: Static analysis runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: technote-space/get-diff-action@v4 + - uses: technote-space/get-diff-action@v6 with: PATTERNS: | pkg/**/*.php @@ -25,7 +25,7 @@ jobs: - run: php ./bin/fix-symfony-version.php "5.4.*" - - uses: "ramsey/composer-install@v1" + - uses: "ramsey/composer-install@v3" - run: sed -i 's/525568/16777471/' vendor/kwn/php-rdkafka-stubs/stubs/constants.php @@ -37,9 +37,9 @@ jobs: name: Code style check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: technote-space/get-diff-action@v4 + - uses: technote-space/get-diff-action@v6 with: PATTERNS: | pkg/**/*.php @@ -49,7 +49,7 @@ jobs: run: | echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: composer-cs-check-${{ hashFiles('**/composer.json') }} @@ -87,14 +87,14 @@ jobs: name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Get Composer Cache Directory id: composer-cache run: | echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: composer-${{ matrix.php }}-${{ matrix.symfony_version }}-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }} @@ -131,14 +131,14 @@ jobs: name: PHP ${{ matrix.php }} functional tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Get Composer Cache Directory id: composer-cache run: | echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: composer-${{ matrix.php }}-${{ matrix.symfony_version }}-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }} @@ -162,10 +162,4 @@ jobs: env: PHP_VERSION: ${{ matrix.php }} - # TODO: convert these two steps into one w/o excludes when Gearman extension gets a release for PHP 8.1 - # See https://github.com/php/pecl-networking-gearman/issues/16 - - run: bin/test.sh - if: ${{ matrix.php != '8.1' && matrix.php != '8.2' }} - - - run: bin/test.sh --exclude-group=gearman - if: ${{ matrix.php == '8.1' && matrix.php != '8.2' }} + - run: bin/test.sh --group=functional diff --git a/composer.json b/composer.json index d2258474d..ff2aea7ae 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "google/cloud-pubsub": "^1.4.3", "doctrine/orm": "^2.12", "doctrine/persistence": "^2.0|^3.0", - "mongodb/mongodb": "^1.2", + "mongodb/mongodb": "^1.17", "pda/pheanstalk": "^3.1", "aws/aws-sdk-php": "^3.290", "stomp-php/stomp-php": "^4.5|^5", @@ -50,8 +50,8 @@ }, "require-dev": { "ext-pcntl": "*", - "phpunit/phpunit": "^9.5", - "phpstan/phpstan": "^1.0", + "phpunit/phpunit": "^9.6.22", + "phpstan/phpstan": "^2.1", "queue-interop/queue-spec": "^0.6.2", "symfony/browser-kit": "^6.2|^7.0", "symfony/config": "^6.2|^7.0", @@ -127,7 +127,7 @@ "ext-rdkafka": "4.0", "ext-bcmath": "1", "ext-mbstring": "1", - "ext-mongo": "1.6.14", + "ext-mongodb": "1.17", "ext-sockets": "1" }, "prefer-stable": true, diff --git a/docker-compose.yml b/docker-compose.yml index 8851efc28..b724d7881 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,11 @@ -version: '2' - services: dev: # when image publishing gets sorted: -# image: enqueue/dev:${PHP_VERSION:-7.4} + # image: enqueue/dev:${PHP_VERSION:-8.2} build: context: docker args: - PHP_VERSION: "${PHP_VERSION:-8.1}" + PHP_VERSION: "${PHP_VERSION:-8.2}" depends_on: - rabbitmq - mysql diff --git a/docker/Dockerfile b/docker/Dockerfile index b2f30c62e..c54a29866 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,71 +1,34 @@ ARG PHP_VERSION=8.2 -FROM makasim/nginx-php-fpm:${PHP_VERSION}-all-exts +FROM php:${PHP_VERSION}-alpine ARG PHP_VERSION -## libs -RUN set -x && \ - apt-get update && \ - apt-get install -y --no-install-recommends --no-install-suggests \ - wget \ - curl \ - openssl \ - ca-certificates \ - nano \ - netcat \ - php${PHP_VERSION}-dev \ - php${PHP_VERSION}-redis \ - php${PHP_VERSION}-pgsql \ - git \ - python \ - php${PHP_VERSION}-amqp \ - php${PHP_VERSION}-xml \ - php${PHP_VERSION}-mysql \ - php${PHP_VERSION}-curl \ - php${PHP_VERSION}-mongodb \ - php${PHP_VERSION}-mbstring \ - make \ - g++ \ - unzip \ - && \ - update-alternatives --install /usr/bin/php php /usr/bin/php${PHP_VERSION} 100 - -## gearman -RUN set -x && \ - apt-get install -y --no-install-recommends --no-install-suggests \ - libgearman-dev \ - && \ - mkdir -p $HOME/gearman && \ - cd $HOME/gearman && \ - git clone https://github.com/php/pecl-networking-gearman.git . && \ - git checkout gearman-2.1.0 && \ - phpize && ./configure && make && make install && \ - if [ ! -f /etc/php/${PHP_VERSION}/cli/conf.d/20-gearman.ini ]; then \ - echo "extension=gearman.so" > /etc/php/${PHP_VERSION}/cli/conf.d/20-gearman.ini && \ - echo "extension=gearman.so" > /etc/php/${PHP_VERSION}/fpm/conf.d/20-gearman.ini \ - ; \ - fi; - -## librdkafka -RUN set -x && \ - mkdir -p $HOME/librdkafka && \ - cd $HOME/librdkafka && \ - git clone https://github.com/edenhill/librdkafka.git . && \ - git checkout v1.0.0 && \ - ./configure && make && make install - -## php-rdkafka -RUN set -x && \ - mkdir -p $HOME/php-rdkafka && \ - cd $HOME/php-rdkafka && \ - git clone https://github.com/arnaud-lb/php-rdkafka.git . && \ - git checkout 5.0.1 && \ - phpize && ./configure && make all && make install && \ - echo "extension=rdkafka.so" > /etc/php/${PHP_VERSION}/cli/conf.d/10-rdkafka.ini && \ - echo "extension=rdkafka.so" > /etc/php/${PHP_VERSION}/fpm/conf.d/10-rdkafka.ini - -COPY ./php/cli.ini /etc/php/${PHP_VERSION}/cli/conf.d/1-dev_cli.ini +RUN --mount=type=cache,target=/var/cache/apk apk add --no-cache $PHPIZE_DEPS \ + libpq-dev \ + librdkafka-dev \ + rabbitmq-c-dev \ + linux-headers && \ + apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \ + gearman-dev + +# Install First Party Modules +RUN docker-php-ext-install -j$(nproc) \ + pcntl \ + pdo_mysql \ + pdo_pgsql + +# Install Third Party Modules +RUN --mount=type=cache,target=/tmp/pear pecl install redis \ + mongodb-1.21.0 \ + gearman \ + rdkafka \ + xdebug && \ + pecl install --configureoptions 'with-librabbitmq-dir="autodetect"' amqp +RUN docker-php-ext-enable redis mongodb gearman rdkafka xdebug amqp + +COPY ./php/cli.ini /usr/local/etc/php/conf.d/1-dev_cli COPY ./bin/dev_entrypoiny.sh /usr/local/bin/entrypoint.sh +RUN mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini RUN chmod u+x /usr/local/bin/entrypoint.sh RUN mkdir -p /mqdev @@ -73,4 +36,4 @@ WORKDIR /mqdev COPY --from=composer:2 /usr/bin/composer /usr/bin/composer -CMD /usr/local/bin/entrypoint.sh +CMD ["/usr/local/bin/entrypoint.sh"] diff --git a/docker/bin/dev_entrypoiny.sh b/docker/bin/dev_entrypoiny.sh index a18b06b1e..c56e146fa 100644 --- a/docker/bin/dev_entrypoiny.sh +++ b/docker/bin/dev_entrypoiny.sh @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh while true; do sleep 1; done diff --git a/docker/bin/test.sh b/docker/bin/test.sh index b78e1c1a8..6bd094b75 100755 --- a/docker/bin/test.sh +++ b/docker/bin/test.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # wait for service # $1 host diff --git a/pkg/amqp-lib/Tests/AmqpContextTest.php b/pkg/amqp-lib/Tests/AmqpContextTest.php index 4cfde3c14..c5ac19643 100644 --- a/pkg/amqp-lib/Tests/AmqpContextTest.php +++ b/pkg/amqp-lib/Tests/AmqpContextTest.php @@ -318,19 +318,19 @@ public function testShouldPurgeQueue() $context->purgeQueue($queue); } - public function testShouldSetQos() + public function testShouldSetQos(): void { + $invoked = $this->exactly(2); $channel = $this->createChannelMock(); $channel - ->expects($this->at(0)) + ->expects($invoked) ->method('basic_qos') - ->with($this->identicalTo(0), $this->identicalTo(1), $this->isFalse()) - ; - $channel - ->expects($this->at(1)) - ->method('basic_qos') - ->with($this->identicalTo(123), $this->identicalTo(456), $this->isTrue()) - ; + ->willReturnCallback(function ($prefetch_size, $prefetch_count, $a_global) use ($invoked) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame([0, 1, false], [$prefetch_size, $prefetch_count, $a_global]), + 2 => $this->assertSame([123, 456, true], [$prefetch_size, $prefetch_count, $a_global]), + }; + }); $connection = $this->createConnectionMock(); $connection diff --git a/pkg/enqueue/Client/DriverFactory.php b/pkg/enqueue/Client/DriverFactory.php index 1d383ac86..5c827e7e7 100644 --- a/pkg/enqueue/Client/DriverFactory.php +++ b/pkg/enqueue/Client/DriverFactory.php @@ -76,7 +76,7 @@ private function findDriverInfo(Dsn $dsn, array $factories): ?array private function createRabbitMqStompDriver(ConnectionFactory $factory, Dsn $dsn, Config $config, RouteCollection $collection): RabbitMqStompDriver { $defaultManagementHost = $dsn->getHost() ?: $config->getTransportOption('host', 'localhost'); - $managementVast = ltrim($dsn->getPath(), '/') ?: $config->getTransportOption('vhost', '/'); + $managementVast = ltrim($dsn->getPath() ?? '', '/') ?: $config->getTransportOption('vhost', '/'); $managementClient = StompManagementClient::create( urldecode($managementVast), diff --git a/pkg/enqueue/Symfony/Client/ConsumeCommand.php b/pkg/enqueue/Symfony/Client/ConsumeCommand.php index 5a0676705..7e459a426 100644 --- a/pkg/enqueue/Symfony/Client/ConsumeCommand.php +++ b/pkg/enqueue/Symfony/Client/ConsumeCommand.php @@ -94,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $consumer = $this->getQueueConsumer($client); } catch (NotFoundExceptionInterface $e) { - throw new \LogicException(sprintf('Client "%s" is not supported.', $client), null, $e); + throw new \LogicException(sprintf('Client "%s" is not supported.', $client), 0, $e); } $driver = $this->getDriver($client); diff --git a/pkg/enqueue/Symfony/Client/ProduceCommand.php b/pkg/enqueue/Symfony/Client/ProduceCommand.php index bd23c16c3..80b7ebd3e 100644 --- a/pkg/enqueue/Symfony/Client/ProduceCommand.php +++ b/pkg/enqueue/Symfony/Client/ProduceCommand.php @@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $producer = $this->getProducer($client); } catch (NotFoundExceptionInterface $e) { - throw new \LogicException(sprintf('Client "%s" is not supported.', $client), null, $e); + throw new \LogicException(sprintf('Client "%s" is not supported.', $client), 0, $e); } if ($topic) { diff --git a/pkg/enqueue/Symfony/Client/RoutesCommand.php b/pkg/enqueue/Symfony/Client/RoutesCommand.php index 0646e37bb..b28f2388a 100644 --- a/pkg/enqueue/Symfony/Client/RoutesCommand.php +++ b/pkg/enqueue/Symfony/Client/RoutesCommand.php @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $this->driver = $this->getDriver($input->getOption('client')); } catch (NotFoundExceptionInterface $e) { - throw new \LogicException(sprintf('Client "%s" is not supported.', $input->getOption('client')), null, $e); + throw new \LogicException(sprintf('Client "%s" is not supported.', $input->getOption('client')), 0, $e); } $routes = $this->driver->getRouteCollection()->all(); diff --git a/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php b/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php index b74902aa6..d3d9ccb88 100644 --- a/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php +++ b/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $this->getDriver($client)->setupBroker(new ConsoleLogger($output)); } catch (NotFoundExceptionInterface $e) { - throw new \LogicException(sprintf('Client "%s" is not supported.', $client), null, $e); + throw new \LogicException(sprintf('Client "%s" is not supported.', $client), 0, $e); } $output->writeln('Broker set up'); diff --git a/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php b/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php index 230a0dc69..b55299fed 100644 --- a/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $consumer = $this->getQueueConsumer($transport); } catch (NotFoundExceptionInterface $e) { - throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), null, $e); + throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), 0, $e); } $this->setQueueConsumerOptions($consumer, $input); diff --git a/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php b/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php index 1c82f3cfb..56cf3ca15 100644 --- a/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int // QueueConsumer must be pre configured outside of the command! $consumer = $this->getQueueConsumer($transport); } catch (NotFoundExceptionInterface $e) { - throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), null, $e); + throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), 0, $e); } $this->setQueueConsumerOptions($consumer, $input); diff --git a/pkg/enqueue/Tests/Client/Driver/AmqpDriverTest.php b/pkg/enqueue/Tests/Client/Driver/AmqpDriverTest.php index 2cfb170b9..88cc95cce 100644 --- a/pkg/enqueue/Tests/Client/Driver/AmqpDriverTest.php +++ b/pkg/enqueue/Tests/Client/Driver/AmqpDriverTest.php @@ -22,6 +22,7 @@ use Interop\Queue\Message as InteropMessage; use Interop\Queue\Producer as InteropProducer; use Interop\Queue\Queue as InteropQueue; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class AmqpDriverTest extends TestCase @@ -190,56 +191,43 @@ public function testShouldSetupBroker() $context = $this->createContextMock(); // setup router $context - ->expects($this->at(0)) + ->expects($this->once()) ->method('createTopic') + ->with($this->identicalTo($this->getRouterTransportName())) ->willReturn($routerTopic) ; $context - ->expects($this->at(1)) + ->expects($this->once()) ->method('declareTopic') ->with($this->identicalTo($routerTopic)) ; - - $context - ->expects($this->at(2)) - ->method('createQueue') - ->willReturn($routerQueue) - ; - $context - ->expects($this->at(3)) - ->method('declareQueue') - ->with($this->identicalTo($routerQueue)) - ; - $context - ->expects($this->at(4)) + ->expects($this->once()) ->method('bind') ->with($this->isInstanceOf(AmqpBind::class)) ; - // setup processor with default queue - $context - ->expects($this->at(5)) - ->method('createQueue') - ->with($this->getDefaultQueueTransportName()) - ->willReturn($processorWithDefaultQueue) - ; - $context - ->expects($this->at(6)) - ->method('declareQueue') - ->with($this->identicalTo($processorWithDefaultQueue)) - ; - $context - ->expects($this->at(7)) + ->expects($this->exactly(3)) ->method('createQueue') - ->with($this->getCustomQueueTransportName()) - ->willReturn($processorWithCustomQueue) + ->with($this->logicalOr( + $this->getDefaultQueueTransportName(), + $this->getCustomQueueTransportName(), + )) + ->willReturnOnConsecutiveCalls( + $routerQueue, + $processorWithDefaultQueue, + $processorWithCustomQueue + ) ; $context - ->expects($this->at(8)) + ->expects($this->exactly(3)) ->method('declareQueue') - ->with($this->identicalTo($processorWithCustomQueue)) + ->with($this->logicalOr( + $this->identicalTo($routerQueue), + $this->identicalTo($processorWithDefaultQueue), + $this->identicalTo($processorWithCustomQueue) + )) ; $driver = new AmqpDriver( @@ -290,7 +278,7 @@ protected function createDriver(...$args): DriverInterface } /** - * @return AmqpContext + * @return AmqpContext&MockObject */ protected function createContextMock(): Context { diff --git a/pkg/enqueue/Tests/Client/Driver/FsDriverTest.php b/pkg/enqueue/Tests/Client/Driver/FsDriverTest.php index f1cd02f9b..8a4d4b0f9 100644 --- a/pkg/enqueue/Tests/Client/Driver/FsDriverTest.php +++ b/pkg/enqueue/Tests/Client/Driver/FsDriverTest.php @@ -18,6 +18,7 @@ use Interop\Queue\Queue as InteropQueue; use Interop\Queue\Topic as InteropTopic; use Makasim\File\TempFile; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class FsDriverTest extends TestCase @@ -44,25 +45,18 @@ public function testShouldSetupBroker() $context = $this->createContextMock(); // setup router $context - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('createQueue') - ->willReturn($routerQueue) + ->with($this->getDefaultQueueTransportName()) + ->willReturnOnConsecutiveCalls($routerQueue, $processorQueue) ; $context - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('declareDestination') - ->with($this->identicalTo($routerQueue)) - ; - // setup processor queue - $context - ->expects($this->at(2)) - ->method('createQueue') - ->willReturn($processorQueue) - ; - $context - ->expects($this->at(3)) - ->method('declareDestination') - ->with($this->identicalTo($processorQueue)) + ->with($this->logicalOr( + $this->identicalTo($routerQueue), + $this->identicalTo($processorQueue) + )) ; $routeCollection = new RouteCollection([ @@ -84,7 +78,7 @@ protected function createDriver(...$args): DriverInterface } /** - * @return FsContext + * @return FsContext&MockObject */ protected function createContextMock(): Context { diff --git a/pkg/enqueue/Tests/Client/Driver/GpsDriverTest.php b/pkg/enqueue/Tests/Client/Driver/GpsDriverTest.php index c0cac0458..2b95d52f2 100644 --- a/pkg/enqueue/Tests/Client/Driver/GpsDriverTest.php +++ b/pkg/enqueue/Tests/Client/Driver/GpsDriverTest.php @@ -18,6 +18,7 @@ use Interop\Queue\Producer as InteropProducer; use Interop\Queue\Queue as InteropQueue; use Interop\Queue\Topic as InteropTopic; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class GpsDriverTest extends TestCase @@ -46,38 +47,31 @@ public function testShouldSetupBroker() $context = $this->createContextMock(); // setup router $context - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('createTopic') - ->willReturn($routerTopic) + ->with($this->logicalOr( + 'aprefix.router', + $this->getDefaultQueueTransportName(), + )) + ->willReturnOnConsecutiveCalls($routerTopic, $processorTopic) ; $context - ->expects($this->at(1)) - ->method('createQueue') - ->willReturn($routerQueue) - ; - $context - ->expects($this->at(2)) - ->method('subscribe') - ->with($this->identicalTo($routerTopic), $this->identicalTo($routerQueue)) - ; - $context - ->expects($this->at(3)) + ->expects($this->exactly(2)) ->method('createQueue') ->with($this->getDefaultQueueTransportName()) - ->willReturn($processorQueue) - ; - // setup processor queue - $context - ->expects($this->at(4)) - ->method('createTopic') - ->with($this->getDefaultQueueTransportName()) - ->willReturn($processorTopic) + ->willReturnOnConsecutiveCalls($routerQueue, $processorQueue) ; + + $invoked = $this->exactly(2); $context - ->expects($this->at(5)) + ->expects($invoked) ->method('subscribe') - ->with($this->identicalTo($processorTopic), $this->identicalTo($processorQueue)) - ; + ->willReturnCallback(function ($topic, $queue) use ($invoked, $routerTopic, $processorTopic, $routerQueue, $processorQueue) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame([$routerTopic, $routerQueue], [$topic, $queue]), + 2 => $this->assertSame([$processorTopic, $processorQueue], [$topic, $queue]), + }; + }); $driver = new GpsDriver( $context, @@ -96,7 +90,7 @@ protected function createDriver(...$args): DriverInterface } /** - * @return GpsContext + * @return GpsContext&MockObject */ protected function createContextMock(): Context { diff --git a/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php b/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php index 9fc72be1e..bed1582d4 100644 --- a/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php +++ b/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php @@ -196,14 +196,9 @@ public function shouldSendMessageToDelayExchangeIfDelaySet() $producer = $this->createProducerMock(); $producer - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('setDeliveryDelay') - ->with(10000) - ; - $producer - ->expects($this->at(1)) - ->method('setDeliveryDelay') - ->with(null) + ->with($this->logicalOr(10000, null)) ; $producer ->expects($this->once()) @@ -300,7 +295,7 @@ public function testShouldSetupBroker() $managementClient = $this->createManagementClientMock(); $managementClient - ->expects($this->at(0)) + ->expects($this->once()) ->method('declareExchange') ->with('aprefix.router', [ 'type' => 'fanout', @@ -309,7 +304,7 @@ public function testShouldSetupBroker() ]) ; $managementClient - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('declareQueue') ->with('aprefix.default', [ 'durable' => true, @@ -320,21 +315,10 @@ public function testShouldSetupBroker() ]) ; $managementClient - ->expects($this->at(2)) + ->expects($this->once()) ->method('bind') ->with('aprefix.router', 'aprefix.default', 'aprefix.default') ; - $managementClient - ->expects($this->at(3)) - ->method('declareQueue') - ->with('aprefix.default', [ - 'durable' => true, - 'auto_delete' => false, - 'arguments' => [ - 'x-max-priority' => 4, - ], - ]) - ; $contextMock = $this->createContextMock(); $contextMock @@ -400,22 +384,39 @@ public function testSetupBrokerShouldCreateDelayExchangeIfEnabled() ]); $managementClient = $this->createManagementClientMock(); + $invoked = $this->exactly(2); $managementClient - ->expects($this->at(4)) + ->expects($invoked) ->method('declareExchange') - ->with('aprefix.default.delayed', [ - 'type' => 'x-delayed-message', - 'durable' => true, - 'auto_delete' => false, - 'arguments' => [ - 'x-delayed-type' => 'direct', - ], - ]) - ; + ->willReturnCallback(function (string $name, array $options) use ($invoked) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame([ + 'aprefix.router', + ['type' => 'fanout', 'durable' => true, 'auto_delete' => false], + ], [$name, $options]), + 2 => $this->assertSame([ + 'aprefix.default.delayed', + ['type' => 'x-delayed-message', 'durable' => true, 'auto_delete' => false, 'arguments' => ['x-delayed-type' => 'direct']], + ], [$name, $options]), + }; + }); + + $bindInvoked = $this->exactly(2); $managementClient - ->expects($this->at(5)) + ->expects($bindInvoked) ->method('bind') - ->with('aprefix.default.delayed', 'aprefix.default', 'aprefix.default') + ->willReturnCallback(function (string $exchange, string $queue, ?string $routingKey = null, $arguments = null) use ($bindInvoked) { + match ($bindInvoked->getInvocationCount()) { + 1 => $this->assertSame( + ['aprefix.router', 'aprefix.default', 'aprefix.default', null], + [$exchange, $queue, $routingKey, $arguments], + ), + 2 => $this->assertSame( + ['aprefix.default.delayed', 'aprefix.default', 'aprefix.default', null], + [$exchange, $queue, $routingKey, $arguments], + ), + }; + }) ; $config = Config::create( diff --git a/pkg/enqueue/Tests/Client/Driver/RdKafkaDriverTest.php b/pkg/enqueue/Tests/Client/Driver/RdKafkaDriverTest.php index c5e40e71d..40cb177d9 100644 --- a/pkg/enqueue/Tests/Client/Driver/RdKafkaDriverTest.php +++ b/pkg/enqueue/Tests/Client/Driver/RdKafkaDriverTest.php @@ -17,6 +17,7 @@ use Interop\Queue\Message as InteropMessage; use Interop\Queue\Producer as InteropProducer; use Interop\Queue\Queue as InteropQueue; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class RdKafkaDriverTest extends TestCase @@ -39,26 +40,14 @@ public function testShouldSetupBroker() $routerTopic = new RdKafkaTopic(''); $routerQueue = new RdKafkaTopic(''); - $processorTopic = new RdKafkaTopic(''); - $context = $this->createContextMock(); $context - ->expects($this->at(0)) - ->method('createQueue') - ->willReturn($routerTopic) - ; - $context - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('createQueue') - ->willReturn($routerQueue) + ->with($this->getDefaultQueueTransportName()) + ->willReturnOnConsecutiveCalls($routerTopic, $routerQueue) ; - $context - ->expects($this->at(2)) - ->method('createQueue') - ->willReturn($processorTopic) - ; - $driver = new RdKafkaDriver( $context, $this->createDummyConfig(), @@ -76,7 +65,7 @@ protected function createDriver(...$args): DriverInterface } /** - * @return RdKafkaContext + * @return RdKafkaContext&MockObject */ protected function createContextMock(): Context { diff --git a/pkg/enqueue/Tests/Client/Driver/SqsDriverTest.php b/pkg/enqueue/Tests/Client/Driver/SqsDriverTest.php index 2e3005e6a..bd4815efa 100644 --- a/pkg/enqueue/Tests/Client/Driver/SqsDriverTest.php +++ b/pkg/enqueue/Tests/Client/Driver/SqsDriverTest.php @@ -17,6 +17,7 @@ use Interop\Queue\Producer as InteropProducer; use Interop\Queue\Queue as InteropQueue; use Interop\Queue\Topic as InteropTopic; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class SqsDriverTest extends TestCase @@ -42,28 +43,18 @@ public function testShouldSetupBroker() $context = $this->createContextMock(); // setup router $context - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('createQueue') ->with('aprefix_dot_default') - ->willReturn($routerQueue) + ->willReturnOnConsecutiveCalls($routerQueue, $processorQueue) ; $context - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('declareQueue') - ->with($this->identicalTo($routerQueue)) - ; - // setup processor queue - $context - ->expects($this->at(2)) - ->method('createQueue') - ->with('aprefix_dot_default') - ->willReturn($processorQueue) - ; - $context - ->expects($this->at(3)) - ->method('declareQueue') - ->with($this->identicalTo($processorQueue)) - ; + ->with($this->logicalOr( + $this->identicalTo($routerQueue), + $this->identicalTo($processorQueue) + )); $driver = new SqsDriver( $context, @@ -82,7 +73,7 @@ protected function createDriver(...$args): DriverInterface } /** - * @return SqsContext + * @return SqsContext&MockObject */ protected function createContextMock(): Context { diff --git a/pkg/enqueue/Tests/Client/ProducerSendCommandTest.php b/pkg/enqueue/Tests/Client/ProducerSendCommandTest.php index 9500e9d62..25fe48ea9 100644 --- a/pkg/enqueue/Tests/Client/ProducerSendCommandTest.php +++ b/pkg/enqueue/Tests/Client/ProducerSendCommandTest.php @@ -370,7 +370,7 @@ public function testShouldCallPreSendCommandExtensionMethodWhenSendToBus() $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onPreSendCommand') ->willReturnCallback(function (PreSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -408,7 +408,7 @@ public function testShouldCallPreSendCommandExtensionMethodWhenSendToApplication $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onPreSendCommand') ->willReturnCallback(function (PreSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -446,7 +446,7 @@ public function testShouldCallPreDriverSendExtensionMethod() $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onDriverPreSend') ->willReturnCallback(function (DriverPreSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -454,7 +454,7 @@ public function testShouldCallPreDriverSendExtensionMethod() $this->assertSame($driver, $context->getDriver()); $this->assertSame('command', $context->getCommand()); - $this->assertTrue($context->isEvent()); + $this->assertFalse($context->isEvent()); }); $producer->sendCommand('command', $message); @@ -478,7 +478,7 @@ public function testShouldCallPostSendExtensionMethod() $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onPostSend') ->willReturnCallback(function (PostSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); diff --git a/pkg/enqueue/Tests/Client/ProducerSendEventTest.php b/pkg/enqueue/Tests/Client/ProducerSendEventTest.php index c92b49560..af6c8c532 100644 --- a/pkg/enqueue/Tests/Client/ProducerSendEventTest.php +++ b/pkg/enqueue/Tests/Client/ProducerSendEventTest.php @@ -326,7 +326,7 @@ public function testShouldCallPreSendEventExtensionMethodWhenSendToBus() $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onPreSendEvent') ->willReturnCallback(function (PreSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -364,7 +364,7 @@ public function testShouldCallPreSendEventExtensionMethodWhenSendToApplicationRo $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onPreSendEvent') ->willReturnCallback(function (PreSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -402,7 +402,7 @@ public function testShouldCallPreDriverSendExtensionMethodWhenSendToMessageBus() $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onDriverPreSend') ->willReturnCallback(function (DriverPreSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -434,7 +434,7 @@ public function testShouldCallPreDriverSendExtensionMethodWhenSendToApplicationR $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onDriverPreSend') ->willReturnCallback(function (DriverPreSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -466,7 +466,7 @@ public function testShouldCallPostSendExtensionMethodWhenSendToMessageBus() $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onPostSend') ->willReturnCallback(function (PostSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); @@ -498,7 +498,7 @@ public function testShouldCallPostSendExtensionMethodWhenSendToApplicationRouter $producer = new Producer($driver, $this->createRpcFactoryMock(), $extension); $extension - ->expects($this->at(0)) + ->expects($this->once()) ->method('onPostSend') ->willReturnCallback(function (PostSend $context) use ($message, $producer, $driver) { $this->assertSame($message, $context->getMessage()); diff --git a/pkg/enqueue/Tests/Client/ResourcesTest.php b/pkg/enqueue/Tests/Client/ResourcesTest.php index e79fb9dda..5db642b00 100644 --- a/pkg/enqueue/Tests/Client/ResourcesTest.php +++ b/pkg/enqueue/Tests/Client/ResourcesTest.php @@ -2,11 +2,20 @@ namespace Enqueue\Tests\Client; +use Enqueue\Client\Config; use Enqueue\Client\Driver\AmqpDriver; use Enqueue\Client\Driver\RabbitMqDriver; use Enqueue\Client\DriverInterface; +use Enqueue\Client\DriverSendResult; +use Enqueue\Client\Message; use Enqueue\Client\Resources; +use Enqueue\Client\Route; +use Enqueue\Client\RouteCollection; +use Interop\Queue\Context; +use Interop\Queue\Message as InteropMessage; +use Interop\Queue\Queue as InteropQueue; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; class ResourcesTest extends TestCase { @@ -100,22 +109,18 @@ public function testThrowsIfDriverClassNotImplementDriverFactoryInterfaceOnAddDr public function testThrowsIfNoSchemesProvidedOnAddDriver() { - $driverClass = $this->getMockClass(DriverInterface::class); - $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Schemes could not be empty.'); - Resources::addDriver($driverClass, [], [], ['foo']); + Resources::addDriver(DriverInterface::class, [], [], ['foo']); } public function testThrowsIfNoPackageProvidedOnAddDriver() { - $driverClass = $this->getMockClass(DriverInterface::class); - $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Packages could not be empty.'); - Resources::addDriver($driverClass, ['foo'], [], []); + Resources::addDriver(DriverInterface::class, ['foo'], [], []); } public function testShouldAllowRegisterDriverThatIsNotInstalled() @@ -131,10 +136,60 @@ public function testShouldAllowRegisterDriverThatIsNotInstalled() public function testShouldAllowGetPreviouslyRegisteredDriver() { - $driverClass = $this->getMockClass(DriverInterface::class); + $driverClass = new class implements DriverInterface { + public function createTransportMessage(Message $message): InteropMessage + { + throw new \LogicException('not implemented'); + } + + public function createClientMessage(InteropMessage $message): Message + { + throw new \LogicException('not implemented'); + } + + public function sendToRouter(Message $message): DriverSendResult + { + throw new \LogicException('not implemented'); + } + + public function sendToProcessor(Message $message): DriverSendResult + { + throw new \LogicException('not implemented'); + } + + public function createQueue(string $queueName, bool $prefix = true): InteropQueue + { + throw new \LogicException('not implemented'); + } + + public function createRouteQueue(Route $route): InteropQueue + { + throw new \LogicException('not implemented'); + } + + public function setupBroker(?LoggerInterface $logger = null): void + { + throw new \LogicException('not implemented'); + } + + public function getConfig(): Config + { + throw new \LogicException('not implemented'); + } + + public function getContext(): Context + { + throw new \LogicException('not implemented'); + } + + public function getRouteCollection(): RouteCollection + { + throw new \LogicException('not implemented'); + } + }; Resources::addDriver( - $driverClass, + $driverClass::class, ['fooscheme', 'barscheme'], ['fooextension', 'barextension'], ['foo/bar'] @@ -145,7 +200,7 @@ public function testShouldAllowGetPreviouslyRegisteredDriver() $driverInfo = end($availableDrivers); $this->assertArrayHasKey('driverClass', $driverInfo); - $this->assertSame($driverClass, $driverInfo['driverClass']); + $this->assertSame($driverClass::class, $driverInfo['driverClass']); $this->assertArrayHasKey('schemes', $driverInfo); $this->assertSame(['fooscheme', 'barscheme'], $driverInfo['schemes']); diff --git a/pkg/enqueue/Tests/Client/SpoolProducerTest.php b/pkg/enqueue/Tests/Client/SpoolProducerTest.php index 014fe4962..005f4b633 100644 --- a/pkg/enqueue/Tests/Client/SpoolProducerTest.php +++ b/pkg/enqueue/Tests/Client/SpoolProducerTest.php @@ -61,21 +61,18 @@ public function testShouldSendQueuedEventMessagesOnFlush() $message = new Message(); $message->setScope('third'); + $invoked = $this->exactly(3); $realProducer = $this->createProducerMock(); $realProducer - ->expects($this->at(0)) + ->expects($invoked) ->method('sendEvent') - ->with('foo_topic', 'first') - ; - $realProducer - ->expects($this->at(1)) - ->method('sendEvent') - ->with('bar_topic', ['second']) - ; - $realProducer - ->expects($this->at(2)) - ->method('sendEvent') - ->with('baz_topic', $this->identicalTo($message)) + ->willReturnCallback(function (string $topic, $argMessage) use ($invoked, $message) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame(['foo_topic', 'first'], [$topic, $argMessage]), + 2 => $this->assertSame(['bar_topic', ['second']], [$topic, $argMessage]), + 3 => $this->assertSame(['baz_topic', $message], [$topic, $argMessage]), + }; + }) ; $realProducer ->expects($this->never()) @@ -96,21 +93,18 @@ public function testShouldSendQueuedCommandMessagesOnFlush() $message = new Message(); $message->setScope('third'); + $invoked = $this->exactly(3); $realProducer = $this->createProducerMock(); $realProducer - ->expects($this->at(0)) - ->method('sendCommand') - ->with('foo_command', 'first') - ; - $realProducer - ->expects($this->at(1)) - ->method('sendCommand') - ->with('bar_command', ['second']) - ; - $realProducer - ->expects($this->at(2)) + ->expects($invoked) ->method('sendCommand') - ->with('baz_command', $this->identicalTo($message)) + ->willReturnCallback(function (string $command, $argMessage, bool $needReply) use ($invoked, $message) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame(['foo_command', 'first', false], [$command, $argMessage, $needReply]), + 2 => $this->assertSame(['bar_command', ['second'], false], [$command, $argMessage, $needReply]), + 3 => $this->assertSame(['baz_command', $message, false], [$command, $argMessage, $needReply]), + }; + }) ; $producer = new SpoolProducer($realProducer); diff --git a/pkg/enqueue/Tests/ResourcesTest.php b/pkg/enqueue/Tests/ResourcesTest.php index ec713fd03..59dd2fb01 100644 --- a/pkg/enqueue/Tests/ResourcesTest.php +++ b/pkg/enqueue/Tests/ResourcesTest.php @@ -6,7 +6,9 @@ use Enqueue\Resources; use Enqueue\Wamp\WampConnectionFactory; use Interop\Queue\ConnectionFactory; +use Interop\Queue\Context; use PHPUnit\Framework\TestCase; +use Symfony\Component\Cache\Exception\LogicException; class ResourcesTest extends TestCase { @@ -70,22 +72,18 @@ public function testThrowsIfConnectionClassNotImplementConnectionFactoryInterfac public function testThrowsIfNoSchemesProvidedOnAddConnection() { - $connectionClass = $this->getMockClass(ConnectionFactory::class); - $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Schemes could not be empty.'); - Resources::addConnection($connectionClass, [], [], 'foo'); + Resources::addConnection(ConnectionFactory::class, [], [], 'foo'); } public function testThrowsIfNoPackageProvidedOnAddConnection() { - $connectionClass = $this->getMockClass(ConnectionFactory::class); - $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Package name could not be empty.'); - Resources::addConnection($connectionClass, ['foo'], [], ''); + Resources::addConnection(ConnectionFactory::class, ['foo'], [], ''); } public function testShouldAllowRegisterConnectionThatIsNotInstalled() @@ -104,10 +102,15 @@ public function testShouldAllowRegisterConnectionThatIsNotInstalled() public function testShouldAllowGetPreviouslyRegisteredConnection() { - $connectionClass = $this->getMockClass(ConnectionFactory::class); + $connectionClass = new class implements ConnectionFactory { + public function createContext(): Context + { + throw new LogicException('not implemented'); + } + }; Resources::addConnection( - $connectionClass, + $connectionClass::class, ['fooscheme', 'barscheme'], ['fooextension', 'barextension'], 'foo/bar' @@ -116,9 +119,9 @@ public function testShouldAllowGetPreviouslyRegisteredConnection() $availableConnections = Resources::getAvailableConnections(); self::assertIsArray($availableConnections); - $this->assertArrayHasKey($connectionClass, $availableConnections); + $this->assertArrayHasKey($connectionClass::class, $availableConnections); - $connectionInfo = $availableConnections[$connectionClass]; + $connectionInfo = $availableConnections[$connectionClass::class]; $this->assertArrayHasKey('schemes', $connectionInfo); $this->assertSame(['fooscheme', 'barscheme'], $connectionInfo['schemes']); diff --git a/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php b/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php index ae878fc53..cec71fb83 100644 --- a/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php +++ b/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php @@ -10,6 +10,8 @@ use Enqueue\Router\RouteRecipientListProcessor; use Enqueue\Test\ClassExtensionTrait; use Interop\Queue\Context; +use Interop\Queue\Destination; +use Interop\Queue\Message; use Interop\Queue\Processor; use Interop\Queue\Producer as InteropProducer; use PHPUnit\Framework\TestCase; @@ -38,17 +40,17 @@ public function testShouldProduceRecipientsMessagesAndAckOriginalMessage() ->willReturn([$fooRecipient, $barRecipient]) ; + $invoked = $this->exactly(2); $producerMock = $this->createProducerMock(); $producerMock - ->expects($this->at(0)) + ->expects($invoked) ->method('send') - ->with($this->identicalTo($fooRecipient->getDestination()), $this->identicalTo($fooRecipient->getMessage())) - ; - $producerMock - ->expects($this->at(1)) - ->method('send') - ->with($this->identicalTo($barRecipient->getDestination()), $this->identicalTo($barRecipient->getMessage())) - ; + ->willReturnCallback(function (Destination $destination, Message $message) use ($invoked, $fooRecipient, $barRecipient) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame([$fooRecipient->getDestination(), $fooRecipient->getMessage()], [$destination, $message]), + 2 => $this->assertSame([$barRecipient->getDestination(), $barRecipient->getMessage()], [$destination, $message]), + }; + }); $sessionMock = $this->createContextMock(); $sessionMock diff --git a/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php index 3758ca96a..c0c79a402 100644 --- a/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php @@ -19,6 +19,7 @@ use Interop\Queue\Consumer; use Interop\Queue\Context as InteropContext; use Interop\Queue\Exception\SubscriptionConsumerNotSupportedException; +use Interop\Queue\Processor; use Interop\Queue\Queue; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -274,33 +275,35 @@ public function testShouldBindCustomExecuteConsumptionAndUseCustomClientDestinat $processor = $this->createDelegateProcessorMock(); + $driverInvoked = $this->exactly(2); $driver = $this->createDriverStub($routeCollection); $driver - ->expects($this->at(3)) + ->expects($driverInvoked) ->method('createQueue') - ->with('default', true) - ->willReturn($defaultQueue) - ; - $driver - ->expects($this->at(4)) - ->method('createQueue') - ->with('custom', true) - ->willReturn($customQueue) - ; + ->willReturnCallback(function (string $queueName, bool $prefix) use ($driverInvoked, $defaultQueue, $customQueue) { + match ($driverInvoked->getInvocationCount()) { + 1 => $this->assertSame(['default', true], [$queueName, $prefix]), + 2 => $this->assertSame(['custom', true], [$queueName, $prefix]), + }; - $consumer = $this->createQueueConsumerMock(); - $consumer - ->expects($this->at(0)) - ->method('bind') - ->with($this->identicalTo($defaultQueue), $this->identicalTo($processor)) + return 1 === $driverInvoked->getInvocationCount() ? $defaultQueue : $customQueue; + }) ; + $consumerInvoked = $this->exactly(2); + $consumer = $this->createQueueConsumerMock(); $consumer - ->expects($this->at(1)) + ->expects($consumerInvoked) ->method('bind') - ->with($this->identicalTo($customQueue), $this->identicalTo($processor)) - ; + ->willReturnCallback(function ($queueName, Processor $argProcessor) use ($consumerInvoked, $defaultQueue, $processor, $customQueue, $consumer) { + match ($consumerInvoked->getInvocationCount()) { + 1 => $this->assertSame([$defaultQueue, $processor], [$queueName, $argProcessor]), + 2 => $this->assertSame([$customQueue, $processor], [$queueName, $argProcessor]), + }; + + return $consumer; + }); $consumer - ->expects($this->at(2)) + ->expects($this->once()) ->method('consume') ->with($this->isInstanceOf(ChainExtension::class)) ; @@ -413,33 +416,37 @@ public function testShouldBindQueuesOnlyOnce() $processor = $this->createDelegateProcessorMock(); + $invoked = $this->exactly(2); $driver = $this->createDriverStub($routeCollection); $driver - ->expects($this->at(3)) + ->expects($invoked) ->method('createQueue') - ->with('default', true) - ->willReturn($defaultQueue) - ; - $driver - ->expects($this->at(4)) - ->method('createQueue', true) - ->with('custom') - ->willReturn($customQueue) + ->willReturnCallback(function (string $queueName, bool $prefix) use ($defaultQueue, $customQueue, $invoked) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame(['default', true], [$queueName, $prefix]), + 2 => $this->assertSame(['custom', true], [$queueName, $prefix]), + }; + + return 1 === $invoked->getInvocationCount() ? $defaultQueue : $customQueue; + }) ; + $consumerInvoked = $this->exactly(2); $consumer = $this->createQueueConsumerMock(); $consumer - ->expects($this->at(0)) + ->expects($consumerInvoked) ->method('bind') - ->with($this->identicalTo($defaultQueue), $this->identicalTo($processor)) - ; - $consumer - ->expects($this->at(1)) - ->method('bind') - ->with($this->identicalTo($customQueue), $this->identicalTo($processor)) + ->willReturnCallback(function ($queueName, Processor $argProcessor) use ($consumerInvoked, $defaultQueue, $processor, $consumer, $customQueue) { + match ($consumerInvoked->getInvocationCount()) { + 1 => $this->assertSame([$defaultQueue, $processor], [$queueName, $argProcessor]), + 2 => $this->assertSame([$customQueue, $processor], [$queueName, $argProcessor]), + }; + + return $consumer; + }) ; $consumer - ->expects($this->at(2)) + ->expects($this->once()) ->method('consume') ->with($this->isInstanceOf(ChainExtension::class)) ; @@ -467,7 +474,7 @@ public function testShouldNotBindExternalRoutes() $driver = $this->createDriverStub($routeCollection); $driver - ->expects($this->exactly(1)) + ->expects($this->once()) ->method('createQueue') ->with('default', true) ->willReturn($defaultQueue) @@ -475,12 +482,12 @@ public function testShouldNotBindExternalRoutes() $consumer = $this->createQueueConsumerMock(); $consumer - ->expects($this->exactly(1)) + ->expects($this->once()) ->method('bind') ->with($this->identicalTo($defaultQueue), $this->identicalTo($processor)) ; $consumer - ->expects($this->at(1)) + ->expects($this->once()) ->method('consume') ->with($this->isInstanceOf(ChainExtension::class)) ; @@ -520,21 +527,9 @@ public function testShouldSkipQueueConsumptionAndUseCustomClientDestinationName( $driver = $this->createDriverStub($routeCollection); $driver - ->expects($this->at(3)) - ->method('createQueue', true) - ->with('default') - ->willReturn($queue) - ; - $driver - ->expects($this->at(4)) - ->method('createQueue', true) - ->with('fooQueue') - ->willReturn($queue) - ; - $driver - ->expects($this->at(5)) - ->method('createQueue', true) - ->with('ololoQueue') + ->expects($this->exactly(3)) + ->method('createQueue') + ->with($this->logicalOr('default', 'fooQueue', 'ololoQueue')) ->willReturn($queue) ; diff --git a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php index 251e264e2..ef22b710f 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php @@ -168,19 +168,22 @@ public function testShouldExecuteConsumptionWithSeveralCustomQueues() { $processor = $this->createProcessor(); + $invoked = $this->exactly(2); $consumer = $this->createQueueConsumerMock(); $consumer - ->expects($this->at(0)) + ->expects($invoked) ->method('bind') - ->with('queue-name', $this->identicalTo($processor)) + ->willReturnCallback(function ($queueName, Processor $argProcessor) use ($invoked, $processor, $consumer) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame(['queue-name', $processor], [$queueName, $argProcessor]), + 2 => $this->assertSame(['another-queue-name', $processor], [$queueName, $argProcessor]), + }; + + return $consumer; + }) ; $consumer - ->expects($this->at(1)) - ->method('bind') - ->with('another-queue-name', $this->identicalTo($processor)) - ; - $consumer - ->expects($this->at(2)) + ->expects($this->once()) ->method('consume') ->with($this->isInstanceOf(ChainExtension::class)) ; @@ -210,19 +213,23 @@ public static function getSubscribedQueues() } }; + $invoked = $this->exactly(2); + $consumer = $this->createQueueConsumerMock(); $consumer - ->expects($this->at(0)) + ->expects($invoked) ->method('bind') - ->with('fooSubscribedQueues', $this->identicalTo($processor)) + ->willReturnCallback(function ($queueName, Processor $argProcessor) use ($invoked, $processor, $consumer) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame(['fooSubscribedQueues', $processor], [$queueName, $argProcessor]), + 2 => $this->assertSame(['barSubscribedQueues', $processor], [$queueName, $argProcessor]), + }; + + return $consumer; + }) ; $consumer - ->expects($this->at(1)) - ->method('bind') - ->with('barSubscribedQueues', $this->identicalTo($processor)) - ; - $consumer - ->expects($this->at(2)) + ->expects($this->once()) ->method('consume') ->with($this->isInstanceOf(ChainExtension::class)) ; diff --git a/pkg/job-queue/Test/DbalPersistedConnection.php b/pkg/job-queue/Test/DbalPersistedConnection.php index 470a65176..91c2bb2f1 100644 --- a/pkg/job-queue/Test/DbalPersistedConnection.php +++ b/pkg/job-queue/Test/DbalPersistedConnection.php @@ -136,7 +136,7 @@ private function wrapTransactionNestingLevel($method) $this->setTransactionNestingLevel($this->getPersistedTransactionNestingLevel()); try { - call_user_func(['parent', $method]); + call_user_func([parent::class, $method]); } catch (\Exception $e) { } diff --git a/pkg/job-queue/Tests/Doctrine/JobStorageTest.php b/pkg/job-queue/Tests/Doctrine/JobStorageTest.php index 73f130d52..f0e96ff9b 100644 --- a/pkg/job-queue/Tests/Doctrine/JobStorageTest.php +++ b/pkg/job-queue/Tests/Doctrine/JobStorageTest.php @@ -434,15 +434,16 @@ public function testShouldInsertIntoUniqueTableIfJobIsUniqueAndNew() $callback($connection); }) ; + $invoked = $this->exactly(2); $connection - ->expects($this->at(0)) + ->expects($invoked) ->method('insert') - ->with('unique_table', ['name' => 'owner-id']) - ; - $connection - ->expects($this->at(1)) - ->method('insert') - ->with('unique_table', ['name' => 'job-name']) + ->willReturnCallback(function ($table, array $data, array $types) use ($invoked) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame(['unique_table', ['name' => 'owner-id'], []], [$table, $data, $types]), + 2 => $this->assertSame(['unique_table', ['name' => 'job-name'], []], [$table, $data, $types]), + }; + }) ; $repository = $this->createRepositoryMock(); @@ -503,16 +504,17 @@ public function testShouldDeleteRecordFromUniqueTableIfJobIsUniqueAndStoppedAtIs $job->setUnique(true); $job->setStoppedAt(new \DateTime()); + $invoked = $this->exactly(2); $connection = $this->createConnectionMock(); $connection - ->expects($this->at(0)) + ->expects($invoked) ->method('delete') - ->with('unique_table', ['name' => 'owner-id']) - ; - $connection - ->expects($this->at(1)) - ->method('delete') - ->with('unique_table', ['name' => 'job-name']) + ->willReturnCallback(function ($table, array $criteria, array $types) use ($invoked) { + match ($invoked->getInvocationCount()) { + 1 => $this->assertSame(['unique_table', ['name' => 'owner-id'], []], [$table, $criteria, $types]), + 2 => $this->assertSame(['unique_table', ['name' => 'job-name'], []], [$table, $criteria, $types]), + }; + }) ; $repository = $this->createRepositoryMock(); diff --git a/pkg/rdkafka/Tests/RdKafkaConsumerTest.php b/pkg/rdkafka/Tests/RdKafkaConsumerTest.php index a0544da6c..e577dfcca 100644 --- a/pkg/rdkafka/Tests/RdKafkaConsumerTest.php +++ b/pkg/rdkafka/Tests/RdKafkaConsumerTest.php @@ -190,6 +190,7 @@ public function testShouldReceiveFromQueueAndReturnMessageIfMessageInQueue() $kafkaMessage = new Message(); $kafkaMessage->err = \RD_KAFKA_RESP_ERR_NO_ERROR; $kafkaMessage->payload = 'theSerializedMessage'; + $kafkaMessage->partition = 0; $kafkaConsumer = $this->createKafkaConsumerMock(); $kafkaConsumer diff --git a/pkg/redis/PhpRedis.php b/pkg/redis/PhpRedis.php index 1a229e3c9..db6174726 100644 --- a/pkg/redis/PhpRedis.php +++ b/pkg/redis/PhpRedis.php @@ -111,8 +111,8 @@ public function connect(): void $this->config['port'], $this->config['timeout'], $this->config['persistent'] ? ($this->config['phpredis_persistent_id'] ?? null) : null, - $this->config['phpredis_retry_interval'] ?? null, - $this->config['read_write_timeout'] + $this->config['phpredis_retry_interval'] ?? 0, + $this->config['read_write_timeout'] ?? 0 ); if (false == $result) { diff --git a/pkg/redis/Tests/RedisConsumerTest.php b/pkg/redis/Tests/RedisConsumerTest.php index 56373c18a..27c7127c3 100644 --- a/pkg/redis/Tests/RedisConsumerTest.php +++ b/pkg/redis/Tests/RedisConsumerTest.php @@ -183,22 +183,14 @@ public function testShouldCallRedisBRPopSeveralTimesWithFiveSecondTimeoutIfZeroT $redisMock = $this->createRedisMock(); $redisMock - ->expects($this->at(2)) + ->expects($this->exactly(3)) ->method('brpop') ->with(['aQueue'], $expectedTimeout) - ->willReturn(null) - ; - $redisMock - ->expects($this->at(5)) - ->method('brpop') - ->with(['aQueue'], $expectedTimeout) - ->willReturn(null) - ; - $redisMock - ->expects($this->at(8)) - ->method('brpop') - ->with(['aQueue'], $expectedTimeout) - ->willReturn(new RedisResult('aQueue', $serializer->toString(new RedisMessage('aBody')))) + ->willReturnOnConsecutiveCalls( + null, + null, + new RedisResult('aQueue', $serializer->toString(new RedisMessage('aBody'))) + ) ; $contextMock = $this->createContextMock(); diff --git a/pkg/redis/Tests/RedisContextTest.php b/pkg/redis/Tests/RedisContextTest.php index 6395e954e..606d564a8 100644 --- a/pkg/redis/Tests/RedisContextTest.php +++ b/pkg/redis/Tests/RedisContextTest.php @@ -149,19 +149,9 @@ public function testShouldAllowDeleteQueue() { $redisMock = $this->createRedisMock(); $redisMock - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('del') - ->with('aQueueName') - ; - $redisMock - ->expects($this->at(1)) - ->method('del') - ->with('aQueueName:delayed') - ; - $redisMock - ->expects($this->at(2)) - ->method('del') - ->with('aQueueName:reserved') + ->with($this->logicalOr('aQueueName', 'aQueueName:delayed', 'aQueueName:reserved')) ; $context = new RedisContext($redisMock, 300); @@ -189,19 +179,9 @@ public function testShouldAllowDeleteTopic() { $redisMock = $this->createRedisMock(); $redisMock - ->expects($this->at(0)) - ->method('del') - ->with('aTopicName') - ; - $redisMock - ->expects($this->at(1)) - ->method('del') - ->with('aTopicName:delayed') - ; - $redisMock - ->expects($this->at(2)) + ->expects($this->exactly(3)) ->method('del') - ->with('aTopicName:reserved') + ->with($this->logicalOr('aTopicName', 'aTopicName:delayed', 'aTopicName:reserved')) ; $context = new RedisContext($redisMock, 300); diff --git a/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveFromQueueTest.php b/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveFromQueueTest.php index 707cab529..e2412c6d0 100644 --- a/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveFromQueueTest.php +++ b/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveFromQueueTest.php @@ -2,7 +2,6 @@ namespace Enqueue\SnsQs\Tests\Spec; -use Enqueue\Test\RetryTrait; use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveFromQueueSpec; @@ -13,7 +12,6 @@ */ class SnsQsSendToAndReceiveFromQueueTest extends SendToAndReceiveFromQueueSpec { - use RetryTrait; use SnsQsFactoryTrait; protected function tearDown(): void diff --git a/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveNoWaitFromQueueTest.php b/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveNoWaitFromQueueTest.php index 652766de4..810c02f0d 100644 --- a/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveNoWaitFromQueueTest.php +++ b/pkg/snsqs/Tests/Spec/SnsQsSendToAndReceiveNoWaitFromQueueTest.php @@ -2,7 +2,6 @@ namespace Enqueue\SnsQs\Tests\Spec; -use Enqueue\Test\RetryTrait; use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveNoWaitFromQueueSpec; @@ -13,7 +12,6 @@ */ class SnsQsSendToAndReceiveNoWaitFromQueueTest extends SendToAndReceiveNoWaitFromQueueSpec { - use RetryTrait; use SnsQsFactoryTrait; protected function tearDown(): void diff --git a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveFromQueueSpec.php b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveFromQueueSpec.php index 4a5869d63..15118f2e1 100644 --- a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveFromQueueSpec.php +++ b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveFromQueueSpec.php @@ -2,7 +2,6 @@ namespace Enqueue\SnsQs\Tests\Spec; -use Enqueue\Test\RetryTrait; use Interop\Queue\Context; use Interop\Queue\Spec\SendToTopicAndReceiveFromQueueSpec; @@ -13,7 +12,6 @@ */ class SnsQsSendToTopicAndReceiveFromQueueSpec extends SendToTopicAndReceiveFromQueueSpec { - use RetryTrait; use SnsQsFactoryTrait; protected function tearDown(): void diff --git a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php index 433fcf3a7..a4eae7396 100644 --- a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php +++ b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php @@ -2,7 +2,6 @@ namespace Enqueue\SnsQs\Tests\Spec; -use Enqueue\Test\RetryTrait; use Interop\Queue\Context; use Interop\Queue\Spec\SendToTopicAndReceiveNoWaitFromQueueSpec; @@ -13,7 +12,6 @@ */ class SnsQsSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiveNoWaitFromQueueSpec { - use RetryTrait; use SnsQsFactoryTrait; protected function tearDown(): void diff --git a/pkg/sqs/Tests/Functional/SqsConsumptionUseCasesTest.php b/pkg/sqs/Tests/Functional/SqsConsumptionUseCasesTest.php index 9c57dcbdc..dc40dab28 100644 --- a/pkg/sqs/Tests/Functional/SqsConsumptionUseCasesTest.php +++ b/pkg/sqs/Tests/Functional/SqsConsumptionUseCasesTest.php @@ -9,7 +9,6 @@ use Enqueue\Consumption\QueueConsumer; use Enqueue\Consumption\Result; use Enqueue\Sqs\SqsContext; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Message; @@ -18,7 +17,6 @@ class SqsConsumptionUseCasesTest extends TestCase { - use RetryTrait; use SqsExtension; /** diff --git a/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php index 40f20d68f..958268fe1 100644 --- a/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php @@ -4,7 +4,6 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Sqs\SqsDestination; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Spec\SendAndReceiveDelayedMessageFromQueueSpec; @@ -17,7 +16,6 @@ class SqsSendAndReceiveDelayedMessageFromQueueTest extends SendAndReceiveDelayedMessageFromQueueSpec { use CreateSqsQueueTrait; - use RetryTrait; use SqsExtension; /** diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php index db698017d..5942c0632 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php @@ -4,7 +4,6 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Sqs\SqsDestination; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveFromQueueSpec; @@ -17,7 +16,6 @@ class SqsSendToAndReceiveFromQueueTest extends SendToAndReceiveFromQueueSpec { use CreateSqsQueueTrait; - use RetryTrait; use SqsExtension; /** diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php index 5cd14468a..84345b4fe 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php @@ -4,7 +4,6 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Sqs\SqsDestination; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveFromTopicSpec; @@ -17,7 +16,6 @@ class SqsSendToAndReceiveFromTopicTest extends SendToAndReceiveFromTopicSpec { use CreateSqsQueueTrait; - use RetryTrait; use SqsExtension; /** diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php index 7e31a25a4..e39ec1e4a 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php @@ -4,7 +4,6 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Sqs\SqsDestination; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveNoWaitFromQueueSpec; @@ -17,7 +16,6 @@ class SqsSendToAndReceiveNoWaitFromQueueTest extends SendToAndReceiveNoWaitFromQueueSpec { use CreateSqsQueueTrait; - use RetryTrait; use SqsExtension; /** diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php index 34f2e75dd..ac66ec5c8 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php @@ -4,7 +4,6 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Sqs\SqsDestination; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveNoWaitFromTopicSpec; @@ -17,7 +16,6 @@ class SqsSendToAndReceiveNoWaitFromTopicTest extends SendToAndReceiveNoWaitFromTopicSpec { use CreateSqsQueueTrait; - use RetryTrait; use SqsExtension; /** diff --git a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php index b8e60aee9..258096e30 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php @@ -4,7 +4,6 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Sqs\SqsDestination; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Spec\SendToTopicAndReceiveFromQueueSpec; @@ -17,7 +16,6 @@ class SqsSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec { use CreateSqsQueueTrait; - use RetryTrait; use SqsExtension; /** diff --git a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php index e5520e01f..fc057b95c 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php @@ -4,7 +4,6 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Sqs\SqsDestination; -use Enqueue\Test\RetryTrait; use Enqueue\Test\SqsExtension; use Interop\Queue\Context; use Interop\Queue\Spec\SendToTopicAndReceiveNoWaitFromQueueSpec; @@ -17,7 +16,6 @@ class SqsSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiveNoWaitFromQueueSpec { use CreateSqsQueueTrait; - use RetryTrait; use SqsExtension; /** diff --git a/pkg/stomp/Tests/BufferedStompClientTest.php b/pkg/stomp/Tests/BufferedStompClientTest.php index e4b6226e1..785d1a3d5 100644 --- a/pkg/stomp/Tests/BufferedStompClientTest.php +++ b/pkg/stomp/Tests/BufferedStompClientTest.php @@ -32,8 +32,8 @@ public function testShouldCleanBufferOnDisconnect() { $client = new BufferedStompClient('tcp://localhost:12345', 12345); - $this->assertObjectHasAttribute('buffer', $client); - $this->assertObjectHasAttribute('currentBufferSize', $client); + $this->assertObjectHasProperty('buffer', $client); + $this->assertObjectHasProperty('currentBufferSize', $client); $this->writeAttribute($client, 'buffer', [1, 2, 3]); $this->writeAttribute($client, 'currentBufferSize', 12345); @@ -123,14 +123,8 @@ public function testShouldAddFrameToBufferIfSubscriptionIdIsNotEqual() $connection = $this->createStompConnectionMock(); $connection - ->expects($this->at(1)) ->method('readFrame') - ->willReturn($frame) - ; - $connection - ->expects($this->at(2)) - ->method('readFrame') - ->willReturn(false) + ->willReturnOnConsecutiveCalls($frame, false) ; $client = new BufferedStompClient($connection); @@ -154,14 +148,9 @@ public function testShouldAddFirstFrameToBufferIfSubscriptionNotEqualAndReturnSe $connection = $this->createStompConnectionMock(); $connection - ->expects($this->at(1)) - ->method('readFrame') - ->willReturn($frame1) - ; - $connection - ->expects($this->at(3)) + ->expects($this->exactly(2)) ->method('readFrame') - ->willReturn($frame2) + ->willReturnOnConsecutiveCalls($frame1, $frame2) ; $client = new BufferedStompClient($connection); diff --git a/pkg/wamp/Tests/Functional/WampConsumerTest.php b/pkg/wamp/Tests/Functional/WampConsumerTest.php index bb2dd89a4..1caf2b77d 100644 --- a/pkg/wamp/Tests/Functional/WampConsumerTest.php +++ b/pkg/wamp/Tests/Functional/WampConsumerTest.php @@ -2,7 +2,6 @@ namespace Enqueue\Wamp\Tests\Functional; -use Enqueue\Test\RetryTrait; use Enqueue\Test\WampExtension; use Enqueue\Wamp\WampMessage; use PHPUnit\Framework\TestCase; @@ -17,7 +16,6 @@ */ class WampConsumerTest extends TestCase { - use RetryTrait; use WampExtension; public static function setUpBeforeClass(): void