Skip to content

Commit

Permalink
AnyOf: calls normalize() on items [Closes #25][Closes #18]
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x authored and dg committed Dec 17, 2020
1 parent 0147fe8 commit 2ac00ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Schema/Elements/AnyOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function complete($value, Nette\Schema\Context $context)
if ($item instanceof Schema) {
$dolly = new Context;
$dolly->path = $context->path;
$res = $item->complete($value, $dolly);
$res = $item->complete($item->normalize($value, $dolly), $dolly);
if (!$dolly->errors) {
return $this->doFinalize($res, $context);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Schema/Expect.anyOf.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,11 @@ test('Schema as default value', function () {

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


test('normalization', function () {
$schema = Expect::anyOf(
Expect::string()->before(function ($v) { return (string) $v; })
);
Assert::same('1', (new Processor)->process($schema, 1));
});

0 comments on commit 2ac00ac

Please sign in to comment.