JSON matcher is not working as expected with pattern expanders
In project I'm currently working on, we had a following scenario step:
And json response should match:
"""
{
"limit": 10,
"offset": 0,
"count": 1,
"wins": @[email protected](1)
}
"""
and it was throwing me a very weird error: Type pattern "@array@" is not supported by TextMatcher. (RuntimeException).
After investigation it turned out that php-matcher/src/Matcher/Pattern/Assert/Json.php:33 can't recognize this pattern as a valid json value (because of @[email protected](1)) and thats why JSONExpander is being ignored.
The same problem seems to be found here: https://github.com/coduo/php-matcher/issues/83
Perfect solution would be to update Json::transformPattern($pattern) method, to transform patterns with expanders into native strings:
before transformation:
@[email protected](1)
after transformation:
"@[email protected](1)"
Of course currently this issue can be solved by making sure that all patterns with expanders are stored just like in following example:
And json response should match:
"""
{
"limit": 10,
"offset": 0,
"count": 1,
"wins": "@[email protected](1)"
}
"""
+1