|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Nuxtifyts\PhpDto\Tests\Unit\Validation\Logical; |
| 4 | + |
| 5 | +use Nuxtifyts\PhpDto\Exceptions\LogicalRuleException; |
| 6 | +use Nuxtifyts\PhpDto\Validation\Contracts\RuleEvaluator; |
| 7 | +use Nuxtifyts\PhpDto\Validation\Logic\LogicalRule; |
| 8 | +use Nuxtifyts\PhpDto\Validation\Logic\TruthyRule; |
| 9 | +use Nuxtifyts\PhpDto\Validation\Rules\StringRule; |
| 10 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 11 | +use PHPUnit\Framework\Attributes\UsesClass; |
| 12 | +use Throwable; |
| 13 | + |
| 14 | +#[CoversClass(TruthyRule::class)] |
| 15 | +#[CoversClass(LogicalRuleException::class)] |
| 16 | +#[UsesClass(StringRule::class)] |
| 17 | +final class TruthyRuleTest extends LogicalRuleTestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @return array<string, array{ |
| 21 | + * logicalRuleClassString: class-string<LogicalRule>, |
| 22 | + * ruleEvaluators: list<RuleEvaluator>, |
| 23 | + * expectedCreateException: ?class-string<LogicalRuleException>, |
| 24 | + * valueToBeEvaluated: mixed, |
| 25 | + * expectedResult: bool, |
| 26 | + * expectedValidationMessageTree: array<string, mixed> |
| 27 | + * }> |
| 28 | + * |
| 29 | + * @throws Throwable |
| 30 | + */ |
| 31 | + public static function data_provider(): array |
| 32 | + { |
| 33 | + return [ |
| 34 | + 'Will always return true when validating' => [ |
| 35 | + 'logicalRuleClassString' => TruthyRule::class, |
| 36 | + 'ruleEvaluators' => [], |
| 37 | + 'expectedCreateException' => null, |
| 38 | + 'valueToBeEvaluated' => 'string', |
| 39 | + 'expectedResult' => true, |
| 40 | + 'expectedValidationMessageTree' => [] |
| 41 | + ], |
| 42 | + 'Will throw an exception if trying to add a nested rule' => [ |
| 43 | + 'logicalRuleClassString' => TruthyRule::class, |
| 44 | + 'ruleEvaluators' => [ |
| 45 | + StringRule::make(), |
| 46 | + ], |
| 47 | + 'expectedCreateException' => LogicalRuleException::class, |
| 48 | + 'valueToBeEvaluated' => 1234, |
| 49 | + 'expectedResult' => true, |
| 50 | + 'expectedValidationMessageTree' => [] |
| 51 | + ] |
| 52 | + ]; |
| 53 | + } |
| 54 | +} |
0 commit comments