You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
seeResponseMatchesJsonType does not work with null data #2522
I read the documentation here and found that we can validate the types of JSON data returned with a REST webservice, and it seems to support null as a valid type :
// This is an example found here : http://codeception.com/docs/modules/REST
$I->seeResponseIsJsonType([
'user_id' => 'integer',
'name' => 'string|null',
'is_active' => 'boolean'
]);
However, using this in my tests, I get a failure when the data returned is null.
Can this be fixed, or is there a workaround ? Leaving only stringdoes not help. I can remove the check for the birthdate, but it is not an ideal solution.
Activity
DavertMik commentedon Nov 6, 2015
seeResponseMatchesJsonTypeis pretty new feature so we plan to constantly improve it. Right now the best way to solve this issue is to help us make it better. Please send us a PR with a fix to it: https://github.com/Codeception/Codeception/blob/2.1/src/Codeception/Util/JsonType.phpIt would be even better if you include a failing test into https://github.com/Codeception/Codeception/blob/2.1/tests/unit/Codeception/Util/JsonTypeTest.php
maxiwheat commentedon Nov 10, 2015
On a side note, I managed to make it work by inverting the types.
string|nullfails my test, butnull|stringpasses.DavertMik commentedon Nov 12, 2015
Strange. I will try to reproduce and fix this issue
DavertMik commentedon Nov 12, 2015
I didn't manage to reproduce it... Probably it depends on your PHP version. Which one are you using?
DavertMik commentedon Nov 12, 2015
I see, that was fixed in #2500