【发布时间】:2018-04-02 13:30:51
【问题描述】:
我正在测试一个有自定义错误消息的 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);
}
【问题讨论】:
-
LinkController.php似乎没有返回任何内容。
标签: lumen laravel-5.6