1
+ <?php
2
+
3
+ namespace ProgrammatorDev \Validator \Test ;
4
+
5
+ use ProgrammatorDev \Validator \Exception \IsNullException ;
6
+ use ProgrammatorDev \Validator \Rule \IsNull ;
7
+ use ProgrammatorDev \Validator \Test \Util \TestRuleFailureConditionTrait ;
8
+ use ProgrammatorDev \Validator \Test \Util \TestRuleMessageOptionTrait ;
9
+ use ProgrammatorDev \Validator \Test \Util \TestRuleSuccessConditionTrait ;
10
+
11
+ class IsNullTest extends AbstractTest
12
+ {
13
+ use TestRuleFailureConditionTrait;
14
+ use TestRuleSuccessConditionTrait;
15
+ use TestRuleMessageOptionTrait;
16
+
17
+ public static function provideRuleFailureConditionData (): \Generator
18
+ {
19
+ $ exception = IsNullException::class;
20
+ $ message = '/The (.*) value should be null, (.*) given\./ ' ;
21
+
22
+ yield 'int ' => [new IsNull (), 1 , $ exception , $ message ];
23
+ yield 'string ' => [new IsNull (), 'string ' , $ exception , $ message ];
24
+ yield 'bool ' => [new IsNull (), true , $ exception , $ message ];
25
+ yield 'array ' => [new IsNull (), [], $ exception , $ message ];
26
+ }
27
+
28
+ public static function provideRuleSuccessConditionData (): \Generator
29
+ {
30
+ yield 'null ' => [new IsNull (), null ];
31
+ }
32
+
33
+ public static function provideRuleMessageOptionData (): \Generator
34
+ {
35
+ yield 'message ' => [
36
+ new IsNull (
37
+ message: '{{ name }} | {{ value }} '
38
+ ),
39
+ 'string ' ,
40
+ 'test | "string" '
41
+ ];
42
+ }
43
+ }
0 commit comments