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
NumericTest.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace StellarWP\Validation\Tests\Unit\Rules; |
| 6 | |
| 7 | use StellarWP\Validation\Rules\Numeric; |
| 8 | use StellarWP\Validation\Tests\TestCase; |
| 9 | class NumericTest extends TestCase |
| 10 | { |
| 11 | /** |
| 12 | * @unreleased |
| 13 | */ |
| 14 | public function testShouldPassWhenValueIsNumeric() |
| 15 | { |
| 16 | $rule = new Numeric(); |
| 17 | |
| 18 | self::assertValidationRulePassed($rule, 1); |
| 19 | self::assertValidationRulePassed($rule, 100.00); |
| 20 | self::assertValidationRulePassed($rule, '1'); |
| 21 | self::assertValidationRulePassed($rule, '100.00'); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @unreleased |
| 26 | */ |
| 27 | public function testShouldFailWhenValueIsNotNumeric() |
| 28 | { |
| 29 | $rule = new Numeric(); |
| 30 | |
| 31 | self::assertValidationRuleFailed($rule, 'abc'); |
| 32 | self::assertValidationRuleFailed($rule, 'abc123'); |
| 33 | self::assertValidationRuleFailed($rule, '123abc'); |
| 34 | self::assertValidationRuleFailed($rule, '123.abc'); |
| 35 | self::assertValidationRuleFailed($rule, '123.345.56'); |
| 36 | self::assertValidationRuleFailed($rule, 'abc.123'); |
| 37 | self::assertValidationRuleFailed($rule, 'abc123.abc'); |
| 38 | self::assertValidationRuleFailed($rule, 'abc.123abc'); |
| 39 | self::assertValidationRuleFailed($rule, 'abc123.abc456'); |
| 40 | } |
| 41 | } |
| 42 |