-
Notifications
You must be signed in to change notification settings - Fork 49
Add validator's priority retrieval into Factory #180
Add validator's priority retrieval into Factory #180
Conversation
@webimpress zend-inputfilter/test/FactoryTest.php Lines 685 to 726 in a23e67d
|
The foreach on the chain won't return its validators. The method $chain->getValidators() return an array with extra data, so the instance need to be extracted. Asserts haven't been changed, but an additional assert assure that the foreach has been executed.
Test is a bit tricky, because when we get validators from ValidatorChain using getValidators method we are getting them as an array, not in order by priority. When validators are called (using isValid method) these are using the order they were added to the chain.
@froschdesign test added. Would you mind to have a look on it, please? It's a bit tricky as I mentioned in the commit comment - we can't use |
👍 |
if (isset($validator['priority'])) { | ||
$priority = $validator['priority']; | ||
} | ||
$priority = isset($validator['priority']) ? $validator['priority'] : ValidatorChain::DEFAULT_PRIORITY; |
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.
Even if this is the most logic way to do it, I used the "ugly" format to maintain coherence with the upper statement (breakChainOnFailure
).
If you want to use the ternary operator, it would be nicer to re-format the previous check too, so there aren't different coding styles in the same file.
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.
@mtagliab
I've changed it to match the logic from populateFilters
:
zend-inputfilter/src/Factory.php
Line 384 in c29cc31
$priority = isset($filter['priority']) ? $filter['priority'] : FilterChain::DEFAULT_PRIORITY; |
As you can see the coding style is mixed in the file...
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.
Actually, you are right, I didn't see that.
Add validator's priority retrieval into Factory
Thanks, @mtagliab! |
I noticed that it was impossible to set validator's priority using the "array notation", even if this feature was already there as it already exists for filters (see line 384 of Factory.php).
To add the priority, it will be enough to add the
priority
key in the array:FactoryTest fix
I also noticed that the FactoryTest class had a minor issue, which was that validators where not tested inside the
testFactoryWillCreateInputWithSuggestedValidators
method.I fixed the loop and added a final assert to verify that all the validators have been tested.