Php 如何为json响应编写测试?

Php 如何为json响应编写测试?,php,json,unit-testing,laravel-5,laravel-5.1,Php,Json,Unit Testing,Laravel 5,Laravel 5.1,我有返回JSON的函数 return response()->json([ 'status' => 'OK', 'data' => [ 'id' => $routeForecast->id, ], ]) 我怎样才能对此进行测试。。我的laravel版本是5.1,我使用了assertJson[]它给了我这个错误 ***** PHPUnit_Fram

我有返回JSON的函数

return response()->json([
            'status' => 'OK',
            'data' => [
                'id' => $routeForecast->id,
            ],
        ])
我怎样才能对此进行测试。。我的laravel版本是5.1,我使用了assertJson[]它给了我这个错误

***** PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_Assert::assertJson() must be a string
试着告诉我这个错误

***** Invalid JSON was returned from the route. Perhaps an exception was thrown?

我怎样才能解决它???

试试这样的方法

    // When
    $response = $this->getJson( 'v1/helloWorld' );

    //dd( $response ); // perhaps die and dump here to check response?

    // Then
    $response
        ->assertStatus( 200 )
        ->assertJson( [
            'status' => 'OK',
        ] );

我认为assertJson不适用于laravel 5.1这是我对response$response=$this->json'POST','/path/en'所做的;啊,对不起,这是5.1中的JSON,对吗$response=$this->json'POST','/path/en';不,看起来你应该做$this->post'/path/en'或$this->call'post','/path/en'-