Lumen 5.6 seeJson()失败了

时间:2018-03-25 21:47:30

标签: lumen laravel-5.6

我正在测试一个带有自定义错误消息的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);
}

1 个答案:

答案 0 :(得分:0)

我通过在seeJson

的值上使用[]来解决这个问题
$substr