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));
}