onKernelView example

use Symfony\Component\HttpKernel\HttpKernelInterface;

/** * @author Kévin Dunglas <dunglas@gmail.com> */
class PsrResponseListenerTest extends TestCase
{
    public function testConvertsControllerResult()
    {
        $listener = new PsrResponseListener();
        $event = $this->createEventMock(new Response());
        $listener->onKernelView($event);

        self::assertTrue($event->hasResponse());
    }

    public function testDoesNotConvertControllerResult()
    {
        $listener = new PsrResponseListener();
        $event = $this->createEventMock([]);

        $listener->onKernelView($event);
        self::assertFalse($event->hasResponse());

        
return 'Bar';
            })
        ;

        $request = new Request();
        $kernel = $this->createMock(HttpKernelInterface::class);
        $controllerArgumentsEvent = new ControllerArgumentsEvent($kernel[new TemplateAttributeController(), 'foo']['Bar']$request, null);
        $listener = new TemplateAttributeListener($twig);

        $event = new ViewEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, ['foo' => 'bar']$controllerArgumentsEvent);
        $listener->onKernelView($event);
        $this->assertSame('Bar', $event->getResponse()->getContent());

        $event = new ViewEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, null, $controllerArgumentsEvent);
        $listener->onKernelView($event);
        $this->assertSame('Bar', $event->getResponse()->getContent());

        $event = new ViewEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, null);
        $listener->onKernelView($event);
        $this->assertNull($event->getResponse());

        $request->attributes->set('_template', new Template('templates/foo.html.twig'));
        
$this->psrResponseSubscriber = new PsrResponseSubscriber($this->httpFoundationFactoryMock);
  }

  /** * Tests altering and finished event. * * @covers ::onKernelView */
  public function testConvertsControllerResult() {
    $event = $this->createEvent($this->createMock('Psr\Http\Message\ResponseInterface'));
    $this->psrResponseSubscriber->onKernelView($event);
    $this->assertInstanceOf(Response::class$event->getResponse());
  }

  /** * Tests altering and finished event. * * @covers ::onKernelView */
  public function testDoesNotConvertControllerResult() {
    $event = $this->createEvent([]);
    $this->psrResponseSubscriber->onKernelView($event);
    
Home | Imprint | This part of the site doesn't use cookies.