Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel testing, get JSON content

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()?

like image 980
rap-2-h Avatar asked Aug 25 '15 15:08

rap-2-h


1 Answers

Proper way to get the content is:

$content = $this->get('/v1/users/1')->decodeResponseJson(); 
like image 101
Jan Tlapák Avatar answered Sep 28 '22 09:09

Jan Tlapák