File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
src/Illuminate/Validation/Rules Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -34,14 +34,14 @@ public function __construct($type)
3434 */
3535 public function passes ($ attribute , $ value )
3636 {
37- if (is_null ($ value ) || ! function_exists ('enum_exists ' ) || ! enum_exists ($ this ->type ) || ! method_exists ($ this ->type , 'tryFrom ' )) {
38- return false ;
39- }
40-
4137 if ($ value instanceof $ this ->type ) {
4238 return true ;
4339 }
4440
41+ if (is_null ($ value ) || ! function_exists ('enum_exists ' ) || ! enum_exists ($ this ->type ) || ! method_exists ($ this ->type , 'tryFrom ' )) {
42+ return false ;
43+ }
44+
4545 try {
4646 return ! is_null ($ this ->type ::tryFrom ($ value ));
4747 } catch (TypeError $ e ) {
Original file line number Diff line number Diff line change @@ -52,6 +52,21 @@ public function testvalidationPassesWhenPassingInstanceOfEnum()
5252 $ this ->assertFalse ($ v ->fails ());
5353 }
5454
55+ public function testvalidationPassesWhenPassingInstanceOfPureEnum ()
56+ {
57+ $ v = new Validator (
58+ resolve ('translator ' ),
59+ [
60+ 'status ' => PureEnum::one,
61+ ],
62+ [
63+ 'status ' => new Enum (PureEnum::class),
64+ ]
65+ );
66+
67+ $ this ->assertFalse ($ v ->fails ());
68+ }
69+
5570 public function testValidationFailsWhenProvidingNoExistingCases ()
5671 {
5772 $ v = new Validator (
You can’t perform that action at this time.
0 commit comments