forked from Respect/Validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If calling the method `getExceptionForPath()` when the exception was nested but had no child it was returning null. This commit ensures that it always return a valid exception.
- Loading branch information
1 parent
d0a98ae
commit 9805047
Showing
2 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--FILE-- | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
use Respect\Validation\Exceptions\NestedValidationException; | ||
use Respect\Validation\Validator as v; | ||
|
||
$input = [ | ||
'contact1' => [ | ||
'daymark' => 'ffesfewf2232313123212', | ||
'building' => [ | ||
'enable' => 'd', | ||
'blank' => 'ffesfewf2232313123212', | ||
'powerdown' => '5', | ||
'powerup' => 'wdwdwf', | ||
], | ||
], | ||
'contact2' => [ | ||
'name' => 'wd', | ||
'daymark' => 'ffesfewf2232313123212', | ||
'building' => [ | ||
'enable' => '1', | ||
'blank' => '1', | ||
'powerdown' => '1', | ||
'powerup' => '1', | ||
], | ||
], | ||
]; | ||
|
||
try { | ||
v::create() | ||
->each( | ||
v::create() | ||
->key('name', v::length(1, 50)) | ||
->key('daymark', v::length(1, 50)) | ||
->key( | ||
'building', | ||
v::create() | ||
->key('enable', v::length(2, 50)) | ||
->key('time', v::length(2, 50)) | ||
->key('powerdown', v::length(2, 50)) | ||
->key('powerup', v::length(2, 50)) | ||
) | ||
) | ||
->assert($input); | ||
} catch (NestedValidationException $exception) { | ||
print_r(array_filter($exception->findMessages([ | ||
'each.name' => 'Center name', | ||
'each.building.enable' => 'Center time', | ||
'each.building.powerdown' => 'Center time', | ||
]))); | ||
} | ||
?> | ||
--EXPECTF-- | ||
Array | ||
( | ||
[each_name] => Center name | ||
[each_building_enable] => Center time | ||
[each_building_powerdown] => Center time | ||
) |