|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MintyPHP\Tests\Validators; |
| 4 | + |
| 5 | +use MintyPHP\Form\Validator\Validators; |
| 6 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +class ExpressionValidatorTest extends TestCase |
| 10 | +{ |
| 11 | + public static function expressionDataProvider(): array |
| 12 | + { |
| 13 | + return [ |
| 14 | + ['10', '>', '9', true], |
| 15 | + ['10', '>=', '10', true], |
| 16 | + ['10', '<', '11', true], |
| 17 | + ['10', '<=', '10', true], |
| 18 | + ['10.5', '>', '9.5', true], |
| 19 | + ['10.5', '<=', '10.5', true], |
| 20 | + ['10.5', '>=', '10.5', true], |
| 21 | + ['10.5', '<', '10.5', false], |
| 22 | + ['10.5', '>', '10.5', false], |
| 23 | + ['10.5', '<=', '9.5', false], |
| 24 | + ['10.5', '>=', '11.5', false], |
| 25 | + ['10.5', '<', '11.5', true], |
| 26 | + ['10.5', '>=', '9.5', true], |
| 27 | + ['10.5', '<=', '9.99999', false], |
| 28 | + ['9.99999', '<=', '11.0', true], |
| 29 | + ]; |
| 30 | + } |
| 31 | + |
| 32 | + #[DataProvider('expressionDataProvider')] |
| 33 | + public function testValidExpression(string $input, string $comperator, string $value, bool $expected): void |
| 34 | + { |
| 35 | + $validator = Validators::expression($comperator, $value, 'invalid value'); |
| 36 | + $this->assertEquals($validator->validate($input) === '', $expected); |
| 37 | + } |
| 38 | +} |
0 commit comments