Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 'transport_name' option resolver check in QueueInteropTransport #82

Merged
merged 1 commit into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions QueueInteropTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'));
Expand Down
54 changes: 54 additions & 0 deletions Tests/QueueInteropTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function testInterfaces()

public function testSendAndEnsuresTheInfrastructureExistsWithDebug()
{
$transportName = 'transport';
$topicName = 'topic';
$queueName = 'queue';
$message = new \stdClass();
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -125,6 +168,7 @@ public function testSendWithoutDebugWillNotVerifyTheInfrastructureForPerformance
$encoderProphecy->reveal(),
$contextManagerProphecy->reveal(),
array(
'transport_name' => $transportName,
'topic' => array('name' => $topicName),
'queue' => array('name' => $queueName),
),
Expand All @@ -136,6 +180,7 @@ public function testSendWithoutDebugWillNotVerifyTheInfrastructureForPerformance

public function testSendMessageOnSpecificTopic()
{
$transportName = 'transport';
$topicName = 'topic';
$queueName = 'queue';
$specificTopicName = 'specific-topic';
Expand Down Expand Up @@ -172,6 +217,7 @@ public function testSendMessageOnSpecificTopic()
$encoderProphecy->reveal(),
$contextManagerProphecy->reveal(),
array(
'transport_name' => $transportName,
'topic' => array('name' => $topicName),
'queue' => array('name' => $queueName),
),
Expand All @@ -183,6 +229,7 @@ public function testSendMessageOnSpecificTopic()

public function testSendWithQueueAndTopicSpecificOptions()
{
$transportName = 'transport';
$topicName = 'topic';
$queueName = 'queue';
$message = new \stdClass();
Expand Down Expand Up @@ -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'),
),
Expand All @@ -229,6 +277,7 @@ public function testSendWithQueueAndTopicSpecificOptions()

public function testSendWithMessageMetadata()
{
$transportName = 'transport';
$topicName = 'topic';
$queueName = 'queue';
$message = new \stdClass();
Expand Down Expand Up @@ -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'),
),
Expand All @@ -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();
Expand Down Expand Up @@ -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'),
),
Expand All @@ -328,6 +380,7 @@ public function testSendWithBadMessageMetadata()
*/
public function testThrow()
{
$transportName = 'transport';
$topicName = 'topic';
$queueName = 'queue';
$message = new \stdClass();
Expand Down Expand Up @@ -365,6 +418,7 @@ public function testThrow()
$encoderProphecy->reveal(),
$contextManagerProphecy->reveal(),
array(
'transport_name' => $transportName,
'topic' => array('name' => $topicName),
'queue' => array('name' => $queueName),
),
Expand Down