Skip to content

Commit

Permalink
Fix enum rule with int enum but value in string (xml)
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Aug 23, 2022
1 parent acf9411 commit f735e12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Rules/EnumRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public function passes(mixed $value): bool
try {
return $this->enum::tryFrom($value) !== null;
} catch (TypeError) {
return false;
try {
return $this->enum::tryFrom((int) $value) !== null;
} catch (TypeError) {
return false;
}
}
}
}
2 changes: 1 addition & 1 deletion tests/Rules/EnumRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testString(string|int|array|float|null|bool $arg, bool $expected

public function dataInt(): array
{
return [[1, true], [1, true], [3, false], ['', false], [[], false]];
return [[1, true], ['1', true], [3, false], ['3', false], ['', false], [[], false]];
}

/**
Expand Down

0 comments on commit f735e12

Please sign in to comment.