-
-
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
2.3 - Add repeat expander feature #109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 For PHP 5.x compat, but this is a new feature and should also be in latest master version for php 7.x
README.md
Outdated
@@ -84,6 +84,7 @@ $matcher->getError(); // returns null or error message | |||
* ``oneOf(...$expanders)`` - example usage ``"@[email protected](contains('foo'), contains('bar'), contains('baz'))"`` | |||
* ``matchRegex($regex)`` - example usage ``"@[email protected]('/^lorem.+/')"`` | |||
* ``optional()`` - work's only with ``ArrayMatcher``, ``JsonMatcher`` and ``XmlMatcher`` | |||
* ``repeat($pattern, $isStrict = true)`` - example usage ``'@[email protected]({"name" => "foe"})'`` or ``"@[email protected]('@string@')"`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{"name" => "foe"}
I think we should either ["name" => "foe"]
or {"name": "foe"}
but not a mix of both there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, a little mistake here. Of course, it's JSON. I will fix that ASAP
{ | ||
$jsonPattern = '{"name": "@string@", "activated": "@boolean@"}'; | ||
|
||
$jsonTest = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use "new" PHP short array syntax []
which is less verbose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes probably, but the whole project seems to use the older array()
syntax. In order to stick with the project's coding convention I'd rather not change that for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On master branch we are using []
- 2.3 branch was only created for 5.6 support however I'm not planning to add more new features here without adding them to the master branch first
* @param Matcher $matcher | ||
* @return bool | ||
*/ | ||
private function matchJson(array $values, Matcher $matcher) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should maybe allow this method to be recursive to match nested objects ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
"offers": "@[email protected]({\"subscription\": \"@[email protected](\"date\": \"@[email protected]()\")\"})"
}
This case will work with actual implementation ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case should work with the nested array.repeat syntax 'cause I just make a call to php-matcher factory. But you're right, maybe allowing nested objects would be more clever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not yet supported, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I'm sorry, didn't have the time to do it
public function __construct($pattern, $isStrict = true) | ||
{ | ||
if (!is_string($pattern)) { | ||
throw new \InvalidArgumentException("Repeat pattern must be a string."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exception is not covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix that ASAP.
private function matchScalar(array $values, Matcher $matcher) | ||
{ | ||
foreach ($values as $index => $value) { | ||
$match = $matcher->match($value, $this->pattern); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only match value, is following pattern failing ?
@[email protected]({"foo": "@string@"})
[
{
"foo": "bar"
},
{
"test": "bar"
}
]
``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand what you're talking about here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ignore this comment
Sure, but first I would like to see that feature on master branch and then into 2.3 or even 2.4 |
Totally agreed with that |
Fix readme and add cover for a new exception in test. Also create #110 for 3.0 repeat. |
Add "repeat" requested feature in:
#35
And also in:
#21
Feel free to comment, give advice.
I want to merge on 2.3 because I want to stick with PHP 5.6 not 7.