From 2ac00acdfdf4ca700530b6254d96cc3eac259f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Mon, 17 Aug 2020 20:22:10 +0200 Subject: [PATCH] AnyOf: calls normalize() on items [Closes #25][Closes #18] --- src/Schema/Elements/AnyOf.php | 2 +- tests/Schema/Expect.anyOf.phpt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Schema/Elements/AnyOf.php b/src/Schema/Elements/AnyOf.php index ab75fbc..b4ce465 100644 --- a/src/Schema/Elements/AnyOf.php +++ b/src/Schema/Elements/AnyOf.php @@ -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); } diff --git a/tests/Schema/Expect.anyOf.phpt b/tests/Schema/Expect.anyOf.phpt index 379e1d8..99792fa 100644 --- a/tests/Schema/Expect.anyOf.phpt +++ b/tests/Schema/Expect.anyOf.phpt @@ -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)); +});