【问题标题】:laravel assertJsonValidationErrors() does not existlaravel assertJsonValidationErrors() 不存在
【发布时间】:2018-07-21 22:08:08
【问题描述】:

当我在 laravel 5.5 中使用 assertJsonValidationErrors() 测试方法时,出现以下错误:

Call to undefined method Illuminate\Http\JsonResponse::assertJsonValidationErrors()

我不知道出了什么问题。其他测试方法对我来说效果很好。 这是我的测试方法:

public function test_user_login_when_phone_is_empty()
{
    $response = $this->json(
        'POST',
        route('login'),
        [
            'phone' => '',
            'password' => 'sdfksfhas4u'
        ]
    );

    $response
        ->assertJsonValidationErrors(['phone'])
        ;
}

有什么帮助吗?

【问题讨论】:

  • 你能发布你的错误堆栈跟踪并给我们链接吗?
  • 如果您的意思是日志文件中的堆栈跟踪,我的日志文件中没有与此错误相关的内容@NikolaGavric
  • 刚刚在新的 laravel 5.5 应用程序上尝试了该方法,这就是我得到的 imgur.com/a/UAaQz
  • 根据 laravel 的文档,一切都应该没问题,但事实并非如此!我很困惑。有什么建议吗? @NikolaGavric
  • 我真的不知道,我什至在Laravel 文件中都找不到那个函数..

标签: php unit-testing laravel-5 phpunit


【解决方案1】:

assertJsonValidationErrorsIlluminate\Foundation\Testing\TestResponse 的方法,而不是 Illuminate\Http\JsonResponse

我猜你可能忘记扩展 TestCase。

【讨论】:

  • 不,我在我的测试类中扩展了TestCase
猜你喜欢
  • 2017-08-07
  • 2021-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-24
  • 2014-02-09
  • 2018-12-15
相关资源
最近更新 更多