From bf0c24a6343c01873a8c63ad4d29157e39cf6159 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Mon, 22 Jul 2019 13:18:46 -0400 Subject: [PATCH] Deprecating error templates for non-html formats and using ErrorRenderer --- UPGRADE-4.4.md | 68 +++++++++++ UPGRADE-5.0.md | 2 + .../Tests/Functional/app/Fragment/config.yml | 1 + .../Bundle/FrameworkBundle/composer.json | 3 +- .../Tests/Functional/JsonLoginTest.php | 2 +- .../Functional/app/ExceptionController.php | 37 ++++++ .../Functional/app/JsonLoginLdap/bundles.php | 1 - .../Functional/app/JsonLoginLdap/config.yml | 2 +- .../Functional/app/SecurityHelper/bundles.php | 2 - .../Functional/app/SecurityHelper/config.yml | 2 +- .../Tests/Functional/app/config/twig.yml | 1 + .../Bundle/SecurityBundle/composer.json | 10 +- src/Symfony/Bundle/TwigBundle/CHANGELOG.md | 3 + .../Controller/ExceptionController.php | 4 + .../Controller/PreviewErrorController.php | 12 +- .../DependencyInjection/Configuration.php | 8 +- .../ErrorRenderer/TwigHtmlErrorRenderer.php | 111 ++++++++++++++++++ .../TwigBundle/Resources/config/twig.xml | 9 ++ .../Resources/views/Exception/error.atom.twig | 1 + .../Resources/views/Exception/error.css.twig | 1 + .../Resources/views/Exception/error.html.twig | 3 + .../Resources/views/Exception/error.js.twig | 1 + .../Resources/views/Exception/error.json.twig | 1 + .../Resources/views/Exception/error.rdf.twig | 1 + .../Resources/views/Exception/error.txt.twig | 1 + .../Resources/views/Exception/error.xml.twig | 1 + .../views/Exception/exception.atom.twig | 1 + .../views/Exception/exception.css.twig | 1 + .../views/Exception/exception.js.twig | 1 + .../views/Exception/exception.json.twig | 1 + .../views/Exception/exception.rdf.twig | 1 + .../views/Exception/exception.txt.twig | 1 + .../views/Exception/exception.xml.twig | 1 + .../Resources/views/Exception/traces.xml.twig | 1 + .../Resources/views/base_js.html.twig | 1 + .../Resources/views/exception.css.twig | 1 + .../Resources/views/layout.html.twig | 1 + .../Controller/ExceptionControllerTest.php | 3 + .../DependencyInjection/ConfigurationTest.php | 15 +++ .../php/customTemplateEscapingGuesser.php | 1 + .../Fixtures/php/empty.php | 1 + .../Fixtures/php/formats.php | 1 + .../DependencyInjection/Fixtures/php/full.php | 1 + .../xml/customTemplateEscapingGuesser.xml | 2 +- .../Fixtures/xml/empty.xml | 2 +- .../Fixtures/xml/extra.xml | 2 +- .../Fixtures/xml/formats.xml | 2 +- .../DependencyInjection/Fixtures/xml/full.xml | 2 +- .../yml/customTemplateEscapingGuesser.yml | 1 + .../Fixtures/yml/empty.yml | 1 + .../Fixtures/yml/extra.yml | 1 + .../Fixtures/yml/formats.yml | 1 + .../DependencyInjection/Fixtures/yml/full.yml | 1 + .../DependencyInjection/TwigExtensionTest.php | 4 + .../TwigHtmlErrorRendererTest.php | 73 ++++++++++++ .../Tests/Functional/CacheWarmingTest.php | 1 + .../Tests/Functional/EmptyAppTest.php | 15 ++- .../Functional/NoTemplatingEntryTest.php | 1 + 58 files changed, 404 insertions(+), 26 deletions(-) create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ExceptionController.php create mode 100644 src/Symfony/Bundle/TwigBundle/ErrorRenderer/TwigHtmlErrorRenderer.php create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/ErrorRenderer/TwigHtmlErrorRendererTest.php diff --git a/UPGRADE-4.4.md b/UPGRADE-4.4.md index 492591a5d4..8561391dc9 100644 --- a/UPGRADE-4.4.md +++ b/UPGRADE-4.4.md @@ -151,6 +151,74 @@ TwigBridge * Deprecated to pass `$rootDir` and `$fileLinkFormatter` as 5th and 6th argument respectively to the `DebugCommand::__construct()` method, swap the variables position. + +TwigBundle +---------- + + * Deprecated default value `twig.controller.exception::showAction` of the `twig.exception_controller` configuration option, + set it to `null` instead. This will also change the default error response format according to https://tools.ietf.org/html/rfc7807 + for `json`, `xml`, `atom` and `txt` formats: + + Before: + ```json + { + "error": { + "code": 404, + "message": "Sorry, the page you are looking for could not be found" + } + } + ``` + + After: + ```json + { + "title": "Not Found", + "status": 404, + "detail": "Sorry, the page you are looking for could not be found" + } + ``` + + * Deprecated the `ExceptionController` and all built-in error templates, use the error renderer mechanism of the `ErrorRenderer` component + * Deprecated loading custom error templates in non-html formats. Custom HTML error pages based on Twig keep working as before: + + Before (`templates/bundles/TwigBundle/Exception/error.jsonld.twig`): + ```twig + { + "@id": "https://example.com", + "@type": "error", + "@context": { + "title": "{{ status_text }}", + "code": {{ status_code }}, + "message": "{{ exception.message }}" + } + } + ``` + + After (`App\ErrorRenderer\JsonLdErrorRenderer`): + ```php + class JsonLdErrorRenderer implements ErrorRendererInterface + { + public static function getFormat(): string + { + return 'jsonld'; + } + + public function render(FlattenException $exception): string + { + return json_encode([ + '@id' => 'https://example.com', + '@type' => 'error', + '@context' => [ + 'title' => $exception->getTitle(), + 'code' => $exception->getStatusCode(), + 'message' => $exception->getMessage(), + ], + ]); + } + } + ``` + + Configure your rendering service tagging it with `error_renderer.renderer`. Validator --------- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index ce0ad3e656..615ec93ac7 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -467,6 +467,8 @@ TwigBundle * The default value (`false`) of the `twig.strict_variables` configuration option has been changed to `%kernel.debug%`. * The `transchoice` tag and filter have been removed, use the `trans` ones instead with a `%count%` parameter. * Removed support for legacy templates directories `src/Resources/views/` and `src/Resources//views/`, use `templates/` and `templates/bundles//` instead. + * The default value (`twig.controller.exception::showAction`) of the `twig.exception_controller` configuration option has been changed to `null`. + * Removed `ExceptionController` class and all built-in error templates TwigBridge ---------- diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/config.yml index 16fc81dd26..f48b4444fb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/config.yml @@ -7,3 +7,4 @@ framework: twig: strict_variables: '%kernel.debug%' + exception_controller: ~ diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 927f153c3b..3c4f7f0b0b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -52,7 +52,7 @@ "symfony/stopwatch": "^3.4|^4.0|^5.0", "symfony/translation": "^4.3|^5.0", "symfony/templating": "^3.4|^4.0|^5.0", - "symfony/twig-bundle": "^3.4|^4.0|^5.0", + "symfony/twig-bundle": "^4.4|^5.0", "symfony/validator": "^4.1|^5.0", "symfony/var-dumper": "^4.3|^5.0", "symfony/workflow": "^4.3|^5.0", @@ -80,6 +80,7 @@ "symfony/stopwatch": "<3.4", "symfony/translation": "<4.3", "symfony/twig-bridge": "<4.1.1", + "symfony/twig-bundle": "<4.4", "symfony/validator": "<4.1", "symfony/workflow": "<4.3" }, diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php index 2859693a17..908f7ce14f 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php @@ -70,6 +70,6 @@ class JsonLoginTest extends AbstractWebTestCase $this->assertSame(400, $response->getStatusCode()); $this->assertSame('application/json', $response->headers->get('Content-Type')); - $this->assertArraySubset(['error' => ['code' => 400, 'message' => 'Bad Request']], json_decode($response->getContent(), true)); + $this->assertArraySubset(['title' => 'Bad Request', 'status' => 400, 'detail' => 'Invalid JSON.'], json_decode($response->getContent(), true)); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ExceptionController.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ExceptionController.php new file mode 100644 index 0000000000..7a22a599b7 --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ExceptionController.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Tests\Functional\app; + +use Symfony\Component\ErrorRenderer\ErrorRenderer; +use Symfony\Component\ErrorRenderer\ErrorRenderer\HtmlErrorRenderer; +use Symfony\Component\ErrorRenderer\ErrorRenderer\JsonErrorRenderer; +use Symfony\Component\ErrorRenderer\Exception\FlattenException; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +class ExceptionController +{ + private $errorRenderer; + + public function __construct() + { + $this->errorRenderer = new ErrorRenderer([ + new HtmlErrorRenderer(), + new JsonErrorRenderer(), + ]); + } + + public function __invoke(Request $request, FlattenException $exception) + { + return new Response($this->errorRenderer->render($exception, $request->getPreferredFormat()), $exception->getStatusCode()); + } +} diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/bundles.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/bundles.php index e3aef52a2e..bcfd17425c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/bundles.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/bundles.php @@ -12,5 +12,4 @@ return [ new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), - new Symfony\Bundle\TwigBundle\TwigBundle(), ]; diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/config.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/config.yml index 622ec0f3eb..80d5ec570e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/config.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLoginLdap/config.yml @@ -1,5 +1,5 @@ imports: - - { resource: ./../config/default.yml } + - { resource: ./../config/framework.yml } services: Symfony\Component\Ldap\Ldap: arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter'] diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/bundles.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/bundles.php index 181618ba99..9a26fb163a 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/bundles.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/bundles.php @@ -11,10 +11,8 @@ use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle; -use Symfony\Bundle\TwigBundle\TwigBundle; return [ new FrameworkBundle(), new SecurityBundle(), - new TwigBundle(), ]; diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/config.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/config.yml index d7b8ac97d9..e49a697e52 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/config.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/SecurityHelper/config.yml @@ -1,5 +1,5 @@ imports: - - { resource: ./../config/default.yml } + - { resource: ./../config/framework.yml } services: # alias the service so we can access it in the tests diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/twig.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/twig.yml index 493989866a..e53084cda7 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/twig.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/twig.yml @@ -2,3 +2,4 @@ twig: debug: '%kernel.debug%' strict_variables: '%kernel.debug%' + exception_controller: Symfony\Bundle\SecurityBundle\Tests\Functional\app\ExceptionController diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index f019a09d95..b31b1de8ca 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -20,7 +20,7 @@ "ext-xml": "*", "symfony/config": "^4.2|^5.0", "symfony/dependency-injection": "^4.2|^5.0", - "symfony/http-kernel": "^4.3", + "symfony/http-kernel": "^4.4", "symfony/security-core": "^4.3", "symfony/security-csrf": "^4.2|^5.0", "symfony/security-guard": "^4.2|^5.0", @@ -33,10 +33,10 @@ "symfony/css-selector": "^3.4|^4.0|^5.0", "symfony/dom-crawler": "^3.4|^4.0|^5.0", "symfony/form": "^3.4|^4.0|^5.0", - "symfony/framework-bundle": "^4.2|^5.0", + "symfony/framework-bundle": "^4.4|^5.0", "symfony/http-foundation": "^3.4|^4.0|^5.0", "symfony/translation": "^3.4|^4.0|^5.0", - "symfony/twig-bundle": "^4.2|^5.0", + "symfony/twig-bundle": "^4.4|^5.0", "symfony/twig-bridge": "^3.4|^4.0|^5.0", "symfony/process": "^3.4|^4.0|^5.0", "symfony/validator": "^3.4|^4.0|^5.0", @@ -48,9 +48,9 @@ }, "conflict": { "symfony/browser-kit": "<4.2", - "symfony/twig-bundle": "<4.2", + "symfony/twig-bundle": "<4.4", "symfony/var-dumper": "<3.4", - "symfony/framework-bundle": "<4.2", + "symfony/framework-bundle": "<4.4", "symfony/console": "<3.4" }, "autoload": { diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index 65b7f4b913..eb1f93246a 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -6,6 +6,9 @@ CHANGELOG * marked the `TemplateIterator` as `internal` * added HTML comment to beginning and end of `exception_full.html.twig` + * added a new `TwigHtmlErrorRenderer` for `html` format, integrated with the `ErrorRenderer` component + * deprecated `ExceptionController` class and all built-in error templates in favor of the new error renderer mechanism + * deprecated default value `twig.controller.exception::showAction` of `twig.exception_controller` configuration option, set it to `null` instead 4.2.0 ----- diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php index e1d7760826..f8fa000d2b 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -19,12 +19,16 @@ use Twig\Environment; use Twig\Error\LoaderError; use Twig\Loader\ExistsLoaderInterface; +@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use the ErrorRenderer component instead.', ExceptionController::class), E_USER_DEPRECATED); + /** * ExceptionController renders error or exception pages for a given * FlattenException. * * @author Fabien Potencier * @author Matthias Pigulla + * + * @deprecated since Symfony 4.4, use the ErrorRenderer component instead. */ class ExceptionController { diff --git a/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php b/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php index 80c79f45ee..bc15a968e9 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php @@ -11,8 +11,10 @@ namespace Symfony\Bundle\TwigBundle\Controller; +use Symfony\Component\ErrorRenderer\ErrorRenderer; use Symfony\Component\ErrorRenderer\Exception\FlattenException; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -26,16 +28,22 @@ class PreviewErrorController { protected $kernel; protected $controller; + private $errorRenderer; - public function __construct(HttpKernelInterface $kernel, $controller) + public function __construct(HttpKernelInterface $kernel, $controller, ErrorRenderer $errorRenderer = null) { $this->kernel = $kernel; $this->controller = $controller; + $this->errorRenderer = $errorRenderer; } public function previewErrorPageAction(Request $request, $code) { - $exception = FlattenException::createFromThrowable(new \Exception('Something has intentionally gone wrong.'), $code); + $exception = FlattenException::createFromThrowable(new \Exception('Something has intentionally gone wrong.'), $code, ['X-Debug' => false]); + + if (null === $this->controller && null !== $this->errorRenderer) { + return new Response($this->errorRenderer->render($exception, $request->getPreferredFormat()), $code); + } /* * This Request mimics the parameters set by diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index b635a752ab..ebbf8d3d32 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -34,7 +34,13 @@ class Configuration implements ConfigurationInterface $rootNode ->children() - ->scalarNode('exception_controller')->defaultValue('twig.controller.exception::showAction')->end() + ->scalarNode('exception_controller') + ->defaultValue(static function () { + @trigger_error('Relying on the default value ("twig.controller.exception::showAction") of the "twig.exception_controller" configuration option is deprecated since Symfony 4.4, set it to "null" explicitly instead, which will be the new default in 5.0.', E_USER_DEPRECATED); + + return 'twig.controller.exception::showAction'; + }) + ->end() ->end() ; diff --git a/src/Symfony/Bundle/TwigBundle/ErrorRenderer/TwigHtmlErrorRenderer.php b/src/Symfony/Bundle/TwigBundle/ErrorRenderer/TwigHtmlErrorRenderer.php new file mode 100644 index 0000000000..b9c876a273 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/ErrorRenderer/TwigHtmlErrorRenderer.php @@ -0,0 +1,111 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\ErrorRenderer; + +use Symfony\Component\ErrorRenderer\ErrorRenderer\ErrorRendererInterface; +use Symfony\Component\ErrorRenderer\ErrorRenderer\HtmlErrorRenderer; +use Symfony\Component\ErrorRenderer\Exception\FlattenException; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; + +/** + * Provides the ability to render custom Twig-based HTML error pages + * in non-debug mode, otherwise falls back to HtmlErrorRenderer. + * + * @author Yonel Ceruto + */ +class TwigHtmlErrorRenderer implements ErrorRendererInterface +{ + private $twig; + private $htmlErrorRenderer; + private $debug; + + public function __construct(Environment $twig, HtmlErrorRenderer $htmlErrorRenderer, bool $debug = false) + { + $this->twig = $twig; + $this->htmlErrorRenderer = $htmlErrorRenderer; + $this->debug = $debug; + } + + /** + * {@inheritdoc} + */ + public static function getFormat(): string + { + return 'html'; + } + + /** + * {@inheritdoc} + */ + public function render(FlattenException $exception): string + { + $debug = $this->debug && ($exception->getHeaders()['X-Debug'] ?? true); + + if ($debug) { + return $this->htmlErrorRenderer->render($exception); + } + + $template = $this->findTemplate($exception->getStatusCode()); + + if (null === $template) { + return $this->htmlErrorRenderer->render($exception); + } + + return $this->twig->render($template, [ + 'legacy' => false, // to be removed in 5.0 + 'exception' => $exception, + 'status_code' => $exception->getStatusCode(), + 'status_text' => $exception->getTitle(), + ]); + } + + private function findTemplate(int $statusCode): ?string + { + $template = sprintf('@Twig/Exception/error%s.html.twig', $statusCode); + if ($this->templateExists($template)) { + return $template; + } + + $template = '@Twig/Exception/error.html.twig'; + if ($this->templateExists($template)) { + return $template; + } + + return null; + } + + /** + * To be removed in 5.0. + * + * Use instead: + * + * $this->twig->getLoader()->exists($template) + */ + private function templateExists(string $template): bool + { + $loader = $this->twig->getLoader(); + if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) { + return $loader->exists($template); + } + + try { + $loader->getSourceContext($template); + + return true; + } catch (LoaderError $e) { + } + + return false; + } +} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 684a688731..52723177a1 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -139,11 +139,13 @@ %kernel.debug% + The "%service_id%" service is deprecated since Symfony 4.4. %twig.exception_listener.controller% + @@ -158,5 +160,12 @@ + + + + + + %kernel.debug% + diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.atom.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.atom.twig index 25c84a6c9b..8a9de15c2b 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.atom.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.atom.twig @@ -1 +1,2 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {{ include('@Twig/Exception/error.xml.twig') }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.css.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.css.twig index d8a9369487..f2816dc8d9 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.css.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.css.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} /* {{ status_code }} {{ status_text }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig index 01fab3ad08..75c3789510 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig @@ -1,3 +1,6 @@ +{% if legacy is not defined or legacy %} + {% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} +{% endif %} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.js.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.js.twig index d8a9369487..f2816dc8d9 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.js.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.js.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} /* {{ status_code }} {{ status_text }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.json.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.json.twig index fc19fd83bb..a675a5620d 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.json.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.json.twig @@ -1 +1,2 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {{ { 'error': { 'code': status_code, 'message': status_text } }|json_encode|raw }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.rdf.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.rdf.twig index 25c84a6c9b..8a9de15c2b 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.rdf.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.rdf.twig @@ -1 +1,2 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {{ include('@Twig/Exception/error.xml.twig') }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.txt.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.txt.twig index bec5b1e302..66ddee0048 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.txt.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.txt.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} Oops! An Error Occurred ======================= diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.xml.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.xml.twig index 5ea8f565ab..5b38858eec 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.xml.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.xml.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.atom.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.atom.twig index 2cdf03f2bc..ec921b9620 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.atom.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.atom.twig @@ -1 +1,2 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {{ include('@Twig/Exception/exception.xml.twig', { exception: exception }) }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.css.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.css.twig index 593d490257..cec0e16f66 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.css.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.css.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} /* {{ include('@Twig/Exception/exception.txt.twig', { exception: exception }) }} */ diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.js.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.js.twig index 593d490257..cec0e16f66 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.js.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.js.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} /* {{ include('@Twig/Exception/exception.txt.twig', { exception: exception }) }} */ diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.json.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.json.twig index 13a41476f2..9b87e74fd0 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.json.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.json.twig @@ -1 +1,2 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {{ { 'error': { 'code': status_code, 'message': status_text, 'exception': exception.toarray } }|json_encode|raw }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.rdf.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.rdf.twig index 2cdf03f2bc..ec921b9620 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.rdf.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.rdf.twig @@ -1 +1,2 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {{ include('@Twig/Exception/exception.xml.twig', { exception: exception }) }} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.txt.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.txt.twig index cb17fb149f..bcc15b7c32 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.txt.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.txt.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} [exception] {{ status_code ~ ' | ' ~ status_text ~ ' | ' ~ exception.class }} [message] {{ exception.message }} {% for i, e in exception.toarray %} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.xml.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.xml.twig index 36c9449b6c..27e95641cf 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.xml.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception.xml.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/traces.xml.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/traces.xml.twig index ae46775925..bbab90432b 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/traces.xml.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/traces.xml.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {% for trace in exception.trace %} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig index c510a13e66..746ba46608 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig @@ -1,3 +1,4 @@ +{% deprecated 'The template "' ~ _self ~'" is deprecated since Symfony 4.4, will be removed in 5.0.' %} {# This file is based on WebProfilerBundle/Resources/views/Profiler/base_js.html.twig. If you make any change in this file, verify the same change is needed in the other file. #} /* diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php index ee7c20746a..4e48df0aeb 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php @@ -18,6 +18,9 @@ use Symfony\Component\HttpFoundation\Request; use Twig\Environment; use Twig\Loader\ArrayLoader; +/** + * @group legacy + */ class ExceptionControllerTest extends TestCase { public function testShowActionCanBeForcedToShowErrorPage() diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php index e479804b98..33300336d1 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -21,6 +21,7 @@ class ConfigurationTest extends TestCase { $input = [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default 'form_themes' => ['form_div_layout.html.twig'], ]; @@ -42,10 +43,23 @@ class ConfigurationTest extends TestCase $this->assertFalse($config['strict_variables']); } + /** + * @group legacy + * @expectedDeprecation Relying on the default value ("twig.controller.exception::showAction") of the "twig.exception_controller" configuration option is deprecated since Symfony 4.4, set it to "null" explicitly instead, which will be the new default in 5.0. + */ + public function testGetExceptionControllerDefault() + { + $processor = new Processor(); + $config = $processor->processConfiguration(new Configuration(), [[]]); + + $this->assertSame('twig.controller.exception::showAction', $config['exception_controller']); + } + public function testGlobalsAreNotNormalized() { $input = [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default 'globals' => ['some-global' => true], ]; @@ -59,6 +73,7 @@ class ConfigurationTest extends TestCase { $input = [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default 'globals' => ['global' => ['some-key' => 'some-value']], ]; diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php index de55467d22..481f57cdc5 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php @@ -4,4 +4,5 @@ $container->loadFromExtension('twig', [ 'autoescape_service' => 'my_project.some_bundle.template_escaping_guesser', 'autoescape_service_method' => 'guess', 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default ]); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/empty.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/empty.php index 76e66160f5..e4d9638c52 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/empty.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/empty.php @@ -2,4 +2,5 @@ $container->loadFromExtension('twig', [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default ]); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/formats.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/formats.php index 69fbf7c012..907217bf40 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/formats.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/formats.php @@ -12,4 +12,5 @@ $container->loadFromExtension('twig', [ 'thousands_separator' => '.', ], 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default ]); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php index 8dd2be4096..5356e44347 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -17,6 +17,7 @@ $container->loadFromExtension('twig', [ 'charset' => 'ISO-8859-1', 'debug' => true, 'strict_variables' => true, + 'exception_controller' => null, 'default_path' => '%kernel.project_dir%/Fixtures/templates', 'paths' => [ 'path1', diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml index 63c851720c..5d2558467b 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml @@ -6,5 +6,5 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/empty.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/empty.xml index ffe2f52577..0affe9386c 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/empty.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/empty.xml @@ -6,5 +6,5 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml index 17bcf0acd4..f95f052104 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/extra.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + namespaced_path3 diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/formats.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/formats.xml index 7f8fb84357..c14a971998 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/formats.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/formats.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 8ece3b80b7..6652301347 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig https://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + MyBundle::form.html.twig @@qux diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml index 34e301c095..de2c45759c 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml @@ -2,3 +2,4 @@ twig: autoescape_service: my_project.some_bundle.template_escaping_guesser autoescape_service_method: guess strict_variables: false # to be removed in 5.0 relying on default + exception_controller: ~ # to be removed in 5.0 relying on default diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/empty.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/empty.yml index 9b5dbcf35b..e66cce0953 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/empty.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/empty.yml @@ -1,2 +1,3 @@ twig: strict_variables: false # to be removed in 5.0 relying on default + exception_controller: ~ # to be removed in 5.0 relying on default diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/extra.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/extra.yml index 41a281cc81..7a7cbae6b1 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/extra.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/extra.yml @@ -1,4 +1,5 @@ twig: strict_variables: false # to be removed in 5.0 relying on default + exception_controller: ~ # to be removed in 5.0 relying on default paths: namespaced_path3: namespace3 diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/formats.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/formats.yml index a5c57f383e..b54e50aea1 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/formats.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/formats.yml @@ -1,5 +1,6 @@ twig: strict_variables: false # to be removed in 5.0 relying on default + exception_controller: ~ # to be removed in 5.0 relying on default date: format: Y-m-d interval_format: '%d' diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 24c10c23fe..0c28f04878 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -14,6 +14,7 @@ twig: debug: true strict_variables: true default_path: '%kernel.project_dir%/Fixtures/templates' + exception_controller: ~ # to be removed in 5.0 relying on default paths: path1: '' path2: '' diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index f3c0bc8503..bba6d41f89 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -31,6 +31,7 @@ class TwigExtensionTest extends TestCase $container->registerExtension(new TwigExtension()); $container->loadFromExtension('twig', [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default ]); $this->compileContainer($container); @@ -156,6 +157,7 @@ class TwigExtensionTest extends TestCase $container->loadFromExtension('twig', [ 'globals' => $globals, 'strict_variables' => false, // // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default ]); $this->compileContainer($container); @@ -259,6 +261,7 @@ class TwigExtensionTest extends TestCase $container->registerExtension(new TwigExtension()); $container->loadFromExtension('twig', [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default ]); $container->setAlias('test.twig.extension.debug.stopwatch', 'twig.extension.debug.stopwatch')->setPublic(true); $this->compileContainer($container); @@ -289,6 +292,7 @@ class TwigExtensionTest extends TestCase $container->registerExtension(new TwigExtension()); $container->loadFromExtension('twig', [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default ]); $container->setParameter('kernel.environment', 'test'); $container->setParameter('debug.file_link_format', 'test'); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/ErrorRenderer/TwigHtmlErrorRendererTest.php b/src/Symfony/Bundle/TwigBundle/Tests/ErrorRenderer/TwigHtmlErrorRendererTest.php new file mode 100644 index 0000000000..fa04d363ca --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/ErrorRenderer/TwigHtmlErrorRendererTest.php @@ -0,0 +1,73 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\Tests\ErrorRenderer; + +use PHPUnit\Framework\TestCase; +use Symfony\Bundle\TwigBundle\ErrorRenderer\TwigHtmlErrorRenderer; +use Symfony\Component\ErrorRenderer\ErrorRenderer\HtmlErrorRenderer; +use Symfony\Component\ErrorRenderer\Exception\FlattenException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Twig\Environment; +use Twig\Loader\ArrayLoader; + +class TwigHtmlErrorRendererTest extends TestCase +{ + public function testFallbackToNativeRendererIfDebugOn() + { + $exception = FlattenException::createFromThrowable(new \Exception()); + + $twig = $this->createMock(Environment::class); + $nativeRenderer = $this->createMock(HtmlErrorRenderer::class); + $nativeRenderer + ->expects($this->once()) + ->method('render') + ->with($exception) + ; + + (new TwigHtmlErrorRenderer($twig, $nativeRenderer, true))->render($exception); + } + + public function testFallbackToNativeRendererIfCustomTemplateNotFound() + { + $exception = FlattenException::createFromThrowable(new NotFoundHttpException()); + + $twig = new Environment(new ArrayLoader([])); + + $nativeRenderer = $this->createMock(HtmlErrorRenderer::class); + $nativeRenderer + ->expects($this->once()) + ->method('render') + ->with($exception) + ; + + (new TwigHtmlErrorRenderer($twig, $nativeRenderer, false))->render($exception); + } + + public function testRenderCustomErrorTemplate() + { + $exception = FlattenException::createFromThrowable(new NotFoundHttpException()); + + $twig = new Environment(new ArrayLoader([ + '@Twig/Exception/error404.html.twig' => '

Page Not Found

', + ])); + + $nativeRenderer = $this->createMock(HtmlErrorRenderer::class); + $nativeRenderer + ->expects($this->never()) + ->method('render') + ; + + $content = (new TwigHtmlErrorRenderer($twig, $nativeRenderer, false))->render($exception); + + $this->assertSame('

Page Not Found

', $content); + } +} diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php index ca21df0902..a9c8737e23 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php @@ -99,6 +99,7 @@ class CacheWarmingKernel extends Kernel ]) ->loadFromExtension('twig', [ // to be removed in 5.0 relying on default 'strict_variables' => false, + 'exception_controller' => null, ]) ; }); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php index df90b23752..d2a3ab68f9 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php @@ -14,6 +14,8 @@ namespace Symfony\Bundle\TwigBundle\Tests\Functional; use Symfony\Bundle\TwigBundle\Tests\TestCase; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\ErrorRenderer\ErrorRenderer; use Symfony\Component\HttpKernel\Kernel; class EmptyAppTest extends TestCase @@ -37,12 +39,13 @@ class EmptyAppKernel extends Kernel public function registerContainerConfiguration(LoaderInterface $loader) { - $loader->load(function ($container) { - $container - ->loadFromExtension('twig', [ // to be removed in 5.0 relying on default - 'strict_variables' => false, - ]) - ; + $loader->load(static function (ContainerBuilder $container) { + $container->loadFromExtension('twig', [ // to be removed in 5.0 relying on default + 'strict_variables' => false, + 'exception_controller' => null, + ]); + $container->register('error_renderer', ErrorRenderer::class); + $container->setParameter('debug.file_link_format', null); }); } diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php index f1e7709072..04f8b8ca10 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php @@ -68,6 +68,7 @@ class NoTemplatingEntryKernel extends Kernel ]) ->loadFromExtension('twig', [ 'strict_variables' => false, // to be removed in 5.0 relying on default + 'exception_controller' => null, // to be removed in 5.0 relying on default 'default_path' => __DIR__.'/templates', ]) ;