|
7 | 7 | use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleMessageOptionTrait; |
8 | 8 | use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleFailureConditionTrait; |
9 | 9 | use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleSuccessConditionTrait; |
| 10 | +use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleUnexpectedValueTrait; |
10 | 11 |
|
11 | 12 | class GreaterThanTest extends AbstractTest |
12 | 13 | { |
| 14 | + use TestRuleUnexpectedValueTrait; |
13 | 15 | use TestRuleFailureConditionTrait; |
14 | 16 | use TestRuleSuccessConditionTrait; |
15 | 17 | use TestRuleMessageOptionTrait; |
16 | 18 |
|
| 19 | + public static function provideRuleUnexpectedValueData(): \Generator |
| 20 | + { |
| 21 | + $exceptionMessage = '/Cannot compare a type "(.*)" with a type "(.*)"/'; |
| 22 | + |
| 23 | + yield 'datetime constraint with int value' => [new GreaterThan(new \DateTime()), 10, $exceptionMessage]; |
| 24 | + yield 'datetime constraint with float value' => [new GreaterThan(new \DateTime()), 1.0, $exceptionMessage]; |
| 25 | + yield 'datetime constraint with string value' => [new GreaterThan(new \DateTime()), 'a', $exceptionMessage]; |
| 26 | + yield 'int constraint with string value' => [new GreaterThan(10), 'a', $exceptionMessage]; |
| 27 | + yield 'float constraint with string value' => [new GreaterThan(1.0), 'a', $exceptionMessage]; |
| 28 | + yield 'array constraint' => [new GreaterThan([10]), 10, $exceptionMessage]; |
| 29 | + yield 'null constraint' => [new GreaterThan(null), 10, $exceptionMessage]; |
| 30 | + } |
| 31 | + |
17 | 32 | public static function provideRuleFailureConditionData(): \Generator |
18 | 33 | { |
19 | 34 | $exception = GreaterThanException::class; |
20 | | - $exceptionMessageInvalid = '/Cannot compare a type "(.*)" with a type "(.*)"/'; |
21 | | - $exceptionMessageFailure = '/The "(.*)" value should be greater than "(.*)", "(.*)" given./'; |
22 | | - |
23 | | - yield 'datetime constraint with int value' => [new GreaterThan(new \DateTime()), 10, $exception, $exceptionMessageInvalid]; |
24 | | - yield 'datetime constraint with float value' => [new GreaterThan(new \DateTime()), 1.0, $exception, $exceptionMessageInvalid]; |
25 | | - yield 'datetime constraint with string value' => [new GreaterThan(new \DateTime()), 'a', $exception, $exceptionMessageInvalid]; |
26 | | - yield 'int constraint with string value' => [new GreaterThan(10), 'a', $exception, $exceptionMessageInvalid]; |
27 | | - yield 'float constraint with string value' => [new GreaterThan(1.0), 'a', $exception, $exceptionMessageInvalid]; |
28 | | - yield 'array constraint' => [new GreaterThan([10]), 10, $exception, $exceptionMessageInvalid]; |
29 | | - yield 'null constraint' => [new GreaterThan(null), 10, $exception, $exceptionMessageInvalid]; |
30 | | - |
31 | | - yield 'datetime' => [new GreaterThan(new \DateTime('today')), new \DateTime('yesterday'), $exception, $exceptionMessageFailure]; |
32 | | - yield 'same datetime' => [new GreaterThan(new \DateTime('today')), new \DateTime('today'), $exception, $exceptionMessageFailure]; |
33 | | - yield 'int' => [new GreaterThan(10), 1, $exception, $exceptionMessageFailure]; |
34 | | - yield 'same int' => [new GreaterThan(10), 10, $exception, $exceptionMessageFailure]; |
35 | | - yield 'float' => [new GreaterThan(10.0), 1.0, $exception, $exceptionMessageFailure]; |
36 | | - yield 'same float' => [new GreaterThan(10.0), 10.0, $exception, $exceptionMessageFailure]; |
37 | | - yield 'int with float' => [new GreaterThan(10), 1.0, $exception, $exceptionMessageFailure]; |
38 | | - yield 'same int with float' => [new GreaterThan(10), 10.0, $exception, $exceptionMessageFailure]; |
39 | | - yield 'string' => [new GreaterThan('z'), 'a', $exception, $exceptionMessageFailure]; |
40 | | - yield 'same string' => [new GreaterThan('a'), 'a', $exception, $exceptionMessageFailure]; |
| 35 | + $exceptionMessage = '/The "(.*)" value should be greater than "(.*)", "(.*)" given./'; |
| 36 | + |
| 37 | + yield 'datetime' => [new GreaterThan(new \DateTime('today')), new \DateTime('yesterday'), $exception, $exceptionMessage]; |
| 38 | + yield 'same datetime' => [new GreaterThan(new \DateTime('today')), new \DateTime('today'), $exception, $exceptionMessage]; |
| 39 | + yield 'int' => [new GreaterThan(10), 1, $exception, $exceptionMessage]; |
| 40 | + yield 'same int' => [new GreaterThan(10), 10, $exception, $exceptionMessage]; |
| 41 | + yield 'float' => [new GreaterThan(10.0), 1.0, $exception, $exceptionMessage]; |
| 42 | + yield 'same float' => [new GreaterThan(10.0), 10.0, $exception, $exceptionMessage]; |
| 43 | + yield 'int with float' => [new GreaterThan(10), 1.0, $exception, $exceptionMessage]; |
| 44 | + yield 'same int with float' => [new GreaterThan(10), 10.0, $exception, $exceptionMessage]; |
| 45 | + yield 'string' => [new GreaterThan('z'), 'a', $exception, $exceptionMessage]; |
| 46 | + yield 'same string' => [new GreaterThan('a'), 'a', $exception, $exceptionMessage]; |
41 | 47 | } |
42 | 48 |
|
43 | 49 | public static function provideRuleSuccessConditionData(): \Generator |
|
0 commit comments