mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 11:52:34 +02:00
Rename rule "Numeric" to "NumericVal"
This commit is contained in:
parent
07a120d058
commit
e708edd005
|
@ -9,7 +9,7 @@
|
|||
|
||||
[The most awesome validation engine ever created for PHP.](http://bit.ly/1a1oeQv)
|
||||
|
||||
- Complex rules made simple: `v::numeric()->positive()->between(1, 255)->validate($input)`.
|
||||
- Complex rules made simple: `v::numericVal()->positive()->between(1, 255)->validate($input)`.
|
||||
- [Granularity control](docs/README.md#validation-methods) for advanced reporting.
|
||||
- More than 100 (fully tested) validators.
|
||||
- [A concrete API](docs/CONCRETE_API.md) for non fluent usage.
|
||||
|
|
|
@ -16,4 +16,4 @@ See also:
|
|||
* [Digit](Digit.md)
|
||||
* [Finite](Finite.md)
|
||||
* [Infinite](Infinite.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
|
|
|
@ -15,4 +15,4 @@ See also:
|
|||
* [Digit](Digit.md)
|
||||
* [Infinite](Infinite.md)
|
||||
* [IntVal](IntVal.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
|
|
|
@ -14,4 +14,4 @@ See also:
|
|||
* [Digit](Digit.md)
|
||||
* [Finite](Finite.md)
|
||||
* [IntVal](IntVal.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
|
|
|
@ -20,7 +20,7 @@ See also:
|
|||
* [Infinite](Infinite.md)
|
||||
* [IntVal](IntVal.md)
|
||||
* [NullType](NullType.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
* [ObjectType](ObjectType.md)
|
||||
* [ResourceType](ResourceType.md)
|
||||
* [StringType](StringType.md)
|
||||
|
|
|
@ -15,4 +15,4 @@ See also:
|
|||
* [Digit](Digit.md)
|
||||
* [Finite](Finite.md)
|
||||
* [Infinite](Infinite.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
Validates if a number is lower than zero
|
||||
|
||||
```php
|
||||
v::numeric()->negative()->validate(-15); // true
|
||||
v::numericVal()->negative()->validate(-15); // true
|
||||
```
|
||||
|
||||
***
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# Numeric
|
||||
# NumericVal
|
||||
|
||||
- `v::numeric()`
|
||||
- `v::numericVal()`
|
||||
|
||||
Validates on any numeric value.
|
||||
|
||||
```php
|
||||
v::numeric()->validate(-12); // true
|
||||
v::numeric()->validate('135.0'); // true
|
||||
v::numericVal()->validate(-12); // true
|
||||
v::numericVal()->validate('135.0'); // true
|
||||
```
|
||||
|
||||
***
|
|
@ -5,7 +5,7 @@
|
|||
Validates if a number is higher than zero
|
||||
|
||||
```php
|
||||
v::numeric()->positive()->validate(-15); // false
|
||||
v::numericVal()->positive()->validate(-15); // false
|
||||
```
|
||||
|
||||
***
|
||||
|
|
|
@ -15,7 +15,7 @@ The Hello World validator is something like this:
|
|||
|
||||
```php
|
||||
$number = 123;
|
||||
v::numeric()->validate($number); // true
|
||||
v::numericVal()->validate($number); // true
|
||||
```
|
||||
|
||||
## Chained validation
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* [IntType](IntType.md)
|
||||
* [IterableType](IterableType.md)
|
||||
* [NullType](NullType.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
* [ObjectType](ObjectType.md)
|
||||
* [ResourceType](ResourceType.md)
|
||||
* [ScalarVal](ScalarVal.md)
|
||||
|
@ -47,7 +47,7 @@
|
|||
* [Max](Max.md)
|
||||
* [Min](Min.md)
|
||||
|
||||
## Numeric
|
||||
## NumericVal
|
||||
|
||||
* [Between](Between.md)
|
||||
* [BoolType](BoolType.md)
|
||||
|
@ -63,7 +63,7 @@
|
|||
* [Multiple](Multiple.md)
|
||||
* [Negative](Negative.md)
|
||||
* [NotEmpty](NotEmpty.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
* [Odd](Odd.md)
|
||||
* [PerfectSquare](PerfectSquare.md)
|
||||
* [Positive](Positive.md)
|
||||
|
@ -289,7 +289,7 @@
|
|||
* [NotEmpty](NotEmpty.md)
|
||||
* [NotOptional](NotOptional.md)
|
||||
* [NullType](NullType.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [NumericVal](NumericVal.md)
|
||||
* [ObjectType](ObjectType.md)
|
||||
* [Odd](Odd.md)
|
||||
* [OneOf](OneOf.md)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class NumericException extends ValidationException
|
||||
class NumericValException extends ValidationException
|
||||
{
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
|
@ -24,7 +24,7 @@ class Length extends AbstractRule
|
|||
$this->minValue = $min;
|
||||
$this->maxValue = $max;
|
||||
$this->inclusive = $inclusive;
|
||||
$paramValidator = new OneOf(new Numeric(), new NullType());
|
||||
$paramValidator = new OneOf(new NumericVal(), new NullType());
|
||||
if (!$paramValidator->validate($min)) {
|
||||
throw new ComponentException(
|
||||
sprintf('%s is not a valid numeric length', $min)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Numeric extends AbstractRule
|
||||
class NumericVal extends AbstractRule
|
||||
{
|
||||
public function validate($input)
|
||||
{
|
|
@ -109,7 +109,7 @@ use Respect\Validation\Rules\Key;
|
|||
* @method static Validator notOptional()
|
||||
* @method static Validator noWhitespace()
|
||||
* @method static Validator nullType()
|
||||
* @method static Validator numeric()
|
||||
* @method static Validator numericVal()
|
||||
* @method static Validator objectType()
|
||||
* @method static Validator odd()
|
||||
* @method static Validator oneOf()
|
||||
|
|
|
@ -13,8 +13,8 @@ $input = [
|
|||
];
|
||||
|
||||
$rules = [
|
||||
v::key('user_name', v::numeric())->setName('First Name'),
|
||||
v::key('user_surname', v::numeric())->setName('Second Name'),
|
||||
v::key('user_name', v::numericVal())->setName('First Name'),
|
||||
v::key('user_surname', v::numericVal())->setName('Second Name'),
|
||||
v::key('user_tel', v::phone())->setName('Phone number'),
|
||||
];
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ require 'vendor/autoload.php';
|
|||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
v::numeric()->assert(123);
|
||||
v::numeric()->check(123);
|
||||
v::numericVal()->assert(123);
|
||||
v::numericVal()->check(123);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
|
@ -3,17 +3,17 @@
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AllOfException;
|
||||
use Respect\Validation\Exceptions\NumericException;
|
||||
use Respect\Validation\Exceptions\NumericValException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::numeric()->check('a');
|
||||
} catch (NumericException $e) {
|
||||
v::numericVal()->check('a');
|
||||
} catch (NumericValException $e) {
|
||||
echo $e->getMainMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::numeric()->assert('a');
|
||||
v::numericVal()->assert('a');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AllOfException;
|
||||
use Respect\Validation\Exceptions\NumericException;
|
||||
use Respect\Validation\Exceptions\NumericValException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::numeric()->setName('Field')->check(null);
|
||||
} catch (NumericException $e) {
|
||||
v::numericVal()->setName('Field')->check(null);
|
||||
} catch (NumericValException $e) {
|
||||
echo $e->getMainMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::numeric()->setName('Field')->assert('');
|
||||
v::numericVal()->setName('Field')->assert('');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AllOfException;
|
||||
use Respect\Validation\Exceptions\NumericException;
|
||||
use Respect\Validation\Exceptions\NumericValException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::not(v::numeric())->check('1');
|
||||
} catch (NumericException $e) {
|
||||
v::not(v::numericVal())->check('1');
|
||||
} catch (NumericValException $e) {
|
||||
echo $e->getMainMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::numeric())->assert('1');
|
||||
v::not(v::numericVal())->assert('1');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
|
|
@ -59,9 +59,9 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
[new AllOf(new NoWhitespace(), new Digit()), 'as df'],
|
||||
[new AllOf(new NoWhitespace(), new Digit()), '12 34'],
|
||||
[new AllOf(new AllOf(new NoWhitespace(), new Digit())), '12 34'],
|
||||
[new AllOf(new NoneOf(new Numeric(), new IntVal())), 13.37],
|
||||
[new NoneOf(new Numeric(), new IntVal()), 13.37],
|
||||
[Validator::noneOf(Validator::numeric(), Validator::intVal()), 13.37],
|
||||
[new AllOf(new NoneOf(new NumericVal(), new IntVal())), 13.37],
|
||||
[new NoneOf(new NumericVal(), new IntVal()), 13.37],
|
||||
[Validator::noneOf(Validator::numericVal(), Validator::intVal()), 13.37],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,9 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return [
|
||||
[new IntVal(), 123],
|
||||
[new AllOf(new OneOf(new Numeric(), new IntVal())), 13.37],
|
||||
[new OneOf(new Numeric(), new IntVal()), 13.37],
|
||||
[Validator::oneOf(Validator::numeric(), Validator::intVal()), 13.37],
|
||||
[new AllOf(new OneOf(new NumericVal(), new IntVal())), 13.37],
|
||||
[new OneOf(new NumericVal(), new IntVal()), 13.37],
|
||||
[Validator::oneOf(Validator::numericVal(), Validator::intVal()), 13.37],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -79,10 +79,10 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return [
|
||||
[new IntVal()],
|
||||
[new AllOf(new Numeric(), new IntVal())],
|
||||
[new AllOf(new NumericVal(), new IntVal())],
|
||||
[new Not(new Not(new IntVal()))],
|
||||
[Validator::intVal()->setName('Bar')],
|
||||
[Validator::noneOf(Validator::numeric(), Validator::intVal())],
|
||||
[Validator::noneOf(Validator::numericVal(), Validator::intVal())],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,16 +13,16 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers Respect\Validation\Rules\Numeric
|
||||
* @covers Respect\Validation\Exceptions\NumericException
|
||||
* @covers Respect\Validation\Rules\NumericVal
|
||||
* @covers Respect\Validation\Exceptions\NumericValException
|
||||
*/
|
||||
class NumericTest extends \PHPUnit_Framework_TestCase
|
||||
class NumericValTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $object;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Numeric();
|
||||
$this->object = new NumericVal();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ class NumericTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotNumeric
|
||||
* @expectedException Respect\Validation\Exceptions\NumericException
|
||||
* @expectedException Respect\Validation\Exceptions\NumericValException
|
||||
*/
|
||||
public function testNotNumeric($input)
|
||||
{
|
Loading…
Reference in a new issue