【问题标题】:disable exception handling in laravel test在 laravel 测试中禁用异常处理
【发布时间】:2019-06-22 23:24:01
【问题描述】:

我一直在尝试在测试中禁用异常处理,以便查看错误,但即使我故意破坏代码也无法正常工作。

我只是得到这个一般性的回应,并没有太大帮助。

Invalid JSON was returned from the route.

我已经尝试了所有可以在网上找到的解决方案,但都没有奏效。

我尝试在测试方法的顶部添加$this->disableExceptionHandling(),但没有成功。我还尝试了 Adam Wathan (https://gist.github.com/adamwathan/125847c7e3f16b88fa33a9f8b42333da) 的教程,但也没有用。

我什至尝试过编辑 Handler.php 文件

public function render($request, Exception $exception)
{
    throw $exception;
    // return parent::render($request, $exception);
}

它现在还在工作。

请问我该如何解决这个问题。

任何帮助将不胜感激。

谢谢。

【问题讨论】:

  • 你的.env中有APP_DEBUG=true吗?
  • 是的。 APP_DEBUG-真。

标签: laravel testing laravel-testing


【解决方案1】:

你可以在handler.php的report方法中使用这段代码

if (env('APP_ENV') === 'testing') {
    throw $exception;
}

【讨论】:

    猜你喜欢
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多