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 error message is confusing #2858

Closed
dakisa91 opened this Issue Mar 1, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@dakisa91

dakisa91 commented Mar 1, 2016

Lets say i pass this array to seeResponseMatchesJsonType.

$I->seeResponseMatchesJsonType([
    'sessions' => [
        [
            'id_session_FAIL' => 'string', //force error
            'session_name' => 'string',
            'course_name' => 'string',
            'course_code' => 'string',
            'course_description' => 'string'
        ],
    ],
    'success'=>'boolean'
]);

In this example im forcing it to fail, but the error message i get is confusing.

Failed asserting that 'Key `id_session_FAIL` doesn't exist in {.............} is true.

It almost sounds like im trying to make sure the key doesn't exist and it failed ( basically found that key ).
After some digging around i found this that this method uses another method matches which also uses another method - typeComparison
typeComparison can return true, or some error message. One of the error messages is this:

return "Key `$key` doesn't exist in " . json_encode($data);

That message sounds ok. Sure, it failed because it didn't find some key.
But after that, this error message is used in a assertTrue in the seeResponseMatchesJsonType method

$matched = (new JsonType($jsonArray))->matches($jsonType); //Error message is returned here
$this->assertTrue($matched, $matched);

Which spits out the confusing message that i pointed out earlier.
I saw issue #2544, which might cover this, as it might rework this method in the process.

@DavertMik DavertMik added the REST label Mar 13, 2016

@Naktibalda Naktibalda self-assigned this Sep 1, 2016

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Sep 2, 2016

Member

In 2.2.4 error output is

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  See response matches json type {"zzz":"string"}
 Fail  Key `zzz` doesn't exist in {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}
Failed asserting that 'Key `zzz` doesn't exist in {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}' is true.

Member

Naktibalda commented Sep 2, 2016

In 2.2.4 error output is

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  See response matches json type {"zzz":"string"}
 Fail  Key `zzz` doesn't exist in {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}
Failed asserting that 'Key `zzz` doesn't exist in {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}' is true.

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Sep 2, 2016

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Sep 2, 2016

Member

After my change it prints

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  See response matches json type {"zzz":"string"}
 Fail  Key `zzz` doesn't exist in {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}
Member

Naktibalda commented Sep 2, 2016

After my change it prints

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  See response matches json type {"zzz":"string"}
 Fail  Key `zzz` doesn't exist in {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Sep 2, 2016

Member

The output of dontSeeResponseMatchesJsonType is

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  Don't see response matches json type {"requestMethod":"string","requestUri":"string"}
 Fail  Unexpectedly the response matched the array (
  'requestMethod' => 'string',
  'requestUri' => 'string',
) data type
Failed asserting that true is not equal to true.

I will change it to:

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  Don't see response matches json type {"requestMethod":"string","requestUri":"string"}
 Fail  Unexpectedly the response matched: {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}
Member

Naktibalda commented Sep 2, 2016

The output of dontSeeResponseMatchesJsonType is

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  Don't see response matches json type {"requestMethod":"string","requestUri":"string"}
 Fail  Unexpectedly the response matched the array (
  'requestMethod' => 'string',
  'requestUri' => 'string',
) data type
Failed asserting that true is not equal to true.

I will change it to:

1) JsonTypeErrorCept: Get error message
 Test  tests/functional/REST/JsonTypeErrorCept.php
 Step  Don't see response matches json type {"requestMethod":"string","requestUri":"string"}
 Fail  Unexpectedly the response matched: {"requestMethod":"GET","requestUri":"\/rest","queryParams":[],"formParams":[],"rawBody":null,"headers":{"User-Agent":"Symfony2 BrowserKit","Host":"localhost"},"X-Auth-Token":null,"files":[]}

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Sep 2, 2016

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Sep 2, 2016

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Sep 3, 2016

@DavertMik DavertMik closed this in #3480 Sep 7, 2016

DavertMik added a commit that referenced this issue Sep 7, 2016

[REST] Improved output of failed JsonType assertions (#3480)
* Print nicer error message when MatchesJsonType failed

Fixes #2858

* Print nicer error message when DontMatchJsonType failed

Fixes #2858

chris1312 added a commit to chris1312/Codeception that referenced this issue Jun 16, 2017

[REST] Improved output of failed JsonType assertions (#3480)
* Print nicer error message when MatchesJsonType failed

Fixes #2858

* Print nicer error message when DontMatchJsonType failed

Fixes #2858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment