diff --git a/composer.json b/composer.json index d2258474d..c62229650 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", @@ -70,7 +70,7 @@ "doctrine/mongodb-odm-bundle": "^3.5|^4.3|^5.0", "alcaeus/mongo-php-adapter": "^1.0", "kwn/php-rdkafka-stubs": "^2.0.3", - "friendsofphp/php-cs-fixer": "^3.4", + "friendsofphp/php-cs-fixer": "^3.64", "dms/phpunit-arraysubset-asserts": "^0.2.1", "phpspec/prophecy-phpunit": "^2.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/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/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/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);