22
33namespace Nuxtifyts \PhpDto \Tests \Unit \Validation ;
44
5- use Nuxtifyts \PhpDto \Validation \Rules \DateRule ;
6- use PHPUnit \Framework \Attributes \CoversClass ;
7- use PHPUnit \Framework \Attributes \Test ;
85use Throwable ;
6+ use PHPUnit \Framework \Attributes \Test ;
7+ use PHPUnit \Framework \Attributes \CoversClass ;
8+ use Nuxtifyts \PhpDto \Validation \Rules \DateRule ;
9+ use Nuxtifyts \PhpDto \Exceptions \ValidationRuleException ;
10+ use Nuxtifyts \PhpDto \Validation \Rules \ValidationRule ;
911
1012#[CoversClass(DateRule::class)]
13+ #[CoversClass(ValidationRuleException::class)]
1114final class DateRuleTest extends ValidationRuleTestCase
1215{
1316 /**
@@ -24,8 +27,8 @@ public function validate_validation_message(): void
2427 );
2528 }
2629
27- /**
28- * @return array<string, array{
30+ /**
31+ * @return array<string, array{
2932 * validationRuleClassString: class-string<ValidationRule>,
3033 * makeParams: ?array<string, mixed>,
3134 * expectedMakeException: ?class-string<ValidationRuleException>,
@@ -64,6 +67,27 @@ public static function data_provider(): array
6467 'valueToBeEvaluated ' => '2021-01-01 00:00:00 ' ,
6568 'expectedResult ' => true
6669 ],
70+ 'Will evaluate false when a custom datetime string is provided but no formats are set ' => [
71+ 'validationRuleClassString ' => DateRule::class,
72+ 'makeParams ' => null ,
73+ 'expectedMakeException ' => null ,
74+ 'valueToBeEvaluated ' => '2021/01-01 00/00/00 ' ,
75+ 'expectedResult ' => false
76+ ],
77+ 'Will evaluate true when a custom datetime string is provided and a format is set ' => [
78+ 'validationRuleClassString ' => DateRule::class,
79+ 'makeParams ' => ['formats ' => ['Y/m-d H/m/s ' ]],
80+ 'expectedMakeException ' => null ,
81+ 'valueToBeEvaluated ' => '2021/01-01 00/00/00 ' ,
82+ 'expectedResult ' => true
83+ ],
84+ 'Will throw an exception when an invalid non string format is passed ' => [
85+ 'validationRuleClassString ' => DateRule::class,
86+ 'makeParams ' => ['formats ' => ['Y/m-d H/m/s ' , 123 ]],
87+ 'expectedMakeException ' => ValidationRuleException::class,
88+ 'valueToBeEvaluated ' => '2021/01-01 00/00/00 ' ,
89+ 'expectedResult ' => false
90+ ],
6791 ];
6892 }
6993}
0 commit comments