Skip to content

Commit f735e12

Browse files
committed
Fix enum rule with int enum but value in string (xml)
1 parent acf9411 commit f735e12

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Rules/EnumRule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public function passes(mixed $value): bool
3636
try {
3737
return $this->enum::tryFrom($value) !== null;
3838
} catch (TypeError) {
39-
return false;
39+
try {
40+
return $this->enum::tryFrom((int) $value) !== null;
41+
} catch (TypeError) {
42+
return false;
43+
}
4044
}
4145
}
4246
}

tests/Rules/EnumRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testString(string|int|array|float|null|bool $arg, bool $expected
2828

2929
public function dataInt(): array
3030
{
31-
return [[1, true], [1, true], [3, false], ['', false], [[], false]];
31+
return [[1, true], ['1', true], [3, false], ['3', false], ['', false], [[], false]];
3232
}
3333

3434
/**

0 commit comments

Comments
 (0)