diff --git a/EventListener/ViewResponseListener.php b/EventListener/ViewResponseListener.php index 89eee18ac..c20b2f5cd 100644 --- a/EventListener/ViewResponseListener.php +++ b/EventListener/ViewResponseListener.php @@ -170,7 +170,7 @@ public static function getSubscribedEvents(): array { return [ KernelEvents::CONTROLLER => 'onKernelController', - KernelEvents::VIEW => ['onKernelView', -128], + KernelEvents::VIEW => ['onKernelView', 30], ]; } diff --git a/Tests/Functional/Bundle/TestBundle/Controller/ArticleController.php b/Tests/Functional/Bundle/TestBundle/Controller/ArticleController.php index 1002f5e1e..8397f718d 100644 --- a/Tests/Functional/Bundle/TestBundle/Controller/ArticleController.php +++ b/Tests/Functional/Bundle/TestBundle/Controller/ArticleController.php @@ -32,14 +32,26 @@ public function cpostAction(Request $request) } /** - * @Get("/articles.{_format}", name="get_article", defaults={"_format": "html"}) + * @Get("/articles.{_format}", name="get_articles", defaults={"_format": "html"}) * * @View() */ - #[Get(path: '/articles.{_format}', name: 'get_article', defaults: ['_format' => 'html'])] + #[Get(path: '/articles.{_format}', name: 'get_articles', defaults: ['_format' => 'html'])] #[View] public function cgetAction() { return $this->view(); } + + /** + * @Get("/articles/{id}.{_format}", name="get_article", defaults={"_format": "html"}) + * + * @View() + */ + #[Get(path: '/articles/{id}.{_format}', name: 'get_article', defaults: ['_format' => 'html'])] + #[View] + public function cgetSingleAction(int $id) + { + return ['id' => $id]; + } } diff --git a/Tests/Functional/ViewResponseListenerTest.php b/Tests/Functional/ViewResponseListenerTest.php index afcbe7437..0ecd0bf95 100644 --- a/Tests/Functional/ViewResponseListenerTest.php +++ b/Tests/Functional/ViewResponseListenerTest.php @@ -35,4 +35,12 @@ public function testRedirect() $this->assertSame('http://localhost/hello/Post%201', $client->getResponse()->headers->get('location')); $this->assertStringNotContainsString('fooo', $client->getResponse()->getContent()); } + + public function testControllerReturnsView() + { + $client = $this->createClient(['test_case' => 'ViewResponseListener']); + $client->request('GET', '/articles.json'); + + $this->assertTrue($client->getResponse()->isSuccessful()); + } } diff --git a/Tests/Functional/app/ViewResponseListener/bundles.php b/Tests/Functional/app/ViewResponseListener/bundles.php index 90086464f..2a4b9abff 100644 --- a/Tests/Functional/app/ViewResponseListener/bundles.php +++ b/Tests/Functional/app/ViewResponseListener/bundles.php @@ -11,6 +11,7 @@ $bundles = [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new \Symfony\Bundle\TwigBundle\TwigBundle(), new \FOS\RestBundle\FOSRestBundle(), new \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\TestBundle(), ]; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 09dcaefda..b69cb791d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,7 @@ xsi:noNamespaceSchemaLocation=".phpunit/phpunit.xsd" > - +