Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seeResponseMatchesJsonType does not work with null data #2522

Closed
maxiwheat opened this issue Nov 5, 2015 · 5 comments
Closed

seeResponseMatchesJsonType does not work with null data #2522

maxiwheat opened this issue Nov 5, 2015 · 5 comments

Comments

@maxiwheat
Copy link

@maxiwheat maxiwheat commented Nov 5, 2015

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.

API returns :

{
    "id": 123456,
    "birthdate": null,
    "firstname": "John",
    "lastname": "Doe"
}
$I->seeResponseMatchesJsonType(array(
            'birthdate' => 'string|null'
));

I get a failed test with this message :

Fail birthdate: NULL is not of type string|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.

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Nov 6, 2015

seeResponseMatchesJsonType is 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.php

It 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
Copy link
Author

@maxiwheat maxiwheat commented Nov 10, 2015

On a side note, I managed to make it work by inverting the types. string|null fails my test, but null|string passes.

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Nov 12, 2015

Strange. I will try to reproduce and fix this issue

@DavertMik DavertMik added the REST label Nov 12, 2015
@DavertMik
Copy link
Member

@DavertMik DavertMik commented Nov 12, 2015

I didn't manage to reproduce it... Probably it depends on your PHP version. Which one are you using?

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Nov 12, 2015

I see, that was fixed in #2500

@DavertMik DavertMik closed this Nov 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.