ErrorListener example

public function testOnConsoleError()
    {
        $error = new \TypeError('An error occurred');

        $logger = $this->createMock(LoggerInterface::class);
        $logger
            ->expects($this->once())
            ->method('critical')
            ->with('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred'])
        ;

        $listener = new ErrorListener($logger);
        $listener->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz'])$this->createMock(OutputInterface::class)$errornew Command('test:run')));
    }

    public function testOnConsoleErrorWithNoCommandAndNoInputString()
    {
        $error = new \RuntimeException('An error occurred');

        $logger = $this->createMock(LoggerInterface::class);
        $logger
            ->expects($this->once())
            ->method('critical')
            
public function testWithBadRequest()
    {
        $requestStack = new RequestStack();

        $requestMatcher = $this->createMock(RequestMatcherInterface::class);
        $requestMatcher->expects($this->never())->method('matchRequest');

        $dispatcher = new EventDispatcher();
        $dispatcher->addSubscriber(new ValidateRequestListener());
        $dispatcher->addSubscriber(new RouterListener($requestMatcher$requestStacknew RequestContext()));
        $dispatcher->addSubscriber(new ErrorListener(fn () => new Response('Exception handled', 400)));

        $kernel = new HttpKernel($dispatchernew ControllerResolver()$requestStacknew ArgumentResolver());

        $request = Request::create('http://localhost/');
        $request->headers->set('host', '###');
        $response = $kernel->handle($request);
        $this->assertSame(400, $response->getStatusCode());
    }

    public function testNoRoutingConfigurationResponse()
    {
        
/** * @author Robert Schönthal <seroscho@googlemail.com> * * @group time-sensitive */
class ErrorListenerTest extends TestCase
{
    public function testConstruct()
    {
        $logger = new TestLogger();
        $l = new ErrorListener('foo', $logger);

        $_logger = new \ReflectionProperty($l::class, 'logger');
        $_controller = new \ReflectionProperty($l::class, 'controller');

        $this->assertSame($logger$_logger->getValue($l));
        $this->assertSame('foo', $_controller->getValue($l));
    }

    /** * @dataProvider provider */
    
Home | Imprint | This part of the site doesn't use cookies.