This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ProgrammatorDev \YetAnotherPhpValidator \Test \Util ;
4+
5+ use PHPUnit \Framework \Attributes \DataProvider ;
6+ use ProgrammatorDev \YetAnotherPhpValidator \Rule \RuleInterface ;
7+
8+ trait TestRuleCustomMessageTrait
9+ {
10+ public static abstract function provideRuleCustomMessageData (): \Generator ;
11+
12+ #[DataProvider('provideRuleCustomMessageData ' )]
13+ public function testRuleCustomMessage (RuleInterface $ rule , mixed $ value , string $ exceptionMessage ): void
14+ {
15+ $ this ->expectExceptionMessage ($ exceptionMessage );
16+ $ rule ->assert ($ value , 'test ' );
17+ }
18+ }
Original file line number Diff line number Diff line change 44
55use ProgrammatorDev \YetAnotherPhpValidator \Exception \GreaterThanException ;
66use ProgrammatorDev \YetAnotherPhpValidator \Rule \GreaterThan ;
7+ use ProgrammatorDev \YetAnotherPhpValidator \Test \Util \TestRuleCustomMessageTrait ;
78use ProgrammatorDev \YetAnotherPhpValidator \Test \Util \TestRuleFailureConditionTrait ;
89use ProgrammatorDev \YetAnotherPhpValidator \Test \Util \TestRuleSuccessConditionTrait ;
910
1011class GreaterThanTest extends AbstractTest
1112{
1213 use TestRuleFailureConditionTrait;
1314 use TestRuleSuccessConditionTrait;
15+ use TestRuleCustomMessageTrait;
1416
1517 public static function provideRuleFailureConditionData (): \Generator
1618 {
@@ -46,4 +48,14 @@ public static function provideRuleSuccessConditionData(): \Generator
4648 yield 'int with float ' => [new GreaterThan (10 ), 20.0 ];
4749 yield 'string ' => [new GreaterThan ('a ' ), 'z ' ];
4850 }
51+
52+ public static function provideRuleCustomMessageData (): \Generator
53+ {
54+ yield 'message ' => [
55+ new GreaterThan (
56+ constraint: 10 ,
57+ message: 'The "{{ name }}" value "{{ value }}" is not greater than "{{ constraint }}". '
58+ ), 1 , 'The "test" value "1" is not greater than "10". '
59+ ];
60+ }
4961}
Original file line number Diff line number Diff line change 44
55use ProgrammatorDev \YetAnotherPhpValidator \Exception \NotBlankException ;
66use ProgrammatorDev \YetAnotherPhpValidator \Rule \NotBlank ;
7+ use ProgrammatorDev \YetAnotherPhpValidator \Test \Util \TestRuleCustomMessageTrait ;
78use ProgrammatorDev \YetAnotherPhpValidator \Test \Util \TestRuleFailureConditionTrait ;
89use ProgrammatorDev \YetAnotherPhpValidator \Test \Util \TestRuleSuccessConditionTrait ;
910
1011class NotBlankTest extends AbstractTest
1112{
1213 use TestRuleFailureConditionTrait;
1314 use TestRuleSuccessConditionTrait;
15+ use TestRuleCustomMessageTrait;
1416
1517 public static function provideRuleFailureConditionData (): \Generator
1618 {
@@ -39,4 +41,13 @@ public static function provideRuleSuccessConditionData(): \Generator
3941 yield 'number ' => [new NotBlank (), 10 ];
4042 yield 'zero number ' => [new NotBlank (), 0 ];
4143 }
44+
45+ public static function provideRuleCustomMessageData (): \Generator
46+ {
47+ yield 'message ' => [
48+ new NotBlank (
49+ message: 'The "{{ name }}" value "{{ value }}" is not blank. '
50+ ), '' , 'The "test" value "" is not blank. '
51+ ];
52+ }
4253}
You can’t perform that action at this time.
0 commit comments