seeJson() never match
I'm using Laravel 5.1 Testsuite.
Now, I test my json api with the method seeJson(). This method expects an array, such as:
->seeJson(['created' => 1]);
But my json api always returns a json object or an array with json objects with line like below:
Response::json(['created' => 1], 200);
In the case above, my json api returns:
{created: 1}
But seeJson() looks for the given array exactly:
[created: 1]
I never get my tests pass with a match.
->seeJson((object) ['created' => 1])
@GrahamCampbell Thanks for your reply, but seeJson() expects an array.
ErrorException: Argument 1 passed to Illuminate\Foundation\Testing\TestCase::seeJson() must be of the type array, object given, called in /Applications/XAMPP/xamppfiles/htdocs/w/server/tests/UserOrganisationTest.php on line 7 and defined
Just literally check the response body is equal. Just because it's a json response, doesn't mean you need to use fancy methods.
@GrahamCampbell I know, but why tells the doc that there are json-methods: seeJson(), seeJsonContains(), etc for testing json output?
See this: http://laravel.com/docs/5.1/testing#testing-json-apis
Ok, I'll check via another way the json output, but why are there new methods in L5.1 testsuite if you say they're too fancy to use?
I know, but why tells the doc that there are json-methods: seeJson(),
Yeh, sure there are, but it doesn't mean they're suitable for every use case ever. you need to make you're own judgement calls. Everything's not one size fits all.