Lumen 5.6 seeJson() 失败
Lumen 5.6 seeJson() fails
我正在测试具有自定义错误消息的 api 验证,当我 运行 单元测试时,这给了我这个错误:
LinkCreationTest::fails_if_no_url_given
Unable to find JSON fragment ["url":"Please enter a URL to shorten."] within [{"url":["Please enter a URL to shorten."]}].
Failed asserting that false is true
LinkController.php
public function store(Request $request)
{
$this->validate($request,[
'url' => 'required|url'
],[
'url.required' => 'Please enter a URL to shorten.'
]);
}
web.php
$router->post('/', 'LinkController@store');
LinkCreationTest.php
/** @test */
public function fails_if_no_url_given()
{
$response = $this->json('POST', '/')
->notSeeInDatabase('links',[
'code' => '1'
])
->seeJson(['url' => 'Please enter a URL to shorten.'])
->assertResponseStatus(422);
}
我通过对 seeJson
的值使用 [] 解决了这个问题
->seeJson(['url' => ['Please enter a URL to shorten.'] ])
我正在测试具有自定义错误消息的 api 验证,当我 运行 单元测试时,这给了我这个错误:
LinkCreationTest::fails_if_no_url_given
Unable to find JSON fragment ["url":"Please enter a URL to shorten."] within [{"url":["Please enter a URL to shorten."]}].
Failed asserting that false is true
LinkController.php
public function store(Request $request)
{
$this->validate($request,[
'url' => 'required|url'
],[
'url.required' => 'Please enter a URL to shorten.'
]);
}
web.php
$router->post('/', 'LinkController@store');
LinkCreationTest.php
/** @test */
public function fails_if_no_url_given()
{
$response = $this->json('POST', '/')
->notSeeInDatabase('links',[
'code' => '1'
])
->seeJson(['url' => 'Please enter a URL to shorten.'])
->assertResponseStatus(422);
}
我通过对 seeJson
的值使用 [] 解决了这个问题->seeJson(['url' => ['Please enter a URL to shorten.'] ])