33namespace ProgrammatorDev \YetAnotherPhpValidator \Test ;
44
55use PHPUnit \Framework \Attributes \DataProvider ;
6+ use ProgrammatorDev \YetAnotherPhpValidator \Exception \UnexpectedValueException ;
67use ProgrammatorDev \YetAnotherPhpValidator \Exception \ValidationException ;
78use ProgrammatorDev \YetAnotherPhpValidator \Rule \GreaterThan ;
89use ProgrammatorDev \YetAnotherPhpValidator \Rule \LessThan ;
1213
1314class ValidatorTest extends AbstractTest
1415{
16+ public function testValidatorRequiredRules ()
17+ {
18+ $ this ->expectException (UnexpectedValueException::class);
19+ $ this ->expectExceptionMessage ('Validator rules not found: at least one rule is required. ' );
20+
21+ $ validator = new Validator ();
22+ $ validator ->assert (true , 'test ' );
23+ }
24+
1525 #[DataProvider('provideValidatorUsageApproachData ' )]
1626 public function testValidatorGetRules (Validator $ validator )
1727 {
@@ -23,7 +33,6 @@ public function testValidatorGetRules(Validator $validator)
2333 public function testValidatorFailureCondition (Validator $ validator )
2434 {
2535 $ this ->assertFalse ($ validator ->validate (false ));
26-
2736 $ this ->expectException (ValidationException::class);
2837 $ validator ->assert (false , 'test ' );
2938 }
@@ -32,7 +41,6 @@ public function testValidatorFailureCondition(Validator $validator)
3241 public function testValidatorSuccessCondition (Validator $ validator )
3342 {
3443 $ this ->assertTrue ($ validator ->validate (15 ));
35-
3644 $ validator ->assert (15 , 'test ' );
3745 }
3846
@@ -52,7 +60,7 @@ public static function provideValidatorUsageApproachData(): \Generator
5260 )
5361 ];
5462 yield 'method approach ' => [
55- (new Validator () )
63+ (new Validator )
5664 ->addRule (new NotBlank ())
5765 ->addRule (new GreaterThan (10 ))
5866 ->addRule (new LessThan (20 ))
0 commit comments