onKernelException example



    /** * @dataProvider provider */
    public function testHandleWithoutLogger($event$event2)
    {
        $this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');

        $l = new ErrorListener('foo');
        $l->logKernelException($event);
        $l->onKernelException($event);

        $this->assertEquals(new Response('foo')$event->getResponse());

        try {
            $l->logKernelException($event2);
            $l->onKernelException($event2);
            $this->fail('RuntimeException expected');
        } catch (\RuntimeException $e) {
            $this->assertSame('bar', $e->getMessage());
            $this->assertSame('foo', $e->getPrevious()->getMessage());
        }
    }
$requestStack = new RequestStack();
        $requestStack->push($mainRequest);

        $onlyException = true;
        $listener = new ProfilerListener($profiler$requestStack, null, $onlyException);

        // main request         $listener->onKernelResponse(new ResponseEvent($kernel$mainRequest, Kernel::MAIN_REQUEST, $response));

        // sub request         $listener->onKernelException(new ExceptionEvent($kernel$subRequest, Kernel::SUB_REQUEST, new HttpException(404)));
        $listener->onKernelResponse(new ResponseEvent($kernel$subRequest, Kernel::SUB_REQUEST, $response));

        $listener->onKernelTerminate(new TerminateEvent($kernel$mainRequest$response));
    }

    /** * @dataProvider collectRequestProvider */
    public function testCollectParameter(Request $request, ?bool $enable)
    {
        $profile = new Profile('token');

        
class ExceptionListenerTest extends TestCase
{
    /** * @dataProvider getAuthenticationExceptionProvider */
    public function testAuthenticationExceptionWithoutEntryPoint(\Exception $exception, \Exception $eventException)
    {
        $event = $this->createEvent($exception);

        $listener = $this->createExceptionListener();
        $listener->onKernelException($event);

        $this->assertNull($event->getResponse());
        $this->assertEquals($eventException$event->getThrowable());
    }

    /** * @dataProvider getAuthenticationExceptionProvider */
    public function testAuthenticationExceptionWithEntryPoint(\Exception $exception)
    {
        $event = $this->createEvent($exception);

        
$this->authenticationTrustResolver = $trustResolver;
        $this->errorPage = $errorPage;
        $this->logger = $logger;
        $this->stateless = $stateless;
    }

    /** * Registers a onKernelException listener to take care of security exceptions. */
    public function register(EventDispatcherInterface $dispatcher): void
    {
        $dispatcher->addListener(KernelEvents::EXCEPTION, $this->onKernelException(...), 1);
    }

    /** * Unregisters the dispatcher. */
    public function unregister(EventDispatcherInterface $dispatcher): void
    {
        $dispatcher->removeListener(KernelEvents::EXCEPTION, $this->onKernelException(...));
    }

    /** * Handles security related exceptions. */
Home | Imprint | This part of the site doesn't use cookies.