Skip to content

Commit

Permalink
Merge pull request #75 from microsoft/dev
Browse files Browse the repository at this point in the history
v0.8.1
  • Loading branch information
Ndiritu authored Jul 10, 2023
2 parents 8e5bda3 + db95402 commit 8d5b6b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ parameters:
polluteScopeWithLoopInitialAssignments: false
paths:
- src
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '/^Parameter #1 \$[A-Za-z_0-9]+ of function is_subclass_of expects object\|string, mixed given.$/'
2 changes: 1 addition & 1 deletion src/Types/TypeUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function validateCollectionValues($values, string $type): void
if (is_array($values)) {
foreach ($values as $value) {
$debugType = get_debug_type($value);
if ($type !== $debugType) {
if ($type !== $debugType && !is_subclass_of($value, $type)) {
throw new UnexpectedValueException("Collection of type=$type contains value of type=$debugType");
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Types/TypeUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,23 @@ public function testInvalidValueThrowsException(): void
}
}
}

public function testValidationWithChildClasses(): void
{
$this->expectNotToPerformAssertions();
TypeUtils::validateCollectionValues([new ChildCustomType(), new ChildCustomType()], TestCustomType::class);
TypeUtils::validateCollectionValues([new ChildCustomType(), new ChildCustomType()], TestInterface::class);
}
}

class TestCustomType {

}

class ChildCustomType extends TestCustomType implements TestInterface {

}

interface TestInterface {

}

0 comments on commit 8d5b6b9

Please sign in to comment.