@@ -37,14 +37,15 @@ public static function provideRuleUnexpectedValueData(): \Generator
3737 public static function provideRuleFailureConditionData (): \Generator
3838 {
3939 $ exception = CollectionException::class;
40+ $ notBlankMessage = '/The "(.*)" value should not be blank, "" given\./ ' ;
4041 $ extraFieldsMessage = '/The (.*) field is not allowed\./ ' ;
4142 $ missingFieldsMessage = '/The (.*) field is missing\./ ' ;
4243
4344 yield 'invalid field ' => [
4445 new Collection (fields: ['field ' => Validator::notBlank ()]),
4546 ['field ' => '' ],
4647 $ exception ,
47- ' /The "(.*)" value should not be blank, "" given\./ '
48+ $ notBlankMessage
4849 ];
4950 yield 'extra fields ' => [
5051 new Collection (fields: ['field ' => Validator::notBlank ()]),
@@ -53,16 +54,25 @@ public static function provideRuleFailureConditionData(): \Generator
5354 $ extraFieldsMessage
5455 ];
5556 yield 'missing fields ' => [
56- new Collection (
57- fields: [
58- 'field1 ' => Validator::notBlank (),
59- 'field2 ' => Validator::notBlank ()
60- ]
61- ),
57+ new Collection (fields: [
58+ 'field1 ' => Validator::notBlank (),
59+ 'field2 ' => Validator::notBlank ()
60+ ]),
6261 ['field1 ' => 'value1 ' ],
6362 $ exception ,
6463 $ missingFieldsMessage
6564 ];
65+ yield 'optional ' => [
66+ new Collection (fields: [
67+ 'field ' => Validator::notBlank (),
68+ 'optional ' => Validator::optional (
69+ Validator::notBlank ()
70+ )
71+ ]),
72+ ['field ' => 'value ' , 'optional ' => '' ],
73+ $ exception ,
74+ $ notBlankMessage
75+ ];
6676 }
6777
6878 public static function provideRuleSuccessConditionData (): \Generator
@@ -82,6 +92,24 @@ public static function provideRuleSuccessConditionData(): \Generator
8292 ),
8393 ['field ' => 'value ' , 'extrafield ' => 'extravalue ' ]
8494 ];
95+ yield 'optional ' => [
96+ new Collection (fields: [
97+ 'field ' => Validator::notBlank (),
98+ 'optional ' => Validator::optional (
99+ Validator::notBlank ()
100+ )
101+ ]),
102+ ['field ' => 'value ' ]
103+ ];
104+ yield 'optional null ' => [
105+ new Collection (fields: [
106+ 'field ' => Validator::notBlank (),
107+ 'optional ' => Validator::optional (
108+ Validator::notBlank ()
109+ )
110+ ]),
111+ ['field ' => 'value ' , 'optional ' => null ]
112+ ];
85113 }
86114
87115 public static function provideRuleMessageOptionData (): \Generator
0 commit comments