Rename "OneOf" to "AnyOf"

This commit is contained in:
Henrique Moody 2017-02-05 12:23:22 +01:00
parent 27d35987be
commit 7ee4ae47d5
No known key found for this signature in database
GPG key ID: 221E9281655813A6
8 changed files with 21 additions and 21 deletions

View file

@ -1,20 +1,20 @@
# OneOf
# AnyOf
- `v::oneOf(v $v1, v $v2, v $v3...)`
- `v::anyOf(v $v1, v $v2, v $v3...)`
This is a group validator that acts as an OR operator.
```php
v::oneOf(
v::anyOf(
v::intVal(),
v::floatVal()
)->validate(15.5); // true
```
In the sample above, `v::intVal()` doesn't validates, but
`v::floatVal()` validates, so oneOf returns true.
`v::floatVal()` validates, so anyOf returns true.
`v::oneOf` returns true if at least one inner validator
`v::anyOf` returns true if at least one inner validator
passes.
***

View file

@ -11,7 +11,7 @@
namespace Respect\Validation\Exceptions;
class OneOfException extends NestedValidationException
class AnyOfException extends NestedValidationException
{
public static $defaultTemplates = [
self::MODE_DEFAULT => [

View file

@ -13,7 +13,7 @@ namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ValidationException;
class OneOf extends AbstractComposite
class AnyOf extends AbstractComposite
{
public function assert($input)
{

View file

@ -28,7 +28,7 @@ class Domain extends AbstractComposite
$this->otherParts = new AllOf(
new Alnum('-'),
new Not(new StartsWith('-')),
new OneOf(
new AnyOf(
new Not(
new Contains('--')
),

View file

@ -24,7 +24,7 @@ class Length extends AbstractRule
$this->minValue = $min;
$this->maxValue = $max;
$this->inclusive = $inclusive;
$paramValidator = new OneOf(new NumericVal(), new NullType());
$paramValidator = new AnyOf(new NumericVal(), new NullType());
if (!$paramValidator->validate($min)) {
throw new ComponentException(
sprintf('%s is not a valid numeric length', $min)

View file

@ -26,8 +26,9 @@ use Respect\Validation\Rules\Key;
* @method static Validator alpha(string $additionalChars = null)
* @method static Validator alwaysInvalid()
* @method static Validator alwaysValid()
* @method static Validator arrayVal()
* @method static Validator anyOf()
* @method static Validator arrayType()
* @method static Validator arrayVal()
* @method static Validator attribute(string $reference, Validatable $validator = null, bool $mandatory = true)
* @method static Validator bank(string $countryCode)
* @method static Validator bankAccount(string $countryCode)
@ -112,7 +113,6 @@ use Respect\Validation\Rules\Key;
* @method static Validator numericVal()
* @method static Validator objectType()
* @method static Validator odd()
* @method static Validator oneOf()
* @method static Validator optional(Validatable $rule)
* @method static Validator perfectSquare()
* @method static Validator pesel()

View file

@ -13,10 +13,10 @@ namespace Respect\Validation\Rules;
/**
* @group rule
* @covers \Respect\Validation\Rules\OneOf
* @covers \Respect\Validation\Exceptions\OneOfException
* @covers \Respect\Validation\Rules\AnyOf
* @covers \Respect\Validation\Exceptions\AnyOfException
*/
class OneOfTest extends \PHPUnit_Framework_TestCase
class AnyOfTest extends \PHPUnit_Framework_TestCase
{
public function testValid()
{
@ -29,14 +29,14 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
$valid3 = new Callback(function () {
return false;
});
$o = new OneOf($valid1, $valid2, $valid3);
$o = new AnyOf($valid1, $valid2, $valid3);
$this->assertTrue($o->validate('any'));
$this->assertTrue($o->assert('any'));
$this->assertTrue($o->check('any'));
}
/**
* @expectedException \Respect\Validation\Exceptions\OneOfException
* @expectedException \Respect\Validation\Exceptions\AnyOfException
*/
public function testInvalid()
{
@ -49,7 +49,7 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
$valid3 = new Callback(function () {
return false;
});
$o = new OneOf($valid1, $valid2, $valid3);
$o = new AnyOf($valid1, $valid2, $valid3);
$this->assertFalse($o->validate('any'));
$this->assertFalse($o->assert('any'));
}
@ -59,7 +59,7 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
*/
public function testInvalidCheck()
{
$o = new OneOf(new Xdigit(), new Alnum());
$o = new AnyOf(new Xdigit(), new Alnum());
$this->assertFalse($o->validate(-10));
$this->assertFalse($o->check(-10));
}

View file

@ -69,9 +69,9 @@ class NotTest extends \PHPUnit_Framework_TestCase
{
return [
[new IntVal(), 123],
[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],
[new AllOf(new AnyOf(new NumericVal(), new IntVal())), 13.37],
[new AnyOf(new NumericVal(), new IntVal()), 13.37],
[Validator::anyOf(Validator::numericVal(), Validator::intVal()), 13.37],
];
}