diff --git a/src/TypeValidator.php b/src/TypeValidator.php index d8b0046..84281c7 100644 --- a/src/TypeValidator.php +++ b/src/TypeValidator.php @@ -52,7 +52,7 @@ public function validate($value): void $actualType = gettype($value); foreach ($this->allowedTypes as $type) { - if ($actualType === $type) { + if (strtolower($actualType) === strtolower($type)) { return; } diff --git a/tests/Fixtures/SampleData.php b/tests/Fixtures/SampleData.php index 4c0667c..0a9e84c 100644 --- a/tests/Fixtures/SampleData.php +++ b/tests/Fixtures/SampleData.php @@ -20,5 +20,11 @@ class SampleData extends DataTransferObject /** @var Foo|string */ public string $union_prop; + /** @var string|null */ + public $nullable_doctype_prop; + + /** @var Boolean|Int|String */ + public $mixed_case_type_prop; + public NestedData $nested; } diff --git a/tests/Unit/DataTransferObjectTest.php b/tests/Unit/DataTransferObjectTest.php index da45929..01fcc6f 100644 --- a/tests/Unit/DataTransferObjectTest.php +++ b/tests/Unit/DataTransferObjectTest.php @@ -97,6 +97,31 @@ public function testUnionProperty($value): void self::assertEquals(['union_prop' => $value], $data->toArray()); } + public function testNullableTypeViaDocBlockProperty(): void + { + $data = SampleData::make(['nullable_doctype_prop' => null]); + + self::assertEquals(['nullable_doctype_prop' => null], $data->toArray()); + } + + /** @return array */ + public function provideMixedCaseTypeValues(): array + { + return [ + [false], + [100], + ['foo'], + ]; + } + + /** @dataProvider provideMixedCaseTypeValues */ + public function testMixedCaseTypeDocBlockProperty($value): void + { + $data = SampleData::make(['mixed_case_type_prop' => $value]); + + self::assertEquals(['mixed_case_type_prop' => $value], $data->toArray()); + } + public function testNativeNullablePropertyAcceptsNull(): void { $data = SampleData::make();