Skip to content

Commit

Permalink
Merge pull request #2410 from flohw/3.x
Browse files Browse the repository at this point in the history
fix: Sensio extra bundle TemplateListener invocation before view response listener and serialization
  • Loading branch information
goetas committed Apr 12, 2024
2 parents fa0f68b + 11e5491 commit db7d9a1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion EventListener/ViewResponseListener.php
Expand Up @@ -170,7 +170,7 @@ public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
KernelEvents::VIEW => ['onKernelView', -128],
KernelEvents::VIEW => ['onKernelView', 30],
];
}

Expand Down
Expand Up @@ -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];
}
}
8 changes: 8 additions & 0 deletions Tests/Functional/ViewResponseListenerTest.php
Expand Up @@ -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());
}
}
1 change: 1 addition & 0 deletions Tests/Functional/app/ViewResponseListener/bundles.php
Expand Up @@ -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(),
];
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -7,7 +7,7 @@
xsi:noNamespaceSchemaLocation=".phpunit/phpunit.xsd"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=104&amp;max[indirect]=243"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=120&amp;max[indirect]=243"/>
<env name="SYMFONY_PHPUNIT_VERSION" value="9.6"/>
<ini name="error_reporting" value="-1"/>
<server name="SHELL_VERBOSITY" value="-1"/>
Expand Down

0 comments on commit db7d9a1

Please sign in to comment.