【问题标题】:Lumen 5.6 seeJson() fails流明 5.6 seeJson() 失败
【发布时间】: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


【解决方案1】:

我通过在 seeJson 的值上使用 [] 解决了这个问题

->seeJson(['url' => ['Please enter a URL to shorten.'] ])

【讨论】:

    猜你喜欢
    • 2016-07-31
    • 2018-07-22
    • 2016-11-30
    • 2021-04-20
    • 2018-10-30
    • 2019-07-16
    • 2015-02-03
    • 2021-06-19
    • 2018-08-10
    相关资源
    最近更新 更多