Always return a valid exception

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.
This commit is contained in:
Henrique Moody 2016-09-19 18:22:39 +02:00
parent d0a98ae5d3
commit 98050476c6
No known key found for this signature in database
GPG key ID: 221E9281655813A6
2 changed files with 63 additions and 0 deletions

View file

@ -53,6 +53,8 @@ class NestedValidationException extends ValidationException implements IteratorA
foreach ($exception as $subException) {
return $subException;
}
return $exception;
}
/**

View file

@ -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
)