88use Enqueue \Consumption \Context ;
99use Enqueue \Consumption \ExtensionInterface ;
1010use Enqueue \Null \NullMessage ;
11+ use Enqueue \Null \NullQueue ;
1112use Enqueue \Psr \PsrContext ;
1213use Enqueue \Test \ClassExtensionTrait ;
1314use PHPUnit \Framework \TestCase ;
@@ -26,13 +27,13 @@ public function testCouldBeConstructedWithRequiredArguments()
2627 new SetRouterPropertiesExtension ($ this ->createDriverMock ());
2728 }
2829
29- public function testShouldSetRouterProcessorPropertyIfNotSet ()
30+ public function testShouldSetRouterProcessorPropertyIfNotSetAndOnRouterQueue ()
3031 {
31- $ config = new Config ( ' ' , '' , '' , 'router-queue ' , '' , 'router-processor-name ' );
32+ $ config = Config:: create ( ' test ' , '' , '' , 'router-queue ' , '' , 'router-processor-name ' );
3233
3334 $ driver = $ this ->createDriverMock ();
3435 $ driver
35- ->expects (self :: exactly ( 2 ))
36+ ->expects ($ this -> once ( ))
3637 ->method ('getConfig ' )
3738 ->willReturn ($ config )
3839 ;
@@ -41,6 +42,7 @@ public function testShouldSetRouterProcessorPropertyIfNotSet()
4142
4243 $ context = new Context ($ this ->createPsrContextMock ());
4344 $ context ->setPsrMessage ($ message );
45+ $ context ->setPsrQueue (new NullQueue ('test.router-queue ' ));
4446
4547 $ extension = new SetRouterPropertiesExtension ($ driver );
4648 $ extension ->onPreReceived ($ context );
@@ -51,11 +53,34 @@ public function testShouldSetRouterProcessorPropertyIfNotSet()
5153 ], $ message ->getProperties ());
5254 }
5355
56+ public function testShouldNotSetRouterProcessorPropertyIfNotSetAndNotOnRouterQueue ()
57+ {
58+ $ config = Config::create ('test ' , '' , '' , 'router-queue ' , '' , 'router-processor-name ' );
59+
60+ $ driver = $ this ->createDriverMock ();
61+ $ driver
62+ ->expects ($ this ->once ())
63+ ->method ('getConfig ' )
64+ ->willReturn ($ config )
65+ ;
66+
67+ $ message = new NullMessage ();
68+
69+ $ context = new Context ($ this ->createPsrContextMock ());
70+ $ context ->setPsrMessage ($ message );
71+ $ context ->setPsrQueue (new NullQueue ('test.another-queue ' ));
72+
73+ $ extension = new SetRouterPropertiesExtension ($ driver );
74+ $ extension ->onPreReceived ($ context );
75+
76+ $ this ->assertEquals ([], $ message ->getProperties ());
77+ }
78+
5479 public function testShouldNotSetAnyPropertyIfProcessorNamePropertyAlreadySet ()
5580 {
5681 $ driver = $ this ->createDriverMock ();
5782 $ driver
58- ->expects (self :: never ())
83+ ->expects ($ this -> never ())
5984 ->method ('getConfig ' )
6085 ;
6186
0 commit comments