From dea1e755549a9b54f5895097cc56b9f244f97867 Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Fri, 20 Oct 2023 12:18:36 +0200 Subject: [PATCH] Revert "Fix issue where non set optional values were transformed" This reverts commit 3b63875338cd6ef29fe362421a4e2186338f5b2d. # Conflicts: # tests/ValidationTest.php --- src/Transformers/DataTransformer.php | 4 ---- tests/ValidationTest.php | 10 ---------- 2 files changed, 14 deletions(-) diff --git a/src/Transformers/DataTransformer.php b/src/Transformers/DataTransformer.php index 8a54fef2..bddb4de2 100644 --- a/src/Transformers/DataTransformer.php +++ b/src/Transformers/DataTransformer.php @@ -76,10 +76,6 @@ protected function resolvePayload(TransformableData $data): array $name = $property->name; - if ($property->type->isOptional && ! isset($data->{$name})) { - continue; - } - if (! $this->shouldIncludeProperty($name, $data->{$name}, $trees)) { continue; } diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 4a7d8cf4..9917cf62 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -2379,13 +2379,3 @@ public static function rules(ValidationContext $context): array ->assertOk(['success' => true, 'id' => 1]) ->assertErrors(['success' => true]); })->skip('V4: The rule inferrers need to be rewritten/removed for this, we need to first add attribute rules and then decide require stuff'); - -it('will not transform non set optional properties ', function () { - $dataClass = new class () extends Data { - public array|Optional $optional; - }; - - expect($dataClass::from([])->toArray())->toBeEmpty(); - expect($dataClass::from()->toArray())->toBeEmpty(); - expect((new ($dataClass::class))->toArray())->toBeEmpty(); -});