Rename rule "Int" to "IntVal"

This commit is contained in:
Henrique Moody 2015-10-07 11:46:57 -03:00
parent 3e1f86baf8
commit 9b85df4601
35 changed files with 76 additions and 76 deletions

View file

@ -14,7 +14,7 @@ on IRC, or on Gitter if you feel that we forgot to respond.
Please see the [project documentation](http://respect.github.io/Validation)
before proceeding. You should also know about [PHP-FIG](http://www.php-fig.org)'s
standards and basic unit testing, but we're sure you can learn that just by
looking at other rules. Pick the simple ones like `Int` to begin.
looking at other rules. Pick the simple ones like `IntVal` to begin.
Before writing anything, make sure there is no validator that already does what
you need. Also, it would be awesome if you

View file

@ -6,7 +6,7 @@ Will validate if all inner validators validates.
```php
v::allOf(
v::int(),
v::intVal(),
v::positive()
)->validate(15); //true
```
@ -16,7 +16,7 @@ its syntax allows you to set custom names for every node:
```php
v::allOf(
v::int()->setName('Account Number'),
v::intVal()->setName('Account Number'),
v::positive()->setName('Higher Than Zero')
)->setName('Positive integer')
->validate(15); //true

View file

@ -6,7 +6,7 @@
Validates ranges. Most simple example:
```php
v::int()->between(10, 20)->validate(15); //true
v::intVal()->between(10, 20)->validate(15); //true
```
The type as the first validator in a chain is a good practice,

View file

@ -41,8 +41,8 @@ v::call(
It is possible to call methods and closures as the first parameter:
```php
v::call(array($myObj, 'methodName'), v::int())->validate($myInput);
v::call(function($input) {}, v::int())->validate($myInput);
v::call(array($myObj, 'methodName'), v::intVal())->validate($myInput);
v::call(function($input) {}, v::intVal())->validate($myInput);
```
***

View file

@ -9,7 +9,7 @@ to validate something:
v::callback('is_int')->validate(10); //true
```
(Please note that this is a sample, the `v::int()` validator is much better).
(Please note that this is a sample, the `v::intVal()` validator is much better).
As in `v::call()`, you can pass a method or closure to it.

View file

@ -5,7 +5,7 @@
Validates an even number.
```php
v::int()->even()->validate(2); //true
v::intVal()->even()->validate(2); //true
```
Using `int()` before `even()` is a best practice.

View file

@ -14,5 +14,5 @@ See also:
* [Digit](Digit.md)
* [Infinite](Infinite.md)
* [Int](Int.md)
* [IntVal](IntVal.md)
* [Numeric](Numeric.md)

View file

@ -13,5 +13,5 @@ See also:
* [Digit](Digit.md)
* [Finite](Finite.md)
* [Int](Int.md)
* [IntVal](IntVal.md)
* [Numeric](Numeric.md)

View file

@ -1,12 +1,12 @@
# Int
# IntVal
- `v::int()`
- `v::intVal()`
Validates if the input is an integer.
```php
v::int()->validate('10'); //true
v::int()->validate(10); //true
v::intVal()->validate('10'); //true
v::intVal()->validate(10); //true
```
***

View file

@ -8,7 +8,7 @@ Validates a keys in a defined structure.
$dict = array('foo' => 42);
v::keySet(
v::key('foo', v::int())
v::key('foo', v::intVal())
)->validate($dict); //true
```
@ -17,7 +17,7 @@ Extra keys are not allowed:
$dict = array('foo' => 42, 'bar' => 'String');
v::keySet(
v::key('foo', v::int())
v::key('foo', v::intVal())
)->validate($dict); //false
```
@ -26,7 +26,7 @@ Missing required keys are not allowed:
$dict = array('foo' => 42, 'bar' => 'String');
v::keySet(
v::key('foo', v::int()),
v::key('foo', v::intVal()),
v::key('bar', v::string()),
v::key('baz', v::boolType())
)->validate($dict); //false
@ -37,7 +37,7 @@ Missing non-required keys are allowed:
$dict = array('foo' => 42, 'bar' => 'String');
v::keySet(
v::key('foo', v::int()),
v::key('foo', v::intVal()),
v::key('bar', v::string()),
v::key('baz', v::boolType(), false)
)->validate($dict); //true

View file

@ -6,9 +6,9 @@
Validates if the input doesn't exceed the maximum value.
```php
v::int()->max(15)->validate(20); //false
v::int()->max(20)->validate(20); //false
v::int()->max(20, true)->validate(20); //true
v::intVal()->max(15)->validate(20); //false
v::intVal()->max(20)->validate(20); //false
v::intVal()->max(20, true)->validate(20); //true
```
Also accepts dates:

View file

@ -6,9 +6,9 @@
Validates if the input is greater than the minimum value.
```php
v::int()->min(15)->validate(5); //false
v::int()->min(5)->validate(5); //false
v::int()->min(5, true)->validate(5); //true
v::intVal()->min(15)->validate(5); //false
v::intVal()->min(5)->validate(5); //false
v::intVal()->min(5, true)->validate(5); //true
```
Also accepts dates:

View file

@ -5,7 +5,7 @@
Validates if the input is a multiple of the given parameter
```php
v::int()->multiple(3)->validate(9); //true
v::intVal()->multiple(3)->validate(9); //true
```
***

View file

@ -6,7 +6,7 @@ Validates if NONE of the given validators validate:
```php
v::noneOf(
v::int(),
v::intVal(),
v::floatVal()
)->validate('foo'); //true
```

View file

@ -19,13 +19,13 @@ In the sample above, validator returns true because 'foo' isn't an IP Address.
You can negate complex, grouped or chained validators as well:
```php
v::not(v::int()->positive())->validate(-1.5); //true
v::not(v::intVal()->positive())->validate(-1.5); //true
```
using a shortcut
```php
v::int()->positive()->not()->validate(-1.5); //true
v::intVal()->positive()->not()->validate(-1.5); //true
```
Each other validation has custom messages for negated rules.

View file

@ -19,7 +19,7 @@ v::notEmpty()->validate(null); //false
Numbers:
```php
v::int()->notEmpty()->validate(0); //false
v::intVal()->notEmpty()->validate(0); //false
```
Empty arrays:

View file

@ -15,4 +15,4 @@ See also:
* [Digit](Digit.md)
* [Finite](Finite.md)
* [Infinite](Infinite.md)
* [Int](Int.md)
* [IntVal](IntVal.md)

View file

@ -5,7 +5,7 @@
Validates an odd number.
```php
v::int()->odd()->validate(3); //true
v::intVal()->odd()->validate(3); //true
```
Using `int()` before `odd()` is a best practice.

View file

@ -6,12 +6,12 @@ This is a group validator that acts as an OR operator.
```php
v::oneOf(
v::int(),
v::intVal(),
v::floatVal()
)->validate(15.5); //true
```
In the sample above, `v::int()` doesn't validates, but
In the sample above, `v::intVal()` doesn't validates, but
`v::floatVal()` validates, so oneOf returns true.
`v::oneOf` returns true if at least one inner validator
@ -20,7 +20,7 @@ passes.
Using a shortcut
```php
v::int()->addOr(v::floatVal())->validate(15.5); //true
v::intVal()->addOr(v::floatVal())->validate(15.5); //true
```
***

View file

@ -81,7 +81,7 @@ See more on [Optional](Optional.md).
You can use the `v::not()` to negate any rule:
```php
v::not(v::int())->validate(10); //false, input must not be integer
v::not(v::intVal())->validate(10); //false, input must not be integer
```
## Validator Reuse

View file

@ -20,7 +20,7 @@ See also:
* [FloatVal](FloatVal.md)
* [Infinite](Infinite.md)
* [Instance](Instance.md)
* [Int](Int.md)
* [IntVal](IntVal.md)
* [Object](Object.md)
* [Resource](Resource.md)
* [Scalar](Scalar.md)

View file

@ -9,7 +9,7 @@
* [FalseVal](FalseVal.md)
* [FloatVal](FloatVal.md)
* [Instance](Instance.md)
* [Int](Int.md)
* [IntVal](IntVal.md)
* [NullValue](NullValue.md)
* [Numeric](Numeric.md)
* [Object](Object.md)
@ -49,7 +49,7 @@
* [Finite](Finite.md)
* [FloatVal](FloatVal.md)
* [Infinite](Infinite.md)
* [Int](Int.md)
* [IntVal](IntVal.md)
* [Multiple](Multiple.md)
* [Negative](Negative.md)
* [NotEmpty](NotEmpty.md)
@ -224,7 +224,7 @@
* [In](In.md)
* [Infinite](Infinite.md)
* [Instance](Instance.md)
* [Int](Int.md)
* [IntVal](IntVal.md)
* [Ip](Ip.md)
* [Json](Json.md)
* [Key](Key.md)

View file

@ -9,7 +9,7 @@ When the `$if` validates, returns validation for `$then`.
When the `$if` doesn't validate, returns validation for `$else`, if defined.
```php
v::when(v::int(), v::positive(), v::notEmpty())->validate($input);
v::when(v::intVal(), v::positive(), v::notEmpty())->validate($input);
```
In the sample above, if `$input` is an integer, then it must be positive.

View file

@ -11,7 +11,7 @@
namespace Respect\Validation\Exceptions;
class IntException extends ValidationException
class IntValException extends ValidationException
{
public static $defaultTemplates = array(
self::MODE_DEFAULT => array(

View file

@ -11,7 +11,7 @@
namespace Respect\Validation\Rules;
class Int extends AbstractRule
class IntVal extends AbstractRule
{
public function validate($input)
{

View file

@ -66,7 +66,7 @@ use Respect\Validation\Rules\Key;
* @method static Validator in(mixed $haystack, bool $compareIdentical = false)
* @method static Validator infinite()
* @method static Validator instance(string $instanceName)
* @method static Validator int()
* @method static Validator intVal()
* @method static Validator ip(mixed $ipOptions = null)
* @method static Validator json()
* @method static Validator key(string $reference, Validatable $referenceValidator = null, bool $mandatory = true)

View file

@ -6,7 +6,7 @@ require 'vendor/autoload.php';
use Respect\Validation\Validator;
var_dump(Validator::not(Validator::int())->validate(10));
var_dump(Validator::not(Validator::intVal())->validate(10));
?>
--EXPECTF--
bool(false)

View file

@ -13,7 +13,7 @@ try {
Validator::not(
Validator::not(
Validator::not(
Validator::int()->positive()
Validator::intVal()->positive()
)
)
)

View file

@ -15,7 +15,7 @@ class AbstractGroupedExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testOneOrMoreGroupedExceptionsShouldBeCondensedByGetRelated()
{
$int = new IntException();
$int = new IntValException();
$e = new AbstractGroupedException();
$e2 = new AbstractNestedException();
$e->addRelated($e2);

View file

@ -31,7 +31,7 @@ class AbstractNestedExceptionTest extends \PHPUnit_Framework_TestCase
public function testGetRelatedShouldReturnExceptionAddedByAddRelated()
{
$composite = new AttributeException();
$node = new IntException();
$node = new IntValException();
$composite->addRelated($node);
$this->assertEquals(1, count($composite->getRelated(true)));
$this->assertContainsOnly($node, $composite->getRelated());
@ -40,7 +40,7 @@ class AbstractNestedExceptionTest extends \PHPUnit_Framework_TestCase
public function testAddingTheSameInstanceShouldAddJustASingleReference()
{
$composite = new AttributeException();
$node = new IntException();
$node = new IntValException();
$composite->addRelated($node);
$composite->addRelated($node);
$composite->addRelated($node);

View file

@ -20,7 +20,7 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
{
public function testRemoveRulesShouldRemoveAllRules()
{
$o = new AllOf(new Int(), new Positive());
$o = new AllOf(new IntVal(), new Positive());
$o->removeRules();
$this->assertEquals(0, count($o->getRules()));
}
@ -30,7 +30,7 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
$o = new AllOf();
$o->addRules(
array(
array($x = new Int(), new Positive()),
array($x = new IntVal(), new Positive()),
)
);
$this->assertTrue($o->hasRule($x));

View file

@ -31,7 +31,7 @@ class EachTest extends \PHPUnit_Framework_TestCase
public function testValidatorShouldPassIfEveryArrayItemAndKeyPass()
{
$v = new Each(new Alpha(), new Int());
$v = new Each(new Alpha(), new IntVal());
$result = $v->validate(array('a', 'b', 'c', 'd', 'e'));
$this->assertTrue($result);
$result = $v->check(array('a', 'b', 'c', 'd', 'e'));
@ -42,7 +42,7 @@ class EachTest extends \PHPUnit_Framework_TestCase
public function testValidatorShouldPassWithOnlyKeyValidation()
{
$v = new Each(null, new Int());
$v = new Each(null, new IntVal());
$result = $v->validate(array('a', 'b', 'c', 'd', 'e'));
$this->assertTrue($result);
$result = $v->check(array('a', 'b', 'c', 'd', 'e'));
@ -80,7 +80,7 @@ class EachTest extends \PHPUnit_Framework_TestCase
*/
public function testAssertShouldFailOnInvalidItem()
{
$v = new Each(new Int());
$v = new Each(new IntVal());
$result = $v->assert(array('a', 2, 3, 4, 5));
$this->assertFalse($result);
}

View file

@ -13,16 +13,16 @@ namespace Respect\Validation\Rules;
/**
* @group rule
* @covers Respect\Validation\Rules\Int
* @covers Respect\Validation\Exceptions\IntException
* @covers Respect\Validation\Rules\IntVal
* @covers Respect\Validation\Exceptions\IntValException
*/
class IntTest extends \PHPUnit_Framework_TestCase
class IntValTest extends \PHPUnit_Framework_TestCase
{
protected $intValidator;
protected function setUp()
{
$this->intValidator = new Int();
$this->intValidator = new IntVal();
}
/**
@ -37,7 +37,7 @@ class IntTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerForNotInt
* @expectedException Respect\Validation\Exceptions\IntException
* @expectedException Respect\Validation\Exceptions\IntValException
*/
public function testInvalidIntegersShouldThrowIntException($input)
{

View file

@ -31,7 +31,7 @@ class NotTest extends \PHPUnit_Framework_TestCase
public function testShortcutNot()
{
$this->assertTrue(Validator::int()->not()->assert('afg'));
$this->assertTrue(Validator::intVal()->not()->assert('afg'));
}
/**
@ -49,30 +49,30 @@ class NotTest extends \PHPUnit_Framework_TestCase
*/
public function testShortcutNotNotHaha()
{
$this->assertFalse(Validator::int()->not()->assert(10));
$this->assertFalse(Validator::intVal()->not()->assert(10));
}
public function providerForValidNot()
{
return array(
array(new Int(), ''),
array(new Int(), 'aaa'),
array(new IntVal(), ''),
array(new IntVal(), 'aaa'),
array(new AllOf(new NoWhitespace(), new Digit()), 'as df'),
array(new AllOf(new NoWhitespace(), new Digit()), '12 34'),
array(new AllOf(new AllOf(new NoWhitespace(), new Digit())), '12 34'),
array(new AllOf(new NoneOf(new Numeric(), new Int())), 13.37),
array(new NoneOf(new Numeric(), new Int()), 13.37),
array(Validator::noneOf(Validator::numeric(), Validator::int()), 13.37),
array(new AllOf(new NoneOf(new Numeric(), new IntVal())), 13.37),
array(new NoneOf(new Numeric(), new IntVal()), 13.37),
array(Validator::noneOf(Validator::numeric(), Validator::intVal()), 13.37),
);
}
public function providerForInvalidNot()
{
return array(
array(new Int(), 123),
array(new AllOf(new OneOf(new Numeric(), new Int())), 13.37),
array(new OneOf(new Numeric(), new Int()), 13.37),
array(Validator::oneOf(Validator::numeric(), Validator::int()), 13.37),
array(new IntVal(), 123),
array(new AllOf(new OneOf(new Numeric(), new IntVal())), 13.37),
array(new OneOf(new Numeric(), new IntVal()), 13.37),
array(Validator::oneOf(Validator::numeric(), Validator::intVal()), 13.37),
);
}
}

View file

@ -20,20 +20,20 @@ class WhenTest extends \PHPUnit_Framework_TestCase
{
public function testWhenHappypath()
{
$v = new When(new Int(), new Between(1, 5), new NotEmpty());
$v = new When(new IntVal(), new Between(1, 5), new NotEmpty());
$this->assertTrue($v->validate(3));
$this->assertTrue($v->validate('aaa'));
}
public function testWhenError()
{
$v = new When(new Int(), new Between(1, 5), new NotEmpty());
$v = new When(new IntVal(), new Between(1, 5), new NotEmpty());
$this->assertFalse($v->validate(15));
}
public function testWhenWithoutElseHappypath()
{
$v = new When(new Int(), new Between(1, 5));
$v = new When(new IntVal(), new Between(1, 5));
$this->assertTrue($v->validate(3));
}
@ -60,7 +60,7 @@ class WhenTest extends \PHPUnit_Framework_TestCase
*/
public function testWhenException()
{
$v = new When(new Int(), new Between(1, 5), new NotEmpty());
$v = new When(new IntVal(), new Between(1, 5), new NotEmpty());
$this->assertFalse($v->assert(15));
}
@ -69,7 +69,7 @@ class WhenTest extends \PHPUnit_Framework_TestCase
*/
public function testWhenException_on_else()
{
$v = new When(new Int(), new Between(1, 5), new NotEmpty());
$v = new When(new IntVal(), new Between(1, 5), new NotEmpty());
$this->assertFalse($v->assert(''));
}
@ -78,7 +78,7 @@ class WhenTest extends \PHPUnit_Framework_TestCase
*/
public function testWhenException_failfast()
{
$v = new When(new Int(), new Between(1, 5), new NotEmpty());
$v = new When(new IntVal(), new Between(1, 5), new NotEmpty());
$this->assertFalse($v->check(15));
}
@ -87,7 +87,7 @@ class WhenTest extends \PHPUnit_Framework_TestCase
*/
public function testWhenException_on_else_failfast()
{
$v = new When(new Int(), new Between(1, 5), new NotEmpty());
$v = new When(new IntVal(), new Between(1, 5), new NotEmpty());
$this->assertFalse($v->check(''));
}
}