Remove all rules shortcuts

This commit is contained in:
Henrique Moody 2015-10-14 03:20:50 -03:00
parent 880cdb5f09
commit bbf9c2505e
8 changed files with 2 additions and 102 deletions

View file

@ -38,6 +38,8 @@ All notable changes of the Respect\Validation releases are documented in this fi
- On exceptions, do not display parent message then rule has only one child (#407)
- On exceptions, improve `Object` conversion to string (#399)
- On exceptions, improve conversion of all values by using JSON (#399)
- Remove `addOr()` shortcut (#444)
- Remove `not()` shortcut (#444)
- Remove identical checking from "Equals" rule (#442)
- Rename rule "Arr" to "ArrayVal"
- Rename rule "Bool" to "BoolType" (#426)

View file

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

View file

@ -17,12 +17,6 @@ In the sample above, `v::intVal()` doesn't validates, but
`v::oneOf` returns true if at least one inner validator
passes.
Using a shortcut
```php
v::intVal()->addOr(v::floatVal())->validate(15.5); //true
```
***
See also:

View file

@ -31,14 +31,6 @@ abstract class AbstractRule implements Validatable
return $this->validate($input);
}
public function addOr()
{
$rules = func_get_args();
array_unshift($rules, $this);
return new OneOf($rules);
}
public function assert($input)
{
if ($this->__invoke($input)) {

View file

@ -208,10 +208,6 @@ class Validator extends AllOf
*/
public function __call($method, $arguments)
{
if ('not' === $method && empty($arguments)) {
return new static(new Rules\Not($this));
}
return $this->addRule(static::buildRule($method, $arguments));
}

View file

@ -29,11 +29,6 @@ class NotTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($not->assert($input));
}
public function testShortcutNot()
{
$this->assertTrue(Validator::intVal()->not()->assert('afg'));
}
/**
* @dataProvider providerForInvalidNot
* @expectedException Respect\Validation\Exceptions\ValidationException
@ -44,14 +39,6 @@ class NotTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($not->assert($input));
}
/**
* @expectedException Respect\Validation\Exceptions\ValidationException
*/
public function testShortcutNotNotHaha()
{
$this->assertFalse(Validator::intVal()->not()->assert(10));
}
public function providerForValidNot()
{
return array(

View file

@ -35,25 +35,6 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($o->check('any'));
}
public function testShortcutValid()
{
$valid1 = new Callback(function () {
return false;
});
$valid2 = new Callback(function () {
return true;
});
$valid3 = new Callback(function () {
return false;
});
$o = $valid1->addOr($valid2, $valid3);
$this->assertTrue($o->validate('any'));
$this->assertTrue($o->assert('any'));
$this->assertTrue($o->check('any'));
}
/**
* @expectedException Respect\Validation\Exceptions\OneOfException
*/
@ -73,25 +54,6 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($o->assert('any'));
}
/**
* @expectedException Respect\Validation\Exceptions\OneOfException
*/
public function testShortcutInvalid()
{
$valid1 = new Callback(function () {
return false;
});
$valid2 = new Callback(function () {
return false;
});
$valid3 = new Callback(function () {
return false;
});
$o = $valid1->addOr($valid2, $valid3);
$this->assertFalse($o->validate('any'));
$this->assertFalse($o->assert('any'));
}
/**
* @expectedException Respect\Validation\Exceptions\XdigitException
*/
@ -101,15 +63,4 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($o->validate(-10));
$this->assertFalse($o->check(-10));
}
/**
* @expectedException Respect\Validation\Exceptions\XdigitException
*/
public function testShortcutInvalidCheck()
{
$xdigits = new Xdigit();
$o = $xdigits->addOr(new Alnum());
$this->assertFalse($o->validate(-10));
$this->assertFalse($o->check(-10));
}
}

View file

@ -24,16 +24,6 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
Validator::iDoNotExistSoIShouldThrowException();
}
/**
* Regression test #174.
*/
public function testShouldReturnANewValidatorInstanceWhenTheNotRuleIsCalledWithoutAnyArgument()
{
$validator = new Validator();
$this->assertInstanceOf('Respect\Validation\Validator', $validator->not());
}
/**
* Regression test #174.
*/