Symfony 2 - 在测试环境中获取错误而非调试页面 / 如何在测试环境中设置Twig ExceptionController的debug为false?

3

我希望在测试环境中,当应用程序抛出异常时,能够获得错误页面而不是调试页面。

我已经追踪了Twig Bundle代码,答案在 Symfony\Bundle\TwigBundle\Controller\ExceptionController 类的 findTemplate() 方法中。 这里我复制了选择模板的负责代码片段。

    $name = $debug ? 'exception' : 'error';
    if ($debug && 'html' == $format) {
        $name = 'exception_full';
    }

这段代码并没有问题。问题在于我无法为我的测试环境设置 ExceptionController 的 $debug 变量为 false。

根据 TwigBundle 配置参考,在 config_test.yml 中将 debug 参数设置为 false 应该就足够了。

twig:
  debug:       false

这里出现了问题。

我浏览了Symfony代码,并在 vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml 中找到了这段配置片段。

    <service id="twig.controller.exception" class="%twig.controller.exception.class%">
        <argument type="service" id="twig" />
        <argument>%kernel.debug%</argument>
    </service>

所以,无论我在配置文件中设置什么,调试变量的值都没有被修改。

你对此有什么看法?

我正在使用Symfony 2.2.1,这个问题与这个问题有点相关。

1个回答

0

这不是基于环境吗?

就像在app_dev.php中:

$kernel = new AppKernel('stag', TRUE); #TRUE = debug/dev mode on
$kernel = new AppKernel('stag', FALSE); #FALSE = debug/dev mode off

谢谢NoScope。虽然应该是基于你所说的,但它就是不起作用。我会继续研究。 - Sergio Romano

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接