1
+ <?php
2
+
3
+ namespace ProgrammatorDev \Validator \Test ;
4
+
5
+ use ProgrammatorDev \Validator \Exception \BlankException ;
6
+ use ProgrammatorDev \Validator \Rule \Blank ;
7
+ use ProgrammatorDev \Validator \Test \Util \TestRuleMessageOptionTrait ;
8
+ use ProgrammatorDev \Validator \Test \Util \TestRuleFailureConditionTrait ;
9
+ use ProgrammatorDev \Validator \Test \Util \TestRuleSuccessConditionTrait ;
10
+
11
+ class BlankTest extends AbstractTest
12
+ {
13
+ use TestRuleFailureConditionTrait;
14
+ use TestRuleSuccessConditionTrait;
15
+ use TestRuleMessageOptionTrait;
16
+
17
+ public static function provideRuleFailureConditionData (): \Generator
18
+ {
19
+ $ exception = BlankException::class;
20
+ $ message = '/The (.*) value should be blank, (.*) given\./ ' ;
21
+
22
+ yield 'true ' => [new Blank (), true , $ exception , $ message ];
23
+
24
+ yield 'string ' => [new Blank (), 'string ' , $ exception , $ message ];
25
+ yield 'whitespace string ' => [new Blank (), ' ' , $ exception , $ message ];
26
+ yield 'zero string ' => [new Blank (), '0 ' , $ exception , $ message ];
27
+
28
+ yield 'array ' => [new Blank (), ['string ' ], $ exception , $ message ];
29
+ yield 'blank string array ' => [new Blank (), ['' ], $ exception , $ message ];
30
+ yield 'whitespace array ' => [new Blank (), [' ' ], $ exception , $ message ];
31
+ yield 'zero array ' => [new Blank (), [0 ], $ exception , $ message ];
32
+
33
+ yield 'number ' => [new Blank (), 10 , $ exception , $ message ];
34
+ yield 'zero number ' => [new Blank (), 0 , $ exception , $ message ];
35
+ }
36
+
37
+ public static function provideRuleSuccessConditionData (): \Generator
38
+ {
39
+ yield 'null ' => [new Blank (), null ];
40
+ yield 'false ' => [new Blank (), false ];
41
+ yield 'blank string ' => [new Blank (), '' ];
42
+ yield 'blank array ' => [new Blank (), []];
43
+
44
+ yield 'normalizer whitespace ' => [new Blank (normalizer: 'trim ' ), ' ' ];
45
+ yield 'normalizer whitespace function ' => [new Blank (normalizer: fn ($ value ) => trim ($ value )), ' ' ];
46
+ }
47
+
48
+ public static function provideRuleMessageOptionData (): \Generator
49
+ {
50
+ yield 'message ' => [
51
+ new Blank (message: '{{ name }} | {{ value }} ' ),
52
+ 'string ' ,
53
+ 'test | "string" '
54
+ ];
55
+ }
56
+ }
0 commit comments