我正在关注这门课程testdrivenlaravel,它提到了一种禁用 Laravel 异常处理的方法,以防止 Laravel 处理发生的异常并抛出它,因此我们可以在测试输出中获得更详细的错误。
所以我在我的测试用例类中添加了这个方法,在渲染方法中我抛出了异常
protected function disableExceptionHandling() {
$this->app->instance(Handler::class, new class extends Handler {
public function __construct()
{
}
public function report(\Exception $e)
{
}
public function render($request, \Exception $e)
{
throw $e;
}
});
}
但是每当我在测试中调用它时,为了获得更详细的错误,我仍然会得到 Laravel 处理程序正在呈现的相同错误。
当我像这样直接更改Handler
课程时:
public function render($request, Exception $exception)
{
throw $exception;
// return parent::render($request, $exception);
}
我得到了详细的错误,但我需要让disableExceptionHandling
助手工作。