diff --git a/AmqpContextManager.php b/AmqpContextManager.php index a46e8bc..ff5715a 100644 --- a/AmqpContextManager.php +++ b/AmqpContextManager.php @@ -17,9 +17,23 @@ use Interop\Amqp\Impl\AmqpBind; use Interop\Queue\Context; +use InvalidArgumentException; + +use function array_key_exists; + class AmqpContextManager implements ContextManager { - private $context; + private const ARGUMENTS_AS_INTEGER = [ + 'x-delay', + 'x-expires', + 'x-max-length', + 'x-max-length-bytes', + 'x-max-priority', + 'x-message-ttl', + 'x-consumer-timeout', + ]; + + private Context $context; public function __construct(Context $context) { @@ -59,19 +73,57 @@ public function ensureExists(array $destination): bool $topic = $this->context->createTopic($destination['topic']); $topic->setType($destination['topicOptions']['type'] ?? AmqpTopic::TYPE_FANOUT); - $topicFlags = $destination['topicOptions']['flags'] ?? ((int) $topic->getFlags() | AmqpTopic::FLAG_DURABLE); + $topicFlags = $destination['topicOptions']['flags'] ?? ((int)$topic->getFlags() | AmqpTopic::FLAG_DURABLE); $topic->setFlags($topicFlags); $this->context->declareTopic($topic); $queue = $this->context->createQueue($destination['queue']); - $queueFlags = $destination['queueOptions']['flags'] ?? ((int) $queue->getFlags() | AmqpQueue::FLAG_DURABLE); + $queueFlags = $destination['queueOptions']['flags'] ?? ((int)$queue->getFlags() | AmqpQueue::FLAG_DURABLE); $queue->setFlags($queueFlags); + $queueArguments = $destination['queueOptions']['arguments'] ?? []; + $queue->setArguments($this->normalizeQueueArguments($queueArguments)); + $this->context->declareQueue($queue); $this->context->bind( - new AmqpBind($queue, $topic, $destination['queueOptions']['bindingKey'] ?? null) + new AmqpBind($queue, $topic, $destination['queueOptions']['bindingKey'] ?? null), ); return true; } + + /** + * Normalizes queue arguments to ensure they are integers. + * + * This method iterates over a predefined list of argument keys that are expected to be integers. + * If an argument is found in the input array but is not numeric, an InvalidArgumentException is thrown. + * Numeric arguments are cast to integers to ensure type consistency. + * + * @param array $arguments Associative array of queue arguments where the key is the argument + * name and the value is the argument value. + * @return array The modified arguments array with all specified keys having integer values. + * @throws InvalidArgumentException If an expected integer argument is not numeric. + */ + private function normalizeQueueArguments(array $arguments): array + { + foreach (self::ARGUMENTS_AS_INTEGER as $key) { + if (!array_key_exists($key, $arguments)) { + continue; + } + + if (!is_numeric($arguments[$key])) { + throw new InvalidArgumentException( + sprintf( + 'Integer expected for queue argument "%s", "%s" given.', + $key, + get_debug_type($arguments[$key]), + ), + ); + } + + $arguments[$key] = (int)$arguments[$key]; + } + + return $arguments; + } } diff --git a/Bundle/DependencyInjection/EnqueueAdapterExtension.php b/Bundle/DependencyInjection/EnqueueAdapterExtension.php index 9f847da..0f4f21b 100644 --- a/Bundle/DependencyInjection/EnqueueAdapterExtension.php +++ b/Bundle/DependencyInjection/EnqueueAdapterExtension.php @@ -21,9 +21,9 @@ class EnqueueAdapterExtension extends Extension /** * {@inheritdoc} */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); } } diff --git a/EnvelopeItem/InteropMessageStamp.php b/EnvelopeItem/InteropMessageStamp.php index df11c69..fad7088 100644 --- a/EnvelopeItem/InteropMessageStamp.php +++ b/EnvelopeItem/InteropMessageStamp.php @@ -17,7 +17,7 @@ final class InteropMessageStamp implements NonSendableStampInterface { /** @var Message */ - private $message; + private Message $message; public function __construct(Message $message) { diff --git a/EnvelopeItem/TransportConfiguration.php b/EnvelopeItem/TransportConfiguration.php index 2baf131..d931a6e 100644 --- a/EnvelopeItem/TransportConfiguration.php +++ b/EnvelopeItem/TransportConfiguration.php @@ -23,14 +23,14 @@ */ final class TransportConfiguration implements StampInterface { - private $topic; + private mixed $topic; private array $metadata; - public function __construct(array $configuration = array()) + public function __construct(array $configuration = []) { $this->topic = $configuration['topic'] ?? null; - $this->metadata = $configuration['metadata'] ?? array(); + $this->metadata = $configuration['metadata'] ?? []; } /** diff --git a/Exception/MissingMessageMetadataSetterException.php b/Exception/MissingMessageMetadataSetterException.php index 3239bf5..c2742f9 100644 --- a/Exception/MissingMessageMetadataSetterException.php +++ b/Exception/MissingMessageMetadataSetterException.php @@ -11,17 +11,20 @@ namespace Enqueue\MessengerAdapter\Exception; +use LogicException; use Symfony\Component\Messenger\Exception\ExceptionInterface; -class MissingMessageMetadataSetterException extends \LogicException implements ExceptionInterface +class MissingMessageMetadataSetterException extends LogicException implements ExceptionInterface { public function __construct(string $metadata, string $setter, string $class) { - parent::__construct(sprintf( - 'Missing "%s" setter for "%s" metadata key in "%s" class', - $setter, - $metadata, - $class - )); + parent::__construct( + sprintf( + 'Missing "%s" setter for "%s" metadata key in "%s" class', + $setter, + $metadata, + $class, + ), + ); } } diff --git a/Exception/RejectMessageException.php b/Exception/RejectMessageException.php index 52bb33b..04dc38e 100644 --- a/Exception/RejectMessageException.php +++ b/Exception/RejectMessageException.php @@ -11,8 +11,9 @@ namespace Enqueue\MessengerAdapter\Exception; +use LogicException; use Symfony\Component\Messenger\Exception\ExceptionInterface; -class RejectMessageException extends \LogicException implements ExceptionInterface +class RejectMessageException extends LogicException implements ExceptionInterface { } diff --git a/Exception/RequeueMessageException.php b/Exception/RequeueMessageException.php index 93e8b5d..b16146f 100644 --- a/Exception/RequeueMessageException.php +++ b/Exception/RequeueMessageException.php @@ -11,8 +11,9 @@ namespace Enqueue\MessengerAdapter\Exception; +use LogicException; use Symfony\Component\Messenger\Exception\ExceptionInterface; -class RequeueMessageException extends \LogicException implements ExceptionInterface +class RequeueMessageException extends LogicException implements ExceptionInterface { } diff --git a/Exception/SendingMessageFailedException.php b/Exception/SendingMessageFailedException.php index d2f53c5..da57d74 100644 --- a/Exception/SendingMessageFailedException.php +++ b/Exception/SendingMessageFailedException.php @@ -11,8 +11,9 @@ namespace Enqueue\MessengerAdapter\Exception; +use LogicException; use Symfony\Component\Messenger\Exception\ExceptionInterface; -class SendingMessageFailedException extends \LogicException implements ExceptionInterface +class SendingMessageFailedException extends LogicException implements ExceptionInterface { } diff --git a/MessageBusProcessor.php b/MessageBusProcessor.php index f529b2c..34c157b 100644 --- a/MessageBusProcessor.php +++ b/MessageBusProcessor.php @@ -19,6 +19,7 @@ use Symfony\Component\Messenger\Exception\MessageDecodingFailedException; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; +use Throwable; /** * The processor could be used with any queue interop compatible consumer, for example Enqueue's QueueConsumer. @@ -26,26 +27,27 @@ * @author Max Kotliar * @author Samuel Roze */ -class MessageBusProcessor implements Processor +readonly class MessageBusProcessor implements Processor { - private $bus; - private $messageDecoder; - public function __construct(MessageBusInterface $bus, SerializerInterface $messageDecoder) - { - $this->bus = $bus; - $this->messageDecoder = $messageDecoder; + public function __construct( + private MessageBusInterface $bus, + private SerializerInterface $messageDecoder, + ) { } + /** + * {@inheritDoc} + */ public function process(Message $message, Context $context) { try { - $busMessage = $this->messageDecoder->decode(array( + $busMessage = $this->messageDecoder->decode([ 'body' => $message->getBody(), 'headers' => $message->getHeaders(), 'properties' => $message->getProperties(), - )); - } catch (MessageDecodingFailedException $e) { + ]); + } catch (MessageDecodingFailedException) { return Processor::REJECT; } @@ -53,11 +55,11 @@ public function process(Message $message, Context $context) $this->bus->dispatch($busMessage); return Processor::ACK; - } catch (RejectMessageException $e) { + } catch (RejectMessageException) { return Processor::REJECT; - } catch (RequeueMessageException $e) { + } catch (RequeueMessageException) { return Processor::REQUEUE; - } catch (\Throwable $e) { + } catch (Throwable) { return Processor::REJECT; } } diff --git a/QueueInteropTransport.php b/QueueInteropTransport.php index 0ae2921..bd0d340 100644 --- a/QueueInteropTransport.php +++ b/QueueInteropTransport.php @@ -18,7 +18,6 @@ use Enqueue\MessengerAdapter\EnvelopeItem\TransportConfiguration; use Enqueue\MessengerAdapter\Exception\MissingMessageMetadataSetterException; use Enqueue\MessengerAdapter\Exception\SendingMessageFailedException; -use Enqueue\SnsQs\SnsQsProducer; use Interop\Queue\Consumer; use Interop\Queue\Exception as InteropQueueException; use Interop\Queue\Message; @@ -40,21 +39,12 @@ */ class QueueInteropTransport implements TransportInterface { - private $serializer; - private $contextManager; - private $options; - private $debug; - public function __construct( - SerializerInterface $serializer, - ContextManager $contextManager, - array $options = array(), - $debug = false + private readonly SerializerInterface $serializer, + private readonly ContextManager $contextManager, + private array $options = [], + private $debug = false, ) { - $this->serializer = $serializer; - $this->contextManager = $contextManager; - $this->debug = $debug; - $resolver = new OptionsResolver(); $this->configureOptions($resolver); $this->options = $resolver->resolve($options); @@ -73,22 +63,22 @@ public function get(): iterable try { if (null === ($interopMessage = $this->getConsumer()->receive($this->options['receiveTimeout'] ?? 30000))) { - return array(); + return []; } } catch (\Exception $e) { if ($this->contextManager->recoverException($e, $destination)) { - return array(); + return []; } throw $e; } try { - $envelope = $this->serializer->decode(array( + $envelope = $this->serializer->decode([ 'body' => $interopMessage->getBody(), 'headers' => $interopMessage->getHeaders(), 'properties' => $interopMessage->getProperties(), - )); + ]); } catch (MessageDecodingFailedException $e) { $this->getConsumer()->reject($interopMessage); @@ -97,7 +87,7 @@ public function get(): iterable $envelope = $envelope->with(new InteropMessageStamp($interopMessage)); - return array($envelope); + return [$envelope]; } /** @@ -140,9 +130,9 @@ public function send(Envelope $envelope): Envelope $producer = $context->createProducer(); if ( + // If queue is present then use it as routing key isset($destination['queue']) && null !== $envelope->last(RedeliveryStamp::class) - && $producer instanceof SnsQsProducer ) { $topic = $context->createQueue($destination['queue']); } @@ -154,6 +144,7 @@ public function send(Envelope $envelope): Envelope } elseif (isset($this->options['deliveryDelay'])) { $delay = $this->options['deliveryDelay']; } + if ($delay > 0) { if ($producer instanceof DelayStrategyAware) { $producer->setDelayStrategy($this->options['delayStrategy']); @@ -184,29 +175,31 @@ public function send(Envelope $envelope): Envelope public function configureOptions(OptionsResolver $resolver): void { - $resolver->setDefaults(array( + $resolver->setDefaults([ 'transport_name' => null, 'receiveTimeout' => null, 'deliveryDelay' => null, 'delayStrategy' => RabbitMqDelayPluginDelayStrategy::class, 'priority' => null, 'timeToLive' => null, - 'topic' => array('name' => 'messages'), - 'queue' => array('name' => 'messages'), - )); - - $resolver->setAllowedTypes('transport_name', array('null', 'string')); - $resolver->setAllowedTypes('receiveTimeout', array('null', 'int')); - $resolver->setAllowedTypes('deliveryDelay', array('null', 'int')); - $resolver->setAllowedTypes('priority', array('null', 'int')); - $resolver->setAllowedTypes('timeToLive', array('null', 'int')); - $resolver->setAllowedTypes('delayStrategy', array('null', 'string')); - - $resolver->setAllowedValues('delayStrategy', array( + 'topic' => ['name' => 'messages'], + 'queue' => ['name' => 'messages'], + ]); + + $resolver->setAllowedTypes('transport_name', ['null', 'string']); + $resolver->setAllowedTypes('receiveTimeout', ['null', 'int']); + $resolver->setAllowedTypes('deliveryDelay', ['null', 'int']); + $resolver->setAllowedTypes('priority', ['null', 'int']); + $resolver->setAllowedTypes('timeToLive', ['null', 'int']); + $resolver->setAllowedTypes('delayStrategy', ['null', 'string']); + + $resolver->setAllowedValues( + 'delayStrategy', + [ null, RabbitMqDelayPluginDelayStrategy::class, RabbitMqDlxDelayStrategy::class, - ) + ], ); $resolver->setNormalizer('delayStrategy', function (Options $options, $value) { @@ -219,12 +212,12 @@ private function getDestination(?Envelope $envelope): array $configuration = $envelope ? $envelope->last(TransportConfiguration::class) : null; $topic = null !== $configuration ? $configuration->getTopic() : null; - return array( + return [ 'topic' => $topic ?? $this->options['topic']['name'], 'topicOptions' => $this->options['topic'], 'queue' => $this->options['queue']['name'], 'queueOptions' => $this->options['queue'], - ); + ]; } private function setMessageMetadata(Message $interopMessage, Envelope $envelope): void @@ -254,8 +247,8 @@ private function encodeMessage(Envelope $envelope): Message $interopMessage = $context->createMessage( $encodedMessage['body'], - $encodedMessage['properties'] ?? array(), - $encodedMessage['headers'] ?? array() + $encodedMessage['properties'] ?? [], + $encodedMessage['headers'] ?? [], ); return $interopMessage; diff --git a/QueueInteropTransportFactory.php b/QueueInteropTransportFactory.php index 98c1cb2..5b87c52 100644 --- a/QueueInteropTransportFactory.php +++ b/QueueInteropTransportFactory.php @@ -12,7 +12,10 @@ namespace Enqueue\MessengerAdapter; use Interop\Queue\Context; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; +use RuntimeException; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; use Symfony\Component\Messenger\Transport\TransportFactoryInterface; use Symfony\Component\Messenger\Transport\TransportInterface; @@ -22,17 +25,13 @@ * * @author Samuel Roze */ -class QueueInteropTransportFactory implements TransportFactoryInterface +readonly class QueueInteropTransportFactory implements TransportFactoryInterface { - private $serializer; - private $debug; - private $container; - - public function __construct(SerializerInterface $serializer, ContainerInterface $container, bool $debug = false) - { - $this->serializer = $serializer; - $this->container = $container; - $this->debug = $debug; + public function __construct( + private SerializerInterface $serializer, + private ContainerInterface $container, + private bool $debug = false, + ) { } // BC layer for Symfony 4.1 beta1 @@ -47,8 +46,11 @@ public function createSender(string $dsn, array $options): TransportInterface return $this->createTransport($dsn, $options); } - public function createTransport(string $dsn, array $options, SerializerInterface $serializer = null): TransportInterface - { + public function createTransport( + string $dsn, + array $options, + SerializerInterface $serializer = null, + ): TransportInterface { [$contextManager, $dsnOptions] = $this->parseDsn($dsn); $options = array_merge($dsnOptions, $options); @@ -57,41 +59,51 @@ public function createTransport(string $dsn, array $options, SerializerInterface $serializer ?? $this->serializer, $contextManager, $options, - $this->debug + $this->debug, ); } public function supports(string $dsn, array $options): bool { - return 0 === strpos($dsn, 'enqueue://'); + return str_starts_with($dsn, 'enqueue://'); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function parseDsn(string $dsn): array { $parsedDsn = parse_url($dsn); $enqueueContextName = $parsedDsn['host']; - $amqpOptions = array(); + $amqpOptions = []; if (isset($parsedDsn['query'])) { parse_str($parsedDsn['query'], $parsedQuery); $parsedQuery = array_map(function ($e) { - return is_numeric($e) ? (int) $e : $e; + return is_numeric($e) ? (int)$e : $e; }, $parsedQuery); $amqpOptions = array_replace_recursive($amqpOptions, $parsedQuery); } - if (!$this->container->has($contextService = 'enqueue.transport.'.$enqueueContextName.'.context')) { - throw new \RuntimeException(sprintf('Can\'t find Enqueue\'s transport named "%s": Service "%s" is not found.', $enqueueContextName, $contextService)); + if (!$this->container->has($contextService = 'enqueue.transport.' . $enqueueContextName . '.context')) { + throw new RuntimeException( + sprintf( + 'Can\'t find Enqueue\'s transport named "%s": Service "%s" is not found.', + $enqueueContextName, + $contextService, + ), + ); } $context = $this->container->get($contextService); if (!$context instanceof Context) { - throw new \RuntimeException(sprintf('Service "%s" not instanceof context', $contextService)); + throw new RuntimeException(sprintf('Service "%s" not instanceof context', $contextService)); } - return array( + return [ new AmqpContextManager($context), $amqpOptions, - ); + ]; } } diff --git a/Tests/AmqpContextManagerTest.php b/Tests/AmqpContextManagerTest.php index 05cf31a..aa89255 100644 --- a/Tests/AmqpContextManagerTest.php +++ b/Tests/AmqpContextManagerTest.php @@ -17,15 +17,24 @@ use Interop\Amqp\AmqpTopic; use Interop\Amqp\Impl\AmqpBind; use Interop\Queue\Context; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +use Throwable; class AmqpContextManagerTest extends TestCase { use ProphecyTrait; - private function getContextManager($topicName, $queueName, $topicType = null, $topicFlags = null, $queueBindingKey = null, $queueFlags = null) - { + private function getContextManager( + $topicName, + $queueName, + $topicType = null, + $topicFlags = null, + $queueBindingKey = null, + $queueFlags = null, + $queueArguments = null, + ): AmqpContextManager { $topicProphecy = $this->prophesize(AmqpTopic::class); $topicProphecy->setType($topicType ?? AmqpTopic::TYPE_FANOUT)->shouldBeCalled(); if (null === $topicFlags) { @@ -39,6 +48,8 @@ private function getContextManager($topicName, $queueName, $topicType = null, $t $queueProphecy->getFlags()->shouldBeCalled()->willReturn(AmqpQueue::FLAG_PASSIVE); } $queueProphecy->setFlags($queueFlags ?? (AmqpQueue::FLAG_DURABLE | AmqpQueue::FLAG_PASSIVE))->shouldBeCalled(); + $queueProphecy->setArguments($queueArguments ?? [])->shouldBeCalled(); + $queue = $queueProphecy->reveal(); $bind = new AmqpBind($queue, $topic, $queueBindingKey); @@ -54,21 +65,21 @@ private function getContextManager($topicName, $queueName, $topicType = null, $t return new AmqpContextManager($context); } - public function testDefaultEnsure() + public function testDefaultEnsure(): void { $topicName = 'foo'; $queueName = 'bar'; $contextManager = $this->getContextManager($topicName, $queueName); - $this->assertTrue($contextManager->ensureExists(array( + $this->assertTrue($contextManager->ensureExists([ 'topic' => $topicName, - 'topicOptions' => array('name' => $topicName), + 'topicOptions' => ['name' => $topicName], 'queue' => $queueName, - 'queueOptions' => array('name' => $queueName), - ))); + 'queueOptions' => ['name' => $queueName], + ])); } - public function testCustomizedEnsure() + public function testCustomizedEnsure(): void { $topicName = 'foo'; $queueName = 'bar'; @@ -76,17 +87,78 @@ public function testCustomizedEnsure() $topicFlags = '8'; $queueFlags = 16; $queueBindingKey = 'foo.#'; - $contextManager = $this->getContextManager($topicName, $queueName, $topicType, $topicFlags, $queueBindingKey, $queueFlags); - - $this->assertTrue($contextManager->ensureExists(array( + $queueArguments = ['x-max-priority' => 10, 'x-consumer-timeout' => '72000', 'x-my-argument' => 'foo']; + $contextManager = $this->getContextManager( + $topicName, + $queueName, + $topicType, + $topicFlags, + $queueBindingKey, + $queueFlags, + $queueArguments, + ); + + $this->assertTrue($contextManager->ensureExists([ 'topic' => $topicName, - 'topicOptions' => array('name' => $topicName, 'type' => $topicType, 'flags' => $topicFlags), + 'topicOptions' => ['name' => $topicName, 'type' => $topicType, 'flags' => $topicFlags], 'queue' => $queueName, - 'queueOptions' => array('name' => $queueName, 'bindingKey' => $queueBindingKey, 'flags' => $queueFlags), - ))); + 'queueOptions' => [ + 'name' => $queueName, + 'bindingKey' => $queueBindingKey, + 'flags' => $queueFlags, + 'arguments' => $queueArguments, + ], + ])); } - public function testNotProcessedEnsure() + public function testInvalidIntegerArgumentTypeEnsure(): void + { + $topicName = 'foo'; + $queueName = 'bar'; + $queueArguments = ['x-max-priority' => 10, 'x-consumer-timeout' => 'string', 'x-my-argument' => 'foo']; + + $topicProphecy = $this->prophesize(AmqpTopic::class); + $topicProphecy->setType(AmqpTopic::TYPE_FANOUT)->shouldBeCalled(); + $topicProphecy->getFlags()->shouldBeCalled()->willReturn(AmqpTopic::FLAG_PASSIVE); + $topicProphecy->setFlags(AmqpTopic::FLAG_DURABLE | AmqpTopic::FLAG_PASSIVE)->shouldBeCalled(); + $topic = $topicProphecy->reveal(); + + $queueProphecy = $this->prophesize(AmqpQueue::class); + $queueProphecy->getFlags()->shouldBeCalled()->willReturn(AmqpQueue::FLAG_PASSIVE); + $queueProphecy->setFlags(AmqpQueue::FLAG_DURABLE | AmqpQueue::FLAG_PASSIVE)->shouldBeCalled(); + $queueProphecy->setArguments($queueArguments)->shouldNotBeCalled(); + + $queue = $queueProphecy->reveal(); + + $contextProphecy = $this->prophesize(AmqpContext::class); + $contextProphecy->createTopic($topicName)->shouldBeCalled()->willReturn($topic); + $contextProphecy->declareTopic($topic)->shouldBeCalled(); + $contextProphecy->createQueue($queueName)->shouldBeCalled()->willReturn($queue); + + $context = $contextProphecy->reveal(); + + $contextManager = new AmqpContextManager($context); + + try { + $contextManager->ensureExists([ + 'topic' => $topicName, + 'topicOptions' => ['name' => $topicName], + 'queue' => $queueName, + 'queueOptions' => [ + 'name' => $queueName, + 'arguments' => $queueArguments, + ], + ]); + } catch (Throwable $e) { + $this->assertInstanceOf(InvalidArgumentException::class, $e); + $this->assertSame( + 'Integer expected for queue argument "x-consumer-timeout", "string" given.', + $e->getMessage(), + ); + } + } + + public function testNotProcessedEnsure(): void { $topicName = 'foo'; $queueName = 'bar'; @@ -96,15 +168,15 @@ public function testNotProcessedEnsure() $contextManager = new AmqpContextManager($context); - $this->assertFalse($contextManager->ensureExists(array( + $this->assertFalse($contextManager->ensureExists([ 'topic' => $topicName, - 'topicOptions' => array('name' => $topicName), + 'topicOptions' => ['name' => $topicName], 'queue' => $queueName, - 'queueOptions' => array('name' => $queueName), - ))); + 'queueOptions' => ['name' => $queueName], + ])); } - public function testContextRetrieving() + public function testContextRetrieving(): void { $contextProphecy = $this->prophesize(Context::class); $context = $contextProphecy->reveal(); diff --git a/Tests/QueueInteropTransportFactoryTest.php b/Tests/QueueInteropTransportFactoryTest.php index 2e1cb97..821f526 100644 --- a/Tests/QueueInteropTransportFactoryTest.php +++ b/Tests/QueueInteropTransportFactoryTest.php @@ -25,15 +25,15 @@ class QueueInteropTransportFactoryTest extends TestCase { use ProphecyTrait; - public function testSupports() + public function testSupports(): void { $factory = $this->getFactory(); - $this->assertTrue($factory->supports('enqueue://something', array())); - $this->assertFalse($factory->supports('amqp://something', array())); + $this->assertTrue($factory->supports('enqueue://something', [])); + $this->assertFalse($factory->supports('amqp://something', [])); } - public function testCreatesTransport() + public function testCreatesTransport(): void { $serializer = $this->prophesize(SerializerInterface::class); $queueContext = $this->prophesize(Context::class)->reveal(); @@ -45,15 +45,20 @@ public function testCreatesTransport() $factory = $this->getFactory($serializer->reveal(), $container->reveal()); $dsn = 'enqueue://default'; - $expectedTransport = new QueueInteropTransport($serializer->reveal(), new AmqpContextManager($queueContext), array(), true); - $this->assertEquals($expectedTransport, $factory->createTransport($dsn, array())); + $expectedTransport = new QueueInteropTransport( + $serializer->reveal(), + new AmqpContextManager($queueContext), + [], + true, + ); + $this->assertEquals($expectedTransport, $factory->createTransport($dsn, [])); // Ensure BC for Symfony beta 4.1 - $this->assertEquals($expectedTransport, $factory->createSender($dsn, array())); - $this->assertEquals($expectedTransport, $factory->createReceiver($dsn, array())); + $this->assertEquals($expectedTransport, $factory->createSender($dsn, [])); + $this->assertEquals($expectedTransport, $factory->createReceiver($dsn, [])); } - public function testDnsParsing() + public function testDnsParsing(): void { $queueContext = $this->prophesize(Context::class)->reveal(); $serializer = $this->prophesize(SerializerInterface::class); @@ -68,42 +73,47 @@ public function testDnsParsing() $expectedTransport = new QueueInteropTransport( $serializer->reveal(), new AmqpContextManager($queueContext), - array( - 'topic' => array('name' => 'test'), - 'queue' => array('name' => 'test'), + [ + 'topic' => ['name' => 'test'], + 'queue' => ['name' => 'test'], 'deliveryDelay' => 100, 'delayStrategy' => RabbitMqDelayPluginDelayStrategy::class, 'priority' => 100, 'timeToLive' => 100, 'receiveTimeout' => 100, - ), - true + ], + true, ); - $this->assertEquals($expectedTransport, $factory->createTransport($dsn, array())); + $this->assertEquals($expectedTransport, $factory->createTransport($dsn, [])); // Ensure BC for Symfony beta 4.1 - $this->assertEquals($expectedTransport, $factory->createSender($dsn, array())); - $this->assertEquals($expectedTransport, $factory->createReceiver($dsn, array())); + $this->assertEquals($expectedTransport, $factory->createSender($dsn, [])); + $this->assertEquals($expectedTransport, $factory->createReceiver($dsn, [])); } public function testItThrowsAnExceptionWhenContextDoesNotExist() { $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage("Can't find Enqueue's transport named \"foo\": Service \"enqueue.transport.foo.context\" is not found."); + $this->expectExceptionMessage( + "Can't find Enqueue's transport named \"foo\": Service \"enqueue.transport.foo.context\" is not found.", + ); $container = $this->prophesize(ContainerInterface::class); $container->has('enqueue.transport.foo.context')->willReturn(false); $factory = $this->getFactory(container: $container->reveal()); - $factory->createTransport('enqueue://foo', array()); + $factory->createTransport('enqueue://foo', []); } - private function getFactory(SerializerInterface $serializer = null, ContainerInterface $container = null, $debug = true) - { + private function getFactory( + SerializerInterface $serializer = null, + ContainerInterface $container = null, + $debug = true, + ) { return new QueueInteropTransportFactory( $serializer ?: $this->prophesize(SerializerInterface::class)->reveal(), $container ?: $this->prophesize(ContainerInterface::class)->reveal(), - $debug + $debug, ); } } diff --git a/composer.json b/composer.json index d4e26a8..ededd93 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "enqueue/enqueue-bundle": "^0.10", "symfony/messenger": "^5.4 || ^6.3 || ^7.0", "symfony/options-resolver": "^5.4 || ^6.3 || ^7.0",