mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 03:42:25 +02:00
Rename "OneOf" to "AnyOf"
This commit is contained in:
parent
27d35987be
commit
7ee4ae47d5
|
@ -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.
|
||||
|
||||
***
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class OneOfException extends NestedValidationException
|
||||
class AnyOfException extends NestedValidationException
|
||||
{
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
|
@ -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)
|
||||
{
|
|
@ -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('--')
|
||||
),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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));
|
||||
}
|
|
@ -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],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue