8000 Test a cloned TraceableStack uses the same stopwatch as the original · symfony/symfony@859db92 · GitHub
[go: up one dir, main page]

Skip to content

Commit 859db92

Browse files
committed
Test a cloned TraceableStack uses the same stopwatch as the original
1 parent 7ae895f commit 859db92

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,59 @@ class_exists(TraceableMiddleware::class);
174174
$clonedStackTail = $clonedStack->next();
175175
self::assertNotSame($stackMiddleware, $clonedStackTail, 'stackMiddleware was also cloned');
176176
}
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+
}
177232
}

0 commit comments

Comments
 (0)
0