Skip to content

Commit

Permalink
AnyOf: call normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Aug 17, 2020
1 parent 1fa79ae commit a1859ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Schema/Elements/AnyOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function complete($value, Nette\Schema\Context $context)
if ($item instanceof Schema) {
$dolly = new Context;
$dolly->path = $context->path;
$value = $item->normalize($value, $dolly);
$res = $item->complete($value, $dolly);
if (!$dolly->errors) {
return $this->doFinalize($res, $context);
Expand Down
21 changes: 21 additions & 0 deletions tests/Schema/Expect.anyOf.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,24 @@ test('Schema as default value', function () {

Assert::same(['key1' => ['key2' => null]], (new Processor)->process($schema, null));
});


test('normalizing', function () {
$schema = Expect::anyOf(
false,
Expect::array()
->before(function ($val) {
if (!is_string($val)) return $val;
return explode(',', $val);
})
);

$processor = new Processor;

Assert::same(false, $processor->process($schema, false));
Assert::same(['1','2','3'], $processor->process($schema, '1,2,3'));

checkValidationErrors(function () use ($schema) {
(new Processor)->process($schema, 1);
}, ['The option expects to be false|array, 1 given.']);
});

0 comments on commit a1859ed

Please sign in to comment.