8000 Rename and refactor test to focus on unstacking the clone of Traceabl… · symfony/symfony@7ae895f · GitHub
[go: up one dir, main page]

Skip to content 10000

Commit 7ae895f

Browse files
committed
Rename and refactor test to focus on unstacking the clone of TraceableStack independently
Notes: - This test manually unstacks TraceableStack and it's clone instead of using a MessageBus, which is what StackMiddlewareTest::testClone() uses. I did this because MessageBus always dispatches with a new StackMiddleware(). I thought about using a custom MessageBus mock, however, I'm not sure if it's needed to test unstacking. - Removed stopwatch expects() as the stopwatch is not currently under test
1 parent dd8a3b3 commit 7ae895f

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,38 +142,36 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
142142
$this->assertSame(1, $middleware->calls);
143143
}
144144

145-
public function testCloneTraceableStack(): void
145+
public function testClonedTraceableStackUnstacksIndependently(): void
146146
{
147147
// import TraceableStack
148148
class_exists(TraceableMiddleware::class);
149149

150150
$stackMiddleware = new StackMiddleware([
151+
null,
151152
$this->createMock(MiddlewareInterface::class),
152153
$this->createMock(MiddlewareInterface::class),
153154
]);
154155

155156
$stopwatch = $this->createMock(Stopwatch::class);
156157

157-
$series = [
158-
[$this->matches('"%sMiddlewareInterface%s" on "command_bus"'), 'messenger.middleware'],
159-
[$this->matches('"%sMiddlewareInterface%s" on "command_bus"'), 'messenger.middleware'],
160-
];
161-
$stopwatch->expects($this->exactly(2))
162-
->method('start')
163-
->willReturnCallback(function (string $name, string $category = null) use (&$series) {
164-
[$constraint, $expectedCategory] = array_shift($series);
158+
$traceableStack = new TraceableStack($stackMiddleware, $stopwatch, 'command_bus', 'messenger.middleware');
159+
$clonedStack = clone $traceableStack;
165160

166-
$constraint->evaluate($name);
167-
$this->assertSame($expectedCategory, $category);
161+
$traceableStackMiddleware1 = $traceableStack->next();
162+
$traceableStackMiddleware2 = $traceableStack->next();
163+
$traceableStackTail = $traceableStack->next();
164+
self::assertSame($stackMiddleware, $traceableStackTail);
168165

169-
return $this->createMock(StopwatchEvent::class);
170-
})
171-
;
172-
$stopwatch->expects($this->never())->method('stop');
166+
// unstack clonedStack independently
167+
$clonedStackMiddleware1 = $clonedStack->next();
168+
self::assertSame($traceableStackMiddleware1, $clonedStackMiddleware1);
169+
self::assertNotSame($traceableStackMiddleware2, $clonedStackMiddleware1);
173170

174-
$traceableStack = new TraceableStack($stackMiddleware, $stopwatch, 'command_bus', 'messenger.middleware');
175-
$clonedStack = clone $traceableStack;
171+
$clonedStackMiddleware2 = $clonedStack->next();
172+
self::assertSame($traceableStackMiddleware2, $clonedStackMiddleware2);
176173

177-
self::assertSame($traceableStack->next(), $clonedStack->next());
174+
$clonedStackTail = $clonedStack->next();
175+
self::assertNotSame($stackMiddleware, $clonedStackTail, 'stackMiddleware was also cloned');
178176
}
179177
}

0 commit comments

Comments
 (0)
0