File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
src/Illuminate/Validation/Rules Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ class RequiredIf
19
19
*/
20
20
public function __construct ($ condition )
21
21
{
22
- $ this ->condition = $ condition ;
22
+ if (!is_string ($ condition ) && (is_bool ($ condition ) || is_callable ($ condition ))) {
23
+ $ this ->condition = $ condition ;
24
+ } else {
25
+ throw new InvalidArgumentException ("Condition type must be 'callable' or 'bool'. " );
26
+ }
23
27
}
24
28
25
29
/**
Original file line number Diff line number Diff line change @@ -29,4 +29,30 @@ public function testItClousureReturnsFormatsAStringVersionOfTheRule()
29
29
30
30
$ this ->assertSame ('' , (string ) $ rule );
31
31
}
32
+
33
+ public function testItOnlyCallableAndBooleanAreAcceptableArgumentsOfTheRule ()
34
+ {
35
+ $ rule = new RequiredIf (false );
36
+
37
+ $ rule = new RequiredIf (true );
38
+
39
+ $ this ->expectException (InvalidArgumentException::class);
40
+
41
+ $ rule = new RequiredIf ('phpinfo ' );
42
+
43
+ $ rule = new RequiredIf (12.3 );
44
+
45
+ $ rule = new RequiredIf (new stdClass ());
46
+ }
47
+
48
+ public function testItReturnedRuleIsNotSerializable ()
49
+ {
50
+ $ this ->expectException (Exception::class);
51
+
52
+ $ rule = serialize (new RequiredIf (function () {
53
+ return true ;
54
+ }));
55
+
56
+ $ rule = serialize (new RequiredIf ());
57
+ }
32
58
}
You can’t perform that action at this time.
0 commit comments