Skip to content

Commit 389562f

Browse files
committed
Merge pull request #1376 from FriendsOfSymfony/FIX
Fix the TwigExceptionController
2 parents 4abeb42 + 9f8f7e9 commit 389562f

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

Controller/TemplatingExceptionController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public function __construct(
3535
* Finds the template for the given format and status code.
3636
*
3737
* @param Request $request
38-
* @param string $format
3938
* @param int $statusCode
4039
* @param bool $showException
4140
*
4241
* @return TemplateReferenceInterface
4342
*/
44-
abstract protected function findTemplate(Request $request, $format, $statusCode, $showException);
43+
abstract protected function findTemplate(Request $request, $statusCode, $showException);
4544
}

Controller/TwigExceptionController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TwigExceptionController extends TemplatingExceptionController
2626
protected function createView(\Exception $exception, $code, array $templateData, Request $request, $showException)
2727
{
2828
$view = parent::createView($exception, $code, $templateData, $request, $showException);
29-
$view->setTemplate($this->findTemplate($request, $format, $code, $showException));
29+
$view->setTemplate($this->findTemplate($request, $code, $showException));
3030

3131
return $view;
3232
}
@@ -37,8 +37,10 @@ protected function createView(\Exception $exception, $code, array $templateData,
3737
* This code is inspired by TwigBundle and should be synchronized on a regular basis
3838
* see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
3939
*/
40-
protected function findTemplate(Request $request, $format, $statusCode, $showException)
40+
protected function findTemplate(Request $request, $statusCode, $showException)
4141
{
42+
$format = $request->getRequestFormat();
43+
4244
$name = $showException ? 'exception' : 'error';
4345
if ($showException && 'html' == $format) {
4446
$name = 'exception_full';

DependencyInjection/FOSRestExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ private function loadException(array $config, XmlFileLoader $loader, ContainerBu
323323
}
324324

325325
$container->getDefinition('fos_rest.exception.controller')
326-
->replaceArgument(2, $config['exception']['codes']);
326+
->replaceArgument(1, $config['exception']['codes']);
327327
$container->getDefinition('fos_rest.serializer.exception_normalizer.jms')
328328
->replaceArgument(0, $config['exception']['messages']);
329329
$container->getDefinition('fos_rest.serializer.exception_normalizer.symfony')
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Tests\Functional;
13+
14+
/**
15+
* @author Ener-Getick <[email protected]>
16+
*/
17+
class ErrorWithTemplatingFormatTest extends WebTestCase
18+
{
19+
public function testSerializeExceptionHtml()
20+
{
21+
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
22+
23+
$client = $this->createClient(['test_case' => 'Serializer', 'debug' => false]);
24+
$client->request('GET', '/serializer-error/exception.html');
25+
26+
$this->assertContains('The server returned a "500 Internal Server Error".', $client->getResponse()->getContent());
27+
$this->assertNotContains('Something bad happened', $client->getResponse()->getContent());
28+
}
29+
30+
public function testSerializeExceptionHtmlInDebugMode()
31+
{
32+
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
33+
34+
$client = $this->createClient(['test_case' => 'Serializer', 'debug' => true]);
35+
$client->request('GET', '/serializer-error/exception.html');
36+
37+
$this->assertContains('Something bad happened. (500 Internal Server Error)', $client->getResponse()->getContent());
38+
}
39+
}

Tests/Functional/WebTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ protected static function createKernel(array $options = [])
4242
throw new \InvalidArgumentException('The option "test_case" must be set.');
4343
}
4444

45+
$debug = isset($options['debug']) ? $options['debug'] : true;
46+
4547
return new $class(
4648
$options['test_case'],
4749
isset($options['root_config']) ? $options['root_config'] : 'config.yml',
48-
isset($options['environment']) ? $options['environment'] : 'fosrestbundletest'.strtolower($options['test_case']),
49-
isset($options['debug']) ? $options['debug'] : true
50+
isset($options['environment']) ? $options['environment'] : 'fosrestbundletest'.strtolower($options['test_case']).(int) $debug,
51+
$debug
5052
);
5153
}
5254
}

Tests/Functional/app/Serializer/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
return [
1313
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
14+
new \Symfony\Bundle\TwigBundle\TwigBundle(),
1415
new \FOS\RestBundle\FOSRestBundle(),
1516
new \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\TestBundle(),
1617
];

Tests/Functional/app/Serializer/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ imports:
55
framework:
66
serializer:
77
enabled: true
8+
templating:
9+
engines: ['twig']
810

911
fos_rest:
1012
view:

0 commit comments

Comments
 (0)