1+ <?php
2+
3+ namespace ProgrammatorDev \YetAnotherPhpValidator \Test ;
4+
5+ use PHPUnit \Framework \Attributes \DataProvider ;
6+ use ProgrammatorDev \YetAnotherPhpValidator \Exception \NotBlankException ;
7+ use ProgrammatorDev \YetAnotherPhpValidator \Validator ;
8+
9+ class NotBlankTest extends AbstractTest
10+ {
11+ #[DataProvider('provideInvalidInputData ' )]
12+ public function testNotBlankInvalidInput (mixed $ input )
13+ {
14+ $ validator = Validator::notBlank ();
15+
16+ $ this ->assertFalse ($ validator ->validate ($ input ));
17+
18+ $ this ->expectException (NotBlankException::class);
19+ $ this ->expectExceptionMessage ('The "test" value should not be blank. ' );
20+ $ validator ->assert ($ input , 'test ' );
21+ }
22+
23+ public static function provideInvalidInputData (): \Generator
24+ {
25+ yield 'null ' => [null ];
26+ yield 'false ' => [false ];
27+ yield 'blank array ' => [[]];
28+ yield 'blank string ' => ['' ];
29+ yield 'whitespace ' => [' ' ];
30+ }
31+
32+ #[DataProvider('provideValidInputData ' )]
33+ public function testNotBlankValidInput (mixed $ input )
34+ {
35+ $ validator = Validator::notBlank ();
36+
37+ $ this ->assertTrue ($ validator ->validate ($ input ));
38+
39+ Validator::notBlank ()->assert ($ input , 'test ' );
40+ }
41+
42+ public static function provideValidInputData (): \Generator
43+ {
44+ yield 'true ' => [true ];
45+ yield 'zero number ' => [0 ];
46+ yield 'zero string ' => ['0 ' ];
47+ yield 'array ' => [[0 ]];
48+ yield 'string ' => ['string ' ];
49+ }
50+
51+ public function testNotBlankExceptionMessageParameters ()
52+ {
53+ $ this ->expectExceptionMessage ('The "test" value false is invalid. Must not be blank. ' );
54+
55+ Validator::notBlank (
56+ message: 'The {{ name }} value {{ input }} is invalid. Must not be blank. '
57+ )->assert (false , 'test ' );
58+ }
59+ }
0 commit comments