diff --git a/UPGRADE-4.4.md b/UPGRADE-4.4.md index 492591a5d49a..8561391dc9ae 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 ce0ad3e6569f..615ec93ac70f 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 16fc81dd268d..f48b4444fbde 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 927f153c3b10..3c4f7f0b0b0a 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 2859693a17c2..908f7ce14f30 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php @@ -70,6 +70,6 @@ public function testDefaultJsonLoginBadRequest() $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 000000000000..7a22a599b74d --- /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 e3aef52a2e09..bcfd17425cfd 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 622ec0f3ebfb..80d5ec570e29 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 181618ba99e4..9a26fb163a77 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 d7b8ac97d977..e49a697e52eb 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 493989866a27..e53084cda7c0 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 f019a09d954e..b31b1de8ca4c 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 65b7f4b9130a..eb1f93246a34 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 e1d7760826ea..f8fa000d2bc4 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -19,12 +19,16 @@ 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 80c79f45ee2f..bc15a968e9c1 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 b635a752aba8..ebbf8d3d325f 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -34,7 +34,13 @@ public function getConfigTreeBuilder() $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 000000000000..b9c876a273cc --- /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 684a68873162..52723177a1fb 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 25c84a6c9b5e..8a9de15c2b89 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 d8a936948782..f2816dc8d903 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 01fab3ad0873..75c3789510d6 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 d8a936948782..f2816dc8d903 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 fc19fd83bb0e..a675a5620d3b 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 25c84a6c9b5e..8a9de15c2b89 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 bec5b1e30248..66ddee0048d4 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 5ea8f565ab9c..5b38858eec32 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 2cdf03f2bcb5..ec921b96202d 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 593d490257e3..cec0e16f66d6 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 593d490257e3..cec0e16f66d6 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 13a41476f2a7..9b87e74fd030 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 2cdf03f2bcb5..ec921b96202d 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 cb17fb149f9a..bcc15b7c3207 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 36c9449b6c50..27e95641cf94 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 ae46775925c5..bbab90432bd7 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 c510a13e6632..746ba46608ca 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 ee7c20746ae5..4e48df0aebd9 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php @@ -18,6 +18,9 @@ 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 e479804b987e..33300336d11c 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -21,6 +21,7 @@ public function testDoNoDuplicateDefaultFormResources() { $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 @@ public function testGetStrictVariablesDefaultFalse() $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 @@ public function testArrayKeysInGlobalsAreNotNormalized() { $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 de55467d2285..481f57cdc5a9 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 @@ '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 76e66160f50d..e4d9638c5292 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 69fbf7c012e8..907217bf4040 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 @@ '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 8dd2be40960b..5356e4434725 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 @@ '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 63c851720cc2..5d2558467ba6 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 ffe2f5257733..0affe9386c31 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 17bcf0acd449..f95f052104f3 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 7f8fb84357da..c14a971998f8 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 8ece3b80b794..665230134766 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 34e301c0957e..de2c45759c9f 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 9b5dbcf35b67..e66cce095371 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 41a281cc8198..7a7cbae6b101 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 a5c57f383edf..b54e50aea180 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 24c10c23fe8f..0c28f048781d 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 f3c0bc8503f1..bba6d41f8986 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -31,6 +31,7 @@ public function testLoadEmptyConfiguration() $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 @@ public function testGlobalsWithDifferentTypesAndValues() $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 @@ public function testStopwatchExtensionAvailability($debug, $stopwatchEnabled, $e $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 @@ public function testRuntimeLoader() $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 000000000000..fa04d363caf2 --- /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 ca21df09029b..a9c8737e2344 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php @@ -99,6 +99,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) ]) ->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 df90b237526e..d2a3ab68f9d7 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php @@ -14,6 +14,8 @@ 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 @@ public function registerBundles() 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 f1e77090721b..04f8b8ca10d7 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php @@ -68,6 +68,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) ]) ->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', ]) ; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy