Reputation: 1563
I have a test that checks a api for a json response
public function test_search_get_place_details()
{
$this->post('/api/searchVenue', ['placeId' => 'ChIJXZE0JMLeekgR2meph0M9Jm41221212112']);
$this->SeeJson([
'Town' => 'Birkenhead',
]);
}
This test works and asserts correctly, but when it fails all I get is
Time: 1.42 seconds, Memory: 27.00MB
There was 1 error:
1) SearchTest::test_search_get_place_details
ErrorException: Invalid argument supplied for foreach()
/home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Support/Arr.php:494
/home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:232
/home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:257
/home/ubuntu/workspace/tests/SearchTest.php:41
I assume that this is because the response is a typical laravel error and not json. But I need to know what that error is as it is happening on my CI box, but not locally.
is there anyway to get it to output what ever the response contains on failure?
Upvotes: 3
Views: 994
Reputation: 2191
I always find it annoying when a testing framework fails to provide any decent indication as to what it saw when it didn't see what I told it to expect. Aside from wrapping a try...catch...report...rethrow around the assertion, I know of no decent way to get the MakesHttpRequests
trait to spit out what it saw only when the test fails.
However, to debug it, you might go ahead and do that, and use $this->response
to see what was in the response.
Upvotes: 2
Reputation: 2445
You can usually get this error due to wrong formatting in your JSON response. Keep in mind your test is awaiting a valid JSON response, so in that case that's what you need to fix.
Upvotes: 1