From 4de2c5a83dd258d027a36303bac02f7e145548de Mon Sep 17 00:00:00 2001 From: Jonathan VUILLEMIN Date: Mon, 29 Jul 2019 16:32:04 +0200 Subject: [PATCH] Fixed 'transport_name' option resolver check in QueueInteropTransport --- QueueInteropTransport.php | 2 ++ Tests/QueueInteropTransportTest.php | 54 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/QueueInteropTransport.php b/QueueInteropTransport.php index 9401e44..8d8d108 100644 --- a/QueueInteropTransport.php +++ b/QueueInteropTransport.php @@ -159,6 +159,7 @@ public function send(Envelope $envelope): Envelope public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults(array( + 'transport_name' => null, 'receiveTimeout' => null, 'deliveryDelay' => null, 'delayStrategy' => RabbitMqDelayPluginDelayStrategy::class, @@ -168,6 +169,7 @@ public function configureOptions(OptionsResolver $resolver): void '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')); diff --git a/Tests/QueueInteropTransportTest.php b/Tests/QueueInteropTransportTest.php index db58dc9..2b96711 100644 --- a/Tests/QueueInteropTransportTest.php +++ b/Tests/QueueInteropTransportTest.php @@ -41,6 +41,7 @@ public function testInterfaces() public function testSendAndEnsuresTheInfrastructureExistsWithDebug() { + $transportName = 'transport'; $topicName = 'topic'; $queueName = 'queue'; $message = new \stdClass(); @@ -80,6 +81,7 @@ public function testSendAndEnsuresTheInfrastructureExistsWithDebug() $encoderProphecy->reveal(), $contextManagerProphecy->reveal(), array( + 'transport_name' => $transportName, 'topic' => array('name' => $topicName), 'queue' => array('name' => $queueName), 'deliveryDelay' => 100, @@ -94,8 +96,49 @@ public function testSendAndEnsuresTheInfrastructureExistsWithDebug() $this->assertSame($envelope, $transport->send($envelope)); } + public function testSendWithoutTransportName() + { + $topicName = 'topic'; + $queueName = 'queue'; + $message = new \stdClass(); + $message->foo = 'bar'; + $envelope = new Envelope($message); + + $psrMessageProphecy = $this->prophesize(Message::class); + $psrMessage = $psrMessageProphecy->reveal(); + $topicProphecy = $this->prophesize(Topic::class); + $topic = $topicProphecy->reveal(); + + $producerProphecy = $this->prophesize(Producer::class); + $producerProphecy->send($topic, $psrMessage)->shouldBeCalled(); + + $contextProphecy = $this->prophesize(Context::class); + $contextProphecy->createTopic($topicName)->shouldBeCalled()->willReturn($topic); + $contextProphecy->createProducer()->shouldBeCalled()->willReturn($producerProphecy->reveal()); + $contextProphecy->createMessage('foo', array(), array())->shouldBeCalled()->willReturn($psrMessage); + + $contextManagerProphecy = $this->prophesize(ContextManager::class); + $contextManagerProphecy->context()->shouldBeCalled()->willReturn($contextProphecy->reveal()); + + $encoderProphecy = $this->prophesize(SerializerInterface::class); + $encoderProphecy->encode($envelope)->shouldBeCalled()->willReturn(array('body' => 'foo')); + + $transport = $this->getTransport( + $encoderProphecy->reveal(), + $contextManagerProphecy->reveal(), + array( + 'topic' => array('name' => $topicName), + 'queue' => array('name' => $queueName), + ), + false + ); + + $transport->send($envelope); + } + public function testSendWithoutDebugWillNotVerifyTheInfrastructureForPerformanceReasons() { + $transportName = 'transport'; $topicName = 'topic'; $queueName = 'queue'; $message = new \stdClass(); @@ -125,6 +168,7 @@ public function testSendWithoutDebugWillNotVerifyTheInfrastructureForPerformance $encoderProphecy->reveal(), $contextManagerProphecy->reveal(), array( + 'transport_name' => $transportName, 'topic' => array('name' => $topicName), 'queue' => array('name' => $queueName), ), @@ -136,6 +180,7 @@ public function testSendWithoutDebugWillNotVerifyTheInfrastructureForPerformance public function testSendMessageOnSpecificTopic() { + $transportName = 'transport'; $topicName = 'topic'; $queueName = 'queue'; $specificTopicName = 'specific-topic'; @@ -172,6 +217,7 @@ public function testSendMessageOnSpecificTopic() $encoderProphecy->reveal(), $contextManagerProphecy->reveal(), array( + 'transport_name' => $transportName, 'topic' => array('name' => $topicName), 'queue' => array('name' => $queueName), ), @@ -183,6 +229,7 @@ public function testSendMessageOnSpecificTopic() public function testSendWithQueueAndTopicSpecificOptions() { + $transportName = 'transport'; $topicName = 'topic'; $queueName = 'queue'; $message = new \stdClass(); @@ -218,6 +265,7 @@ public function testSendWithQueueAndTopicSpecificOptions() $encoderProphecy->reveal(), $contextManagerProphecy->reveal(), array( + 'transport_name' => $transportName, 'topic' => array('name' => $topicName, 'foo' => 'bar'), 'queue' => array('name' => $queueName, 'bar' => 'foo'), ), @@ -229,6 +277,7 @@ public function testSendWithQueueAndTopicSpecificOptions() public function testSendWithMessageMetadata() { + $transportName = 'transport'; $topicName = 'topic'; $queueName = 'queue'; $message = new \stdClass(); @@ -267,6 +316,7 @@ public function testSendWithMessageMetadata() $encoderProphecy->reveal(), $contextManagerProphecy->reveal(), array( + 'transport_name' => $transportName, 'topic' => array('name' => $topicName, 'foo' => 'bar'), 'queue' => array('name' => $queueName, 'bar' => 'foo'), ), @@ -281,6 +331,7 @@ public function testSendWithBadMessageMetadata() $this->expectException(MissingMessageMetadataSetterException::class); $this->expectExceptionMessageRegExp('/Missing "setDumb" setter for "dumb" metadata key in "Double\\\Enqueue\\\MessengerAdapter\\\Tests\\\Fixtures\\\DecoratedPsrMessage\\\[^"]+" class/'); + $transportName = 'transport'; $topicName = 'topic'; $queueName = 'queue'; $message = new \stdClass(); @@ -314,6 +365,7 @@ public function testSendWithBadMessageMetadata() $encoderProphecy->reveal(), $contextManagerProphecy->reveal(), array( + 'transport_name' => $transportName, 'topic' => array('name' => $topicName, 'foo' => 'bar'), 'queue' => array('name' => $queueName, 'bar' => 'foo'), ), @@ -328,6 +380,7 @@ public function testSendWithBadMessageMetadata() */ public function testThrow() { + $transportName = 'transport'; $topicName = 'topic'; $queueName = 'queue'; $message = new \stdClass(); @@ -365,6 +418,7 @@ public function testThrow() $encoderProphecy->reveal(), $contextManagerProphecy->reveal(), array( + 'transport_name' => $transportName, 'topic' => array('name' => $topicName), 'queue' => array('name' => $queueName), ),