[Messenger] Don't prevent dispatch out of another bus
This commit is contained in:
parent
9cd3e674e6
commit
1e8ae43372
@ -6,6 +6,7 @@ CHANGELOG
|
||||
|
||||
* Added `FlattenExceptionNormalizer` to give more information about the exception on Messenger background processes. The `FlattenExceptionNormalizer` has a higher priority than `ProblemNormalizer` and it is only used when the Messenger serialization context is set.
|
||||
* Added factory methods to `DelayStamp`.
|
||||
* Removed the exception when dispatching a message with a `DispatchAfterCurrentBusStamp` and not in a context of another dispatch call
|
||||
|
||||
5.1.0
|
||||
-----
|
||||
|
@ -44,12 +44,13 @@ class DispatchAfterCurrentBusMiddleware implements MiddlewareInterface
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
if (null !== $envelope->last(DispatchAfterCurrentBusStamp::class)) {
|
||||
if (!$this->isRootDispatchCallRunning) {
|
||||
throw new \LogicException(sprintf('You can only use a "%s" stamp in the context of a message handler.', DispatchAfterCurrentBusStamp::class));
|
||||
}
|
||||
$this->queue[] = new QueuedEnvelope($envelope, $stack);
|
||||
if ($this->isRootDispatchCallRunning) {
|
||||
$this->queue[] = new QueuedEnvelope($envelope, $stack);
|
||||
|
||||
return $envelope;
|
||||
return $envelope;
|
||||
}
|
||||
|
||||
$envelope = $envelope->withoutAll(DispatchAfterCurrentBusStamp::class);
|
||||
}
|
||||
|
||||
if ($this->isRootDispatchCallRunning) {
|
||||
|
@ -256,6 +256,28 @@ class DispatchAfterCurrentBusMiddlewareTest extends TestCase
|
||||
$messageBus->dispatch($message);
|
||||
}
|
||||
|
||||
public function testDispatchOutOfAnotherHandlerDispatchesAndRemoveStamp()
|
||||
{
|
||||
$event = new DummyEvent('First event');
|
||||
|
||||
$middleware = new DispatchAfterCurrentBusMiddleware();
|
||||
$handlingMiddleware = $this->createMock(MiddlewareInterface::class);
|
||||
|
||||
$handlingMiddleware
|
||||
->method('handle')
|
||||
->with($this->expectHandledMessage($event))
|
||||
->will($this->willHandleMessage());
|
||||
|
||||
$eventBus = new MessageBus([
|
||||
$middleware,
|
||||
$handlingMiddleware,
|
||||
]);
|
||||
|
||||
$enveloppe = $eventBus->dispatch($event, [new DispatchAfterCurrentBusStamp()]);
|
||||
|
||||
self::assertNull($enveloppe->last(DispatchAfterCurrentBusStamp::class));
|
||||
}
|
||||
|
||||
private function expectHandledMessage($message): Callback
|
||||
{
|
||||
return $this->callback(function (Envelope $envelope) use ($message) {
|
||||
|
Reference in New Issue
Block a user