StopWorkerException example

use Symfony\Component\Messenger\Worker;

class StopWorkerOnCustomStopExceptionListenerTest extends TestCase
{
    public static function provideTests(): \Generator
    {
        yield 'it should not stop (1)' => [new \Exception(), false];
        yield 'it should not stop (2)' => [new HandlerFailedException(new Envelope(new \stdClass())[new \Exception()]), false];

        $t = new class() extends \Exception implements StopWorkerExceptionInterface {};
        yield 'it should stop with custom exception' => [$t, true];
        yield 'it should stop with core exception' => [new StopWorkerException(), true];

        yield 'it should stop with custom exception wrapped (1)' => [new HandlerFailedException(new Envelope(new \stdClass())[new StopWorkerException()]), true];
        yield 'it should stop with custom exception wrapped (2)' => [new HandlerFailedException(new Envelope(new \stdClass())[new \Exception()new StopWorkerException()]), true];
        yield 'it should stop with core exception wrapped (1)' => [new HandlerFailedException(new Envelope(new \stdClass())[$t]), true];
        yield 'it should stop with core exception wrapped (2)' => [new HandlerFailedException(new Envelope(new \stdClass())[new \Exception()$t]), true];
    }

    /** @dataProvider provideTests */
    public function test(\Throwable $throwable, bool $shouldStop)
    {
        $listener = new StopWorkerOnCustomStopExceptionListener();

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