Skip to content

Commit

Permalink
fix: accept DocBlock types with mixed cases
Browse files Browse the repository at this point in the history
  • Loading branch information
phanan committed Mar 17, 2021
1 parent f93f225 commit 522f2ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TypeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Fixtures/SampleData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
25 changes: 25 additions & 0 deletions tests/Unit/DataTransferObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<mixed> */
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();
Expand Down

0 comments on commit 522f2ee

Please sign in to comment.