@@ -174,4 +174,59 @@ class_exists(TraceableMiddleware::class);
174
174
$ clonedStackTail = $ clonedStack ->next ();
175
175
self ::assertNotSame ($ stackMiddleware , $ clonedStackTail , 'stackMiddleware was also cloned ' );
176
176
}
177
+
178
+ public function testClonedTraceableStackUsesSameStopwatch (): void
179
+ {
180
+ // import TraceableStack
181
+ class_exists (TraceableMiddleware::class);
182
+
183
+ $ middlewareIterable = [null , $ this ->createMock (MiddlewareInterface::class)];
184
+
185
+ $ stackMiddleware = new StackMiddleware ($ middlewareIterable );
186
+
187
+ $ stopwatch = $ this ->createMock (Stopwatch::class);
188
+ $ stopwatch ->expects ($ this ->exactly (2 ))->method ('isStarted ' )->willReturn (true );
189
+
190
+ $ startSeries = [
191
+ [$ this ->matches ('"%sMiddlewareInterface%s" on "command_bus" ' ), 'messenger.middleware ' ],
192
+ [$ this ->identicalTo ('Tail on "command_bus" ' ), 'messenger.middleware ' ],
193
+ [$ this ->matches ('"%sMiddlewareInterface%s" on "command_bus" ' ), 'messenger.middleware ' ],
194
+ [$ this ->identicalTo ('Tail on "command_bus" ' ), 'messenger.middleware ' ],
195
+ ];
196
+ $ stopwatch ->expects ($ this ->exactly (4 ))
197
+ ->method ('start ' )
198
+ ->willReturnCallback (function (string $ name , string $ category = null ) use (&$ startSeries ) {
199
+ [$ constraint , $ expectedCategory ] = array_shift ($ startSeries );
200
+
201
+ $ constraint ->evaluate ($ name );
202
+ $ this ->assertSame ($ expectedCategory , $ category );
203
+
204
+ return $ this ->createMock (StopwatchEvent::class);
205
+ })
206
+ ;
207
+
208
+ $ stopSeries = [
209
+ $ this ->matches ('"%sMiddlewareInterface%s" on "command_bus" ' ),
210
+ $ this ->matches ('"%sMiddlewareInterface%s" on "command_bus" ' ),
211
+ ];
212
+ $ stopwatch ->expects ($ this ->exactly (2 ))
213
+ ->method ('stop ' )
214
+ ->willReturnCallback (function (string $ name ) use (&$ stopSeries ) {
215
+ $ constraint = array_shift ($ stopSeries );
216
+ $ constraint ->evaluate ($ name );
217
+
218
+ return $ this ->createMock (StopwatchEvent::class);
219
+ })
220
+ ;
221
+
222
+ $ traceableStack = new TraceableStack ($ stackMiddleware , $ stopwatch , 'command_bus ' , 'messenger.middleware ' );
223
+ $ clonedStack = clone $ traceableStack ;
224
+
225
+ // unstack the stacks independently
226
+ $ traceableStack ->next ();
227
+ $ traceableStack ->next ();
228
+
229
+ $ clonedStack ->next ();
230
+ $ clonedStack ->next ();
231
+ }
177
232
}
0 commit comments