-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wrong behavior when using templates
When a template is set for a chain of rules, does not really matter which messages the chain can have, the only message to be used should be the one based on the defined template. This commit set the same template of a parent rule to its children's exception. Our first thought was to set the template to its children however that would mean that if another rule would be added to the chain we would have to set it as well. Doing that to the children's exception make sure we only do that once. Co-authored-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
e70c201
commit 83bb6e3
Showing
5 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--FILE-- | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
use Respect\Validation\Exceptions\ValidationException; | ||
use Respect\Validation\Rules\Instance; | ||
|
||
try { | ||
(new Instance('stdClass'))->setTemplate('invalid object')->assert('test'); | ||
} catch (ValidationException $exception) { | ||
print_r($exception->getMainMessage()); | ||
} | ||
?> | ||
--EXPECTF-- | ||
invalid object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--FILE-- | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
use Respect\Validation\Exceptions\NestedValidationException; | ||
use Respect\Validation\Validator as v; | ||
|
||
try { | ||
v::key('email', v::email()->setTemplate('WRONG EMAIL!!!!!!'))->assert(['email' => 'qwe']); | ||
} catch (NestedValidationException $exception) { | ||
print_r($exception->getMessages()); | ||
} | ||
?> | ||
--EXPECTF-- | ||
Array | ||
( | ||
[0] => WRONG EMAIL!!!!!! | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,3 @@ try { | |
?> | ||
--EXPECTF-- | ||
- "something" is not tasty | ||
- "something" must be greater than or equal to 1 |