CurrencyTest.php
3 years ago
EmailTest.php
3 years ago
IntegerTest.php
3 years ago
MaxTest.php
3 years ago
MinTest.php
3 years ago
NumericTest.php
3 years ago
RequiredTest.php
3 years ago
SizeTest.php
3 years ago
MinTest.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace StellarWP\Validation\Tests\Unit\Rules; |
| 6 | |
| 7 | use InvalidArgumentException; |
| 8 | use StellarWP\Validation\Exceptions\ValidationException; |
| 9 | use StellarWP\Validation\Rules\Min; |
| 10 | use StellarWP\Validation\Tests\TestCase; |
| 11 | |
| 12 | class MinTest extends TestCase |
| 13 | { |
| 14 | /** |
| 15 | * @dataProvider validationsProvider |
| 16 | */ |
| 17 | public function testRuleValidations($value, $shouldPass) |
| 18 | { |
| 19 | $rule = new Min(3); |
| 20 | |
| 21 | if ( $shouldPass ) { |
| 22 | self::assertValidationRulePassed($rule, $value); |
| 23 | } else { |
| 24 | self::assertValidationRuleFailed($rule, $value); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | public function validationsProvider(): array |
| 29 | { |
| 30 | return [ |
| 31 | // numbers |
| 32 | [5, true], |
| 33 | [3, true], |
| 34 | [3.3, true], |
| 35 | [2, false], |
| 36 | [-10, false], |
| 37 | |
| 38 | // strings |
| 39 | ['bob', true], |
| 40 | ['bobby', true], |
| 41 | ['bo', false], |
| 42 | ['', false], |
| 43 | ]; |
| 44 | } |
| 45 | |
| 46 | public function testRuleShouldThrowValidationExceptionForInvalidValue() |
| 47 | { |
| 48 | $this->expectException(ValidationException::class); |
| 49 | |
| 50 | $rule = new Min(5); |
| 51 | self::assertValidationRulePassed($rule, true); |
| 52 | } |
| 53 | |
| 54 | public function testRuleThrowsExceptionForNonPositiveSize() |
| 55 | { |
| 56 | $this->expectException(InvalidArgumentException::class); |
| 57 | new Min(0); |
| 58 | } |
| 59 | } |
| 60 |