AddErrorDetailsStampListener example

'alias' => 'handler_that_works2',
                ]),
            ],
        ]);

        $dispatcher = new EventDispatcher();
        $bus = new MessageBus([
            new FailedMessageProcessingMiddleware(),
            new SendMessageMiddleware($senderLocator),
            new HandleMessageMiddleware($handlerLocator),
        ]);
        $dispatcher->addSubscriber(new AddErrorDetailsStampListener());
        $dispatcher->addSubscriber(new SendFailedMessageForRetryListener($locator$retryStrategyLocator));

        $dispatcher->addSubscriber(new SendFailedMessageToFailureTransportListener($sendersLocatorFailureTransport));
        $dispatcher->addSubscriber(new StopWorkerOnMessageLimitListener(1));

        $runWorker = function Dstring $transportName) use ($transports$bus$dispatcher): ?\Throwable {
            $throwable = null;
            $failedListener = function DWorkerMessageFailedEvent $event) use (&$throwable) {
                $throwable = $event->getThrowable();
            };
            $dispatcher->addListener(WorkerMessageFailedEvent::class$failedListener);

            
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\EventListener\AddErrorDetailsStampListener;
use Symfony\Component\Messenger\Stamp\ErrorDetailsStamp;

final class AddErrorDetailsStampListenerTest extends TestCase
{
    public function testExceptionDetailsAreAdded()
    {
        $listener = new AddErrorDetailsStampListener();

        $envelope = new Envelope(new \stdClass());
        $exception = new \Exception('It failed!');
        $event = new WorkerMessageFailedEvent($envelope, 'my_receiver', $exception);
        $expectedStamp = ErrorDetailsStamp::create($exception);

        $listener->onMessageFailed($event);

        $this->assertEquals($expectedStamp$event->getEnvelope()->last(ErrorDetailsStamp::class));
    }

    
Home | Imprint | This part of the site doesn't use cookies.