Laravel testing, get JSON content

rap-2-h picture rap-2-h · Aug 25, 2015 · Viewed 38.3k times · Source

In Laravel's unit test, I can test a JSON API like that:

$this->post('/user', ['name' => 'Sally'])
    ->seeJson([
        'created' => true,
    ]);

But what if I want to use the response. How can I get the JSON response (as an array) using $this->post()?

Answer

Jan Tlapák picture Jan Tlapák · Jun 23, 2016

Proper way to get the content is:

$content = $this->get('/v1/users/1')->decodeResponseJson();