@@ -42,7 +42,7 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
42
42
};
43
43
44
44
$ stopwatch = $ this ->createMock (Stopwatch::class);
45
- $ stopwatch ->expects ($ this ->once ( ))->method ('isStarted ' )->willReturn (true );
45
+ $ stopwatch ->expects ($ this ->exactly ( 2 ))->method ('isStarted ' )->willReturn (true );
46
46
$ stopwatch ->expects ($ this ->exactly (2 ))
47
47
->method ('start ' )
48
48
->withConsecutive (
@@ -91,4 +91,36 @@ public function testHandleWithException()
91
91
$ traced = new TraceableMiddleware ($ stopwatch , $ busId );
92
92
$ traced ->handle (new Envelope (new DummyMessage ('Hello ' )), new StackMiddleware (new \ArrayIterator ([null , $ middleware ])));
93
93
}
94
+
95
+ public function testHandleWhenStopwatchHasBeenReset ()
96
+ {
97
+ $ busId = 'command_bus ' ;
98
+ $ envelope = new Envelope (new DummyMessage ('Hello ' ));
99
+
100
+ $ stopwatch = new Stopwatch ();
101
+
102
+ $ middleware = new class ($ stopwatch ) implements MiddlewareInterface {
103
+ public $ calls = 0 ;
104
+ private $ stopwatch ;
105
+
106
+ public function __construct (Stopwatch $ stopwatch )
107
+ {
108
+ $ this ->stopwatch = $ stopwatch ;
109
+ }
110
+
111
+ public function handle (Envelope $ envelope , StackInterface $ stack ): Envelope
112
+ {
113
+ $ this ->stopwatch ->reset ();
114
+
115
+ ++$ this ->calls ;
116
+
117
+ return $ stack ->next ()->handle ($ envelope , $ stack );
118
+ }
119
+ };
120
+
121
+ $ traced = new TraceableMiddleware ($ stopwatch , $ busId );
122
+
123
+ $ traced ->handle ($ envelope , new StackMiddleware (new \ArrayIterator ([null , $ middleware ])));
124
+ $ this ->assertSame (1 , $ middleware ->calls );
125
+ }
94
126
}
0 commit comments