-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Adds NonStrictArrayMatcher which will matches softly value and pattern #40
Adds NonStrictArrayMatcher which will matches softly value and pattern #40
Conversation
+1 |
Sorry @javierseixas I'm 👎 for this one. I dont like that fact that value match the pattern when it contains more elements than pattern itself. I think that |
@norzechowicz thanks for taking into account the pull request. Why do you think it adds magic? Regarding the solution itself, I liked your proposal as well, but what I wasn't convince because of the legibility in a Behat feature file. Your sample looked great, however I was wondering how it would be with a more complex json value. {
"id": "@string@",
"title": "My Title",
"short_description": "@string@",
"campaign_start": "@string@",
"campaign_end": "@string@",
"status": "@integer@",
"_links": "@wildcard@",
"_embedded": {
"products": [
{
"name": "My product 1",
"price": "@double@",
"description": "@string@",
"quantity": "@integer@"
},
{
"name": "My product 2",
"price": "@double@",
"description": "@string@",
"quantity": "@integer@"
}
],
"account": {
"id": "@string@",
"name": "foo",
"society_name": "@string@",
"_links": "@wildcard@"
}
}
} With the solution in this pull request, would be like this: {
"title": "My Title",
"status": 2,
"_embedded": {
"products": [
{
"name": "foo"
},
{
"name": "bar"
}
],
"account": {
"name": "foo"
}
}
} |
Adds test negative matches Does some refactoring
@norzechowicz hello again! After thinking a bit more, I want to propose a solution to make clearer this non strict work. I was inspired by the strictness solution of JSON Expression. My proposal is to have a pattern, as I first proposed in the issue #39 but in the following way: {
"title": "My Title",
"status": 2,
"_embedded": {
"account": {
"name": "foo"
}
}
}@ignore_extra_keys@ It would keep the What do you think? |
Yea looks a lot better but now we need to figure out how to pass this "ignore_extra_keys" into JsonMatcher in order to use NonStrictArrayMatcher instead of ArrayMatcher. |
See my second commit in this pull request 😄 |
Interesting but |
Ok, make sense. So would me something like instead of |
Most important I think its to create a pattern for those modifiers. Maybe
|
We can also consider moving modifiers at the beggining of the pattern. So we can assume that everything that is between
Or in simpler cases |
I really like the idea! I'm not sure if I understood well the concept modifier though. What does it modify? For me, it does not modify the value, neither the pattern (it is just removed from the pattern). What it modifies is the behaviour of the matcher. Are you agree? So, I'm not sure about calling them modifiers. I'd vote for "strictnessers" (A made up word :P). For me it would make sense for the two samples I agree to put it them at the beginning of the json and between I'll work on this for a couple of days. |
Indeed those values would modifie the matcher behavior. I came up with modifiers because there is very similar thing in regular expression, you can add it at the end of expression and it will modifie the pattern for example by ignoring case sensitive. |
Hi! I've been busy the last days. Now I'm working on these improvements. @norzechowicz you're welcome. It's a pleasure to work on this :) I 've started working on that, and as far as I go more doubts about how to do it come to my mind. And when I was doing that, and I was thinking in injecting to the
And here I am. Personally, I think the option 2 is cleaner, separating classes with its own behaviour, but the fact of changing the injected object on the fly depending on the modifiers passed to the pattern is quite magic. Besides, I don't really like the fact of modifying So please, let me know what you think about it or if you have any question about the explanations. I'm very open to suggestions as well :) Cheers! |
Changing value/pattern is not a good solution. Method 2 sounds better but... ;) I dont think that we need to replace "loaded" matchers. IMO modifier is more like a option for specific matcher. So lets take "case_insnensitive" modifier for example. $pattern = '|case_insensitive|{id: 12345, name:"Norbert Orzechowicz"}' In such situation json matcher should do 3 things.
In order to do so we need following methods in
We also need to add 2 methods into
public function match($value, $pattern)
{
if (!is_string($value) || !$this->isValidJson($value)) {
return false;
}
$this->modifyMatchers($this->parser->parseModifiers($pattern));
$pattern = $this->transformPattern($pattern); // remove modifiers here using trimModifiers
$match = $this->matcher->match(json_decode($value, true), json_decode($pattern, true));
if (!$match) {
$this->error = $this->matcher->getError();
return false;
}
return true;
} modifyMatchers will simply iterate through all matchers (if there are more than 1 modifier) and check if any matcher can handle any modifier.
Thanks to this approach there will be no need to create There is only one important thing that we need to keep in minds during implementation. Modifiers should be passed through each matcher than can make use of them. For example current JsonMatcher in order to work require ArrayMatcher that require ScalarMatcher. Of course feedback is more than welcome @javierseixas ;) |
Hi! Just say that I don't forget this pull request. I've been very busy the last weeks. Hoping to get some free time next month to advance on this :) |
Hey @javierseixas thanks for information. PR is open, take as long as you need to finish it and let me know if you will need some help. |
@javierseixas I'm closing this PR for now, if u will find some time to work on it ping me and I will reopen it or create new one on your own. |
@norzechowicz no problem. I'm sorry I haven't had the time to work on this. Thanks! |
👍 Like this idea a lot! any update on this? |
👍Any news on this? @javierseixas |
Hi @vitalyiegorov ! No news actually. I haven't been programming with php for a while, so I stop needing that feature. I can say though other languages like java have it. |
Maybe we can merge this PR and enable this feature?
вс, 3 июня 2018 г. в 17:15, Javier Seixas <[email protected]>:
… Hi @vitalyiegorov <https://github.com/vitalyiegorov> ! No news actually.
I haven't been programming with php for a while, so I stop needing that
feature. I can say though other languages like java have it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAjzPtp2wITK2W0tvU0rT_RrpS9d6YIEks5t4--HgaJpZM4DFS0C>
.
|
My PR is from 2015. Not sure if is still compatible with the current version of the project. |
After studying a bit issue #39 , I found out that the only thing required to be able to match softly a JSON, would be having a new
ArrayMatcher
, being able to keep going through the array instead of returning an error when there is a value not contained in the pattern.So here it is my proposal of creating a new
NonStrictArrayMatcher
, a subtype of theArrayMatcher
, where only changes theiterateMatch()
method.So, to get what I requested on issue #39 it would be only needed to create a
JsonMatcher
containing aNonStrictArrayMatcher
.