44
55use PHPUnit \Framework \Attributes \DataProvider ;
66use ProgrammatorDev \YetAnotherPhpValidator \Exception \NotBlankException ;
7+ use ProgrammatorDev \YetAnotherPhpValidator \Exception \Util \FormatValueTrait ;
78use ProgrammatorDev \YetAnotherPhpValidator \Validator ;
89
910class NotBlankTest extends AbstractTest
1011{
11- #[DataProvider('provideInvalidInputData ' )]
12- public function testNotBlankInvalidInput (mixed $ input )
12+ use FormatValueTrait;
13+
14+ #[DataProvider('provideInvalidValueData ' )]
15+ public function testNotBlankInvalidValue (mixed $ value )
1316 {
1417 $ validator = Validator::notBlank ();
1518
16- $ this ->assertFalse ($ validator ->validate ($ input ));
19+ $ this ->assertFalse ($ validator ->validate ($ value ));
1720
1821 $ this ->expectException (NotBlankException::class);
19- $ this ->expectExceptionMessage ('The "test" value should not be blank. ' );
20- $ validator ->assert ($ input , 'test ' );
22+ $ this ->expectExceptionMessage (
23+ \sprintf ('The "test" value should not be blank, "%s" given. ' , $ this ->formatValue ($ value ))
24+ );
25+ $ validator ->assert ($ value , 'test ' );
2126 }
2227
23- public static function provideInvalidInputData (): \Generator
28+ public static function provideInvalidValueData (): \Generator
2429 {
2530 yield 'null ' => [null ];
2631 yield 'false ' => [false ];
27- yield 'blank array ' => [[]];
2832 yield 'blank string ' => ['' ];
29- yield 'whitespace ' => [' ' ];
33+ yield 'blank array ' => [[] ];
3034 }
3135
32- #[DataProvider('provideValidInputData ' )]
33- public function testNotBlankValidInput (mixed $ input )
36+ #[DataProvider('provideValidValueData ' )]
37+ public function testNotBlankValidValue (mixed $ value )
3438 {
3539 $ validator = Validator::notBlank ();
3640
37- $ this ->assertTrue ($ validator ->validate ($ input ));
41+ $ this ->assertTrue ($ validator ->validate ($ value ));
3842
39- Validator:: notBlank () ->assert ($ input , 'test ' );
43+ $ validator ->assert ($ value , 'test ' );
4044 }
4145
42- public static function provideValidInputData (): \Generator
46+ public static function provideValidValueData (): \Generator
4347 {
4448 yield 'true ' => [true ];
45- yield 'zero number ' => [0 ];
46- yield 'zero string ' => ['0 ' ];
47- yield 'array ' => [[0 ]];
49+
4850 yield 'string ' => ['string ' ];
51+ yield 'whitespace string ' => [' ' ];
52+ yield 'zero string ' => ['0 ' ];
53+
54+ yield 'array ' => [['string ' ]];
55+ yield 'blank string array ' => [['' ]];
56+ yield 'whitespace array ' => [[' ' ]];
57+ yield 'zero array ' => [[0 ]];
58+
59+ yield 'number ' => [10 ];
60+ yield 'zero number ' => [0 ];
4961 }
5062
5163 public function testNotBlankExceptionMessageParameters ()
5264 {
53- $ this ->expectExceptionMessage ('The "test" value false is invalid. Must not be blank. ' );
65+ $ this ->expectExceptionMessage ('The "test" value " false" is invalid. Must not be blank. ' );
5466
55- Validator:: notBlank (
56- message: 'The {{ name }} value {{ input }} is invalid. Must not be blank. '
57- ) ->assert (false , 'test ' );
67+ Validator
68+ :: notBlank ( message: 'The " {{ name }}" value " {{ value }}" is invalid. Must not be blank. ' )
69+ ->assert (false , 'test ' );
5870 }
5971}
0 commit comments