33namespace Enqueue \Tests \Client ;
44
55use Enqueue \Client \ChainExtension ;
6+ use Enqueue \Client \DriverInterface ;
7+ use Enqueue \Client \DriverPreSend ;
68use Enqueue \Client \ExtensionInterface ;
79use Enqueue \Client \Message ;
10+ use Enqueue \Client \PostSend ;
11+ use Enqueue \Client \PreSend ;
12+ use Enqueue \Client \ProducerInterface ;
813use Enqueue \Test \ClassExtensionTrait ;
914use PHPUnit \Framework \TestCase ;
1015
@@ -17,53 +22,128 @@ public function testShouldImplementExtensionInterface()
1722 $ this ->assertClassImplements (ExtensionInterface::class, ChainExtension::class);
1823 }
1924
25+ public function testShouldBeFinal ()
26+ {
27+ $ this ->assertClassFinal (ChainExtension::class);
28+ }
29+
2030 public function testCouldBeConstructedWithExtensionsArray ()
2131 {
2232 new ChainExtension ([$ this ->createExtension (), $ this ->createExtension ()]);
2333 }
2434
25- public function testShouldProxyOnPreSendToAllInternalExtensions ()
35+ public function testThrowIfArrayContainsNotExtension ()
36+ {
37+ $ this ->expectException (\TypeError::class);
38+ $ this ->expectExceptionMessage ('Argument 1 passed to ' );
39+
40+ new ChainExtension ([$ this ->createExtension (), new \stdClass ()]);
41+ }
42+
43+ public function testShouldProxyOnPreSendEventToAllInternalExtensions ()
44+ {
45+ $ preSend = new PreSend (
46+ 'aCommandOrTopic ' ,
47+ new Message (),
48+ $ this ->createMock (ProducerInterface::class),
49+ $ this ->createMock (DriverInterface::class)
50+ );
51+
52+ $ fooExtension = $ this ->createExtension ();
53+ $ fooExtension
54+ ->expects ($ this ->once ())
55+ ->method ('onPreSendEvent ' )
56+ ->with ($ this ->identicalTo ($ preSend ))
57+ ;
58+ $ barExtension = $ this ->createExtension ();
59+ $ barExtension
60+ ->expects ($ this ->once ())
61+ ->method ('onPreSendEvent ' )
62+ ->with ($ this ->identicalTo ($ preSend ))
63+ ;
64+
65+ $ extensions = new ChainExtension ([$ fooExtension , $ barExtension ]);
66+
67+ $ extensions ->onPreSendEvent ($ preSend );
68+ }
69+
70+ public function testShouldProxyOnPreSendCommandToAllInternalExtensions ()
71+ {
72+ $ preSend = new PreSend (
73+ 'aCommandOrTopic ' ,
74+ new Message (),
75+ $ this ->createMock (ProducerInterface::class),
76+ $ this ->createMock (DriverInterface::class)
77+ );
78+
79+ $ fooExtension = $ this ->createExtension ();
80+ $ fooExtension
81+ ->expects ($ this ->once ())
82+ ->method ('onPreSendCommand ' )
83+ ->with ($ this ->identicalTo ($ preSend ))
84+ ;
85+ $ barExtension = $ this ->createExtension ();
86+ $ barExtension
87+ ->expects ($ this ->once ())
88+ ->method ('onPreSendCommand ' )
89+ ->with ($ this ->identicalTo ($ preSend ))
90+ ;
91+
92+ $ extensions = new ChainExtension ([$ fooExtension , $ barExtension ]);
93+
94+ $ extensions ->onPreSendCommand ($ preSend );
95+ }
96+
97+ public function testShouldProxyOnDriverPreSendToAllInternalExtensions ()
2698 {
27- $ message = new Message ();
99+ $ driverPreSend = new DriverPreSend (
100+ new Message (),
101+ $ this ->createMock (ProducerInterface::class),
102+ $ this ->createMock (DriverInterface::class)
103+ );
28104
29105 $ fooExtension = $ this ->createExtension ();
30106 $ fooExtension
31107 ->expects ($ this ->once ())
32- ->method ('onPreSend ' )
33- ->with (' topic ' , $ this ->identicalTo ($ message ))
108+ ->method ('onDriverPreSend ' )
109+ ->with ($ this ->identicalTo ($ driverPreSend ))
34110 ;
35111 $ barExtension = $ this ->createExtension ();
36112 $ barExtension
37113 ->expects ($ this ->once ())
38- ->method ('onPreSend ' )
39- ->with (' topic ' , $ this ->identicalTo ($ message ))
114+ ->method ('onDriverPreSend ' )
115+ ->with ($ this ->identicalTo ($ driverPreSend ))
40116 ;
41117
42118 $ extensions = new ChainExtension ([$ fooExtension , $ barExtension ]);
43119
44- $ extensions ->onPreSend ( ' topic ' , $ message );
120+ $ extensions ->onDriverPreSend ( $ driverPreSend );
45121 }
46122
47- public function testShouldProxyOnPostSendToAllInternalExtensions ()
123+ public function testShouldProxyOnPostSentToAllInternalExtensions ()
48124 {
49- $ message = new Message ();
125+ $ postSend = new PostSend (
126+ new Message (),
127+ $ this ->createMock (ProducerInterface::class),
128+ $ this ->createMock (DriverInterface::class)
129+ );
50130
51131 $ fooExtension = $ this ->createExtension ();
52132 $ fooExtension
53133 ->expects ($ this ->once ())
54134 ->method ('onPostSend ' )
55- ->with (' topic ' , $ this ->identicalTo ($ message ))
135+ ->with ($ this ->identicalTo ($ postSend ))
56136 ;
57137 $ barExtension = $ this ->createExtension ();
58138 $ barExtension
59139 ->expects ($ this ->once ())
60140 ->method ('onPostSend ' )
61- ->with (' topic ' , $ this ->identicalTo ($ message ))
141+ ->with ($ this ->identicalTo ($ postSend ))
62142 ;
63143
64144 $ extensions = new ChainExtension ([$ fooExtension , $ barExtension ]);
65145
66- $ extensions ->onPostSend (' topic ' , $ message );
146+ $ extensions ->onPostSend ($ postSend );
67147 }
68148
69149 /**
0 commit comments