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

More details with JsonMatcher #191

Closed
Linkinou opened this issue Dec 11, 2019 · 8 comments
Closed

More details with JsonMatcher #191

Linkinou opened this issue Dec 11, 2019 · 8 comments

Comments

@Linkinou
Copy link

Linkinou commented Dec 11, 2019

Hello there,

using version 4.0 of coduo/php-matcher

Is there a way to get more details when JSON values do not match ?
Like the line that differ maybe ?

Because right now I have something like that :

Value {BIG_CHUNK_OF_JSON} does not match {BIG_CHUNK_OF_JSON}

Which is kind of difficult to debug.

Any suggestions ?

@norberttech
Copy link
Member

Hey, with the latest version of php-matcher you can review the backtrace that can be printed on demand.
You can check how it works on the demo page https://php-matcher.norbert.tech/

@julienfalque
Copy link

I am facing the same issue. Supposing this expected JSON:

{
    "foo": "bar"
}

if the actual value is

{
    "foo": "baz"
}

the error messages are:

  • v3.2: "baz" does not match "bar" pattern
  • v4.0: Value {"foo":"baz"} does not match pattern {"foo":"bar"}

The v4 is not useful as it just shows expected and actual values, without details about where the mismatch was. Newlines are also stripped out, so big values become unreadable.

Then the backtrace is

#1 Matcher Coduo\PHPMatcher\Matcher matching value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#2 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (all) matching value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#3 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) can match pattern "{"foo":"bar"}"
#4 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) matching value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#5 Matcher Coduo\PHPMatcher\Matcher\CallbackMatcher can't match pattern "{"foo":"bar"}"
#6 Matcher Coduo\PHPMatcher\Matcher\ExpressionMatcher can't match pattern "{"foo":"bar"}"
#7 Matcher Coduo\PHPMatcher\Matcher\NullMatcher can't match pattern "{"foo":"bar"}"
#8 Matcher Coduo\PHPMatcher\Matcher\StringMatcher can't match pattern "{"foo":"bar"}"
#9 Matcher Coduo\PHPMatcher\Matcher\IntegerMatcher can't match pattern "{"foo":"bar"}"
#10 Matcher Coduo\PHPMatcher\Matcher\BooleanMatcher can't match pattern "{"foo":"bar"}"
#11 Matcher Coduo\PHPMatcher\Matcher\DoubleMatcher can't match pattern "{"foo":"bar"}"
#12 Matcher Coduo\PHPMatcher\Matcher\NumberMatcher can't match pattern "{"foo":"bar"}"
#13 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher can match pattern "{"foo":"bar"}"
#14 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher matching value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#15 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher failed to match value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#16 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher error: "{"foo":"baz"}" does not match "{"foo":"bar"}".
#17 Matcher Coduo\PHPMatcher\Matcher\WildcardMatcher can't match pattern "{"foo":"bar"}"
#18 Matcher Coduo\PHPMatcher\Matcher\UuidMatcher can't match pattern "{"foo":"bar"}"
#19 Matcher Coduo\PHPMatcher\Matcher\JsonObjectMatcher can't match pattern "{"foo":"bar"}"
#20 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) failed to match value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#21 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) error: "{"foo":"baz"}" does not match "{"foo":"bar"}".
#22 Matcher Coduo\PHPMatcher\Matcher\JsonMatcher can match pattern "{"foo":"bar"}"
#23 Matcher Coduo\PHPMatcher\Matcher\JsonMatcher matching value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#24 Matcher Coduo\PHPMatcher\Matcher\ArrayMatcher matching value "Array(1)" with "Array(1)" pattern
#25 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (array) can match pattern "bar"
#26 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (array) matching value "baz" with "bar" pattern
#27 Matcher Coduo\PHPMatcher\Matcher\OrMatcher can't match pattern "bar"
#28 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) can match pattern "bar"
#29 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) matching value "baz" with "bar" pattern
#30 Matcher Coduo\PHPMatcher\Matcher\CallbackMatcher can't match pattern "bar"
#31 Matcher Coduo\PHPMatcher\Matcher\ExpressionMatcher can't match pattern "bar"
#32 Matcher Coduo\PHPMatcher\Matcher\NullMatcher can't match pattern "bar"
#33 Matcher Coduo\PHPMatcher\Matcher\StringMatcher can't match pattern "bar"
#34 Matcher Coduo\PHPMatcher\Matcher\IntegerMatcher can't match pattern "bar"
#35 Matcher Coduo\PHPMatcher\Matcher\BooleanMatcher can't match pattern "bar"
#36 Matcher Coduo\PHPMatcher\Matcher\DoubleMatcher can't match pattern "bar"
#37 Matcher Coduo\PHPMatcher\Matcher\NumberMatcher can't match pattern "bar"
#38 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher can match pattern "bar"
#39 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher matching value "baz" with "bar" pattern
#40 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher failed to match value "baz" with "bar" pattern
#41 Matcher Coduo\PHPMatcher\Matcher\ScalarMatcher error: "baz" does not match "bar".
#42 Matcher Coduo\PHPMatcher\Matcher\WildcardMatcher can't match pattern "bar"
#43 Matcher Coduo\PHPMatcher\Matcher\UuidMatcher can't match pattern "bar"
#44 Matcher Coduo\PHPMatcher\Matcher\JsonObjectMatcher can't match pattern "bar"
#45 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) failed to match value "baz" with "bar" pattern
#46 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (scalars) error: "baz" does not match "bar".
#47 Matcher Coduo\PHPMatcher\Matcher\TextMatcher can match pattern "bar"
#48 Matcher Coduo\PHPMatcher\Matcher\TextMatcher matching value "baz" with "bar" pattern
#49 Matcher Coduo\PHPMatcher\Matcher\TextMatcher failed to match value "baz" with "bar" pattern
#50 Matcher Coduo\PHPMatcher\Matcher\TextMatcher error: "baz" does not match "bar" pattern
#51 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (array) failed to match value "baz" with "bar" pattern
#52 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (array) error: "baz" does not match "bar" pattern
#53 Matcher Coduo\PHPMatcher\Matcher\ArrayMatcher failed to match value "Array(1)" with "Array(1)" pattern
#54 Matcher Coduo\PHPMatcher\Matcher\ArrayMatcher error: "baz" does not match "bar" pattern
#55 Matcher Coduo\PHPMatcher\Matcher\JsonMatcher failed to match value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#56 Matcher Coduo\PHPMatcher\Matcher\JsonMatcher error: Value {"foo":"baz"} does not match pattern {"foo":"bar"}
#57 Matcher Coduo\PHPMatcher\Matcher\XmlMatcher can't match pattern "{"foo":"bar"}"
#58 Matcher Coduo\PHPMatcher\Matcher\OrMatcher can't match pattern "{"foo":"bar"}"
#59 Matcher Coduo\PHPMatcher\Matcher\TextMatcher can't match pattern "{"foo":"bar"}"
#60 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (all) failed to match value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#61 Matcher Coduo\PHPMatcher\Matcher\ChainMatcher (all) error: Value {"foo":"baz"} does not match pattern {"foo":"bar"}
#62 Matcher Coduo\PHPMatcher\Matcher failed to match value "{"foo":"baz"}" with "{"foo":"bar"}" pattern
#63 Matcher Coduo\PHPMatcher\Matcher error: Value {"foo":"baz"} does not match pattern {"foo":"bar"}

As the backtrace contains all mismatches (the ones from matchers that are not related to the pattern and the ones that actually failed), it is quite complicated to find the error, even in this trivial example.

I couldn't find a way to get a precise error like v3.2 reported, is it still possible with v4?

@norberttech
Copy link
Member

Hey
yeah, that's probably currently the biggest issue of phpmatcher. I don't have on my roadmap fixing this anytime soon, too many things are happening in other projects.
Now beside my daily paid work I’m 100% focused on releasing stable version of https://github.com/aeon-php/calendar
This library is havely used in projects I’m working on and stable release is my top priority for now.
Once I release version 1.0.0 I would like to focus on integrating this lib with popular frameworks like Symfony and Laravel. Once those bridges are done I would like to get back into https://github.com/app-insights-php
After upgrading app insights I should finally take cleanup coduo/php-humanizer and only then I can get back to PHP-matcher.
Sorry, I know that you would probably like me to focus on the matcher but it’s not that easy to handle all those things my spare time.

However I’ll reopen this issue since it seems to be important and maybe someone else would find time to work on it

@bendavies
Copy link
Contributor

Hey @norberttech.

No worries! I'm happy to take a look, and have tried, but can't work it out so far.
I can't work out where/why this behaviour changed between v3 and v4/5.

If you have any ideas to help me on my way I'd appreciate it!

Thanks.

@norberttech
Copy link
Member

Afaik that behavior changed to fix another nasty bug related to not precise error messages when other matchers failed but unfortunately it also affected JSON matches. I guess you might want to work on error message by extracting difference between pattern and value

@bendavies
Copy link
Contributor

bendavies commented Oct 22, 2020

the causes look to be a combination of:

  1. Do not use anymore child matcher errors in Json/XML matchers #172
  2. The OrMatcher being moved to AFTER the JsonMatcher, as the OrMatcher does not return any error (returns a null error) so an previous errors will be lost in favour of the generic error.

@norberttech
Copy link
Member

norberttech commented Feb 25, 2021

so I think I finally fixed that problem in #225, latest version was deployed and this is how it looks

I'm closing this issue for now but feel free to let me know if I missed anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants