From 5b4e4420db4f6029becc0e30ed6fe8fe78152800 Mon Sep 17 00:00:00 2001 From: Flohw Date: Tue, 9 Apr 2024 08:43:17 +0200 Subject: [PATCH 1/5] Add TwigBundle to be able to trigger error --- Tests/Functional/app/ViewResponseListener/bundles.php | 1 + 1 file changed, 1 insertion(+) 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(), ]; From 68d9747378bacf28967fb453200c9593eb5a621a Mon Sep 17 00:00:00 2001 From: Flohw Date: Tue, 9 Apr 2024 08:45:22 +0200 Subject: [PATCH 2/5] Create new endpoint fixture to test if view response listener is called before template as it should --- .../TestBundle/Controller/ArticleController.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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]; + } } From e0927f60dc32e1ceaa21e8c3c6d94241649d09b8 Mon Sep 17 00:00:00 2001 From: Flohw Date: Tue, 9 Apr 2024 08:49:28 +0200 Subject: [PATCH 3/5] Revert view response listener to a value higher than Sensios TemplateListener --- EventListener/ViewResponseListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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], ]; } From 30d97dc175924c6067a7c12a7c33bad985e4fbf5 Mon Sep 17 00:00:00 2001 From: Flohw Date: Wed, 10 Apr 2024 08:43:36 +0200 Subject: [PATCH 4/5] Add functional test on controller --- Tests/Functional/ViewResponseListenerTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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()); + } } From 11e549151ada8f6954a175d374ab1269ceb4359e Mon Sep 17 00:00:00 2001 From: Flohw Date: Wed, 10 Apr 2024 08:44:01 +0200 Subject: [PATCH 5/5] Update max deprecation allowed --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" > - +