Skip to content

Commit 9c475a6

Browse files
committed
[client] Fix SetRouterProeprtiesExtension should skip no topic messages.
1 parent 14ab754 commit 9c475a6

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

pkg/enqueue/Client/ConsumptionExtension/SetRouterPropertiesExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function __construct(DriverInterface $driver)
2525
public function onMessageReceived(MessageReceived $context): void
2626
{
2727
$message = $context->getMessage();
28+
if (false == $message->getProperty(Config::TOPIC)) {
29+
return;
30+
}
2831
if ($message->getProperty(Config::PROCESSOR)) {
2932
return;
3033
}

pkg/enqueue/Tests/Client/ConsumptionExtension/SetRouterPropertiesExtensionTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function testShouldSetRouterProcessorPropertyIfNotSetAndOnRouterQueue()
4949
;
5050

5151
$message = new NullMessage();
52+
$message->setProperty(Config::TOPIC, 'aTopic');
5253

5354
$messageReceived = new MessageReceived(
5455
$this->createContextMock(),
@@ -64,6 +65,7 @@ public function testShouldSetRouterProcessorPropertyIfNotSetAndOnRouterQueue()
6465

6566
$this->assertEquals([
6667
Config::PROCESSOR => 'router-processor-name',
68+
Config::TOPIC => 'aTopic',
6769
], $message->getProperties());
6870
}
6971

@@ -86,6 +88,7 @@ public function testShouldNotSetRouterProcessorPropertyIfNotSetAndNotOnRouterQue
8688
;
8789

8890
$message = new NullMessage();
91+
$message->setProperty(Config::TOPIC, 'aTopic');
8992

9093
$messageReceived = new MessageReceived(
9194
$this->createContextMock(),
@@ -99,7 +102,9 @@ public function testShouldNotSetRouterProcessorPropertyIfNotSetAndNotOnRouterQue
99102
$extension = new SetRouterPropertiesExtension($driver);
100103
$extension->onMessageReceived($messageReceived);
101104

102-
$this->assertEquals([], $message->getProperties());
105+
$this->assertEquals([
106+
Config::TOPIC => 'aTopic',
107+
], $message->getProperties());
103108
}
104109

105110
public function testShouldNotSetAnyPropertyIfProcessorNamePropertyAlreadySet()
@@ -130,6 +135,31 @@ public function testShouldNotSetAnyPropertyIfProcessorNamePropertyAlreadySet()
130135
], $message->getProperties());
131136
}
132137

138+
public function testShouldSkipMessagesWithoutTopicPropertySet()
139+
{
140+
$driver = $this->createDriverMock();
141+
$driver
142+
->expects($this->never())
143+
->method('getConfig')
144+
;
145+
146+
$message = new NullMessage();
147+
148+
$messageReceived = new MessageReceived(
149+
$this->createContextMock(),
150+
$this->createConsumerStub(null),
151+
$message,
152+
$this->createProcessorMock(),
153+
1,
154+
new NullLogger()
155+
);
156+
157+
$extension = new SetRouterPropertiesExtension($driver);
158+
$extension->onMessageReceived($messageReceived);
159+
160+
$this->assertEquals([], $message->getProperties());
161+
}
162+
133163
/**
134164
* @return \PHPUnit_Framework_MockObject_MockObject|InteropContext
135165
*/

0 commit comments

Comments
 (0)