mirror of
https://github.com/Respect/Validation.git
synced 2024-06-14 11:35:08 +02:00
Make all rules mandatory
This commit is contained in:
parent
845d976264
commit
3e45647b81
|
@ -22,13 +22,6 @@ remove them add `->noWhitespace()` to the chain:
|
|||
v::alnum()->noWhitespace->validate('foo 123'); //false
|
||||
```
|
||||
|
||||
By default empty values are allowed, if you want
|
||||
to invalidate them, add `->notEmpty()` to the chain:
|
||||
|
||||
```php
|
||||
v::alnum()->notEmpty()->validate(''); //false
|
||||
```
|
||||
|
||||
You can restrict case using the `->lowercase()` and
|
||||
`->uppercase()` validators:
|
||||
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
- `v::alpha()`
|
||||
- `v::alpha(string $additionalChars)`
|
||||
|
||||
This is similar to v::alnum(), but it doesn't allow numbers. It also
|
||||
accepts empty values and whitespace, so use `v::notEmpty()` and
|
||||
`v::noWhitespace()` when appropriate.
|
||||
This is similar to `v::alnum()`, but it doesn't allow numbers.
|
||||
|
||||
***
|
||||
See also:
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
- `v::digit()`
|
||||
|
||||
This is similar to v::alnum(), but it doesn't allow a-Z. It also
|
||||
accepts empty values and whitespace, so use `v::notEmpty()` and
|
||||
`v::noWhitespace()` when appropriate.
|
||||
This is similar to `v::alnum()`, but it doesn't allow a-Z.
|
||||
|
||||
***
|
||||
See also:
|
||||
|
|
|
@ -9,11 +9,4 @@ v::noWhitespace()->validate('foo bar'); //false
|
|||
v::noWhitespace()->validate("foo\nbar"); //false
|
||||
```
|
||||
|
||||
Like other rules the input is still optional.
|
||||
|
||||
```php
|
||||
v::string()->noWhitespace()->validate(''); //true
|
||||
v::string()->noWhitespace()->validate(' '); //false
|
||||
```
|
||||
|
||||
This is most useful when chaining with other validators such as `v::alnum()`
|
||||
|
|
|
@ -53,18 +53,6 @@ Note that we used `v::string()` and `v::date()` in the beginning of the validato
|
|||
Although is not mandatory, it is a good practice to use the type of the
|
||||
validated object as the first node in the chain.
|
||||
|
||||
## Input optional
|
||||
|
||||
All validators treat input as optional and will accept empty string input as valid,
|
||||
unless otherwise stated in the documentation.
|
||||
|
||||
We use the `v:notEmpty()` validator prefixed to disallow empty input and effectively
|
||||
define the field as mandatory as input will be required or validation will fail.
|
||||
|
||||
```php
|
||||
v::string()->notEmpty()->validate(''); //false input required
|
||||
```
|
||||
|
||||
## Negating Rules
|
||||
|
||||
You can use the `v::not()` to negate any rule:
|
||||
|
|
|
@ -7,6 +7,3 @@ Validates roman numbers
|
|||
```php
|
||||
v::roman()->validate('IV'); //true
|
||||
```
|
||||
|
||||
This validator ignores empty values, use `notEmpty()` when
|
||||
appropriate.
|
||||
|
|
|
@ -39,7 +39,12 @@ abstract class AbstractFilterRule extends AbstractRule
|
|||
return false;
|
||||
}
|
||||
|
||||
$cleanInput = $this->filter((string) $input);
|
||||
$stringInput = (string) $input;
|
||||
if ('' === $stringInput) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cleanInput = $this->filter($stringInput);
|
||||
|
||||
return $cleanInput === '' || $this->validateClean($cleanInput);
|
||||
}
|
||||
|
|
|
@ -53,10 +53,6 @@ abstract class AbstractRelated extends AbstractRule
|
|||
|
||||
public function assert($input)
|
||||
{
|
||||
if ($input === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$hasReference = $this->hasReference($input);
|
||||
if ($this->mandatory && !$hasReference) {
|
||||
throw $this->reportError($input, array('hasReference' => false));
|
||||
|
@ -73,10 +69,6 @@ abstract class AbstractRelated extends AbstractRule
|
|||
|
||||
public function check($input)
|
||||
{
|
||||
if ($input === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$hasReference = $this->hasReference($input);
|
||||
if ($this->mandatory && !$hasReference) {
|
||||
throw $this->reportError($input, array('hasReference' => false));
|
||||
|
@ -87,10 +79,6 @@ abstract class AbstractRelated extends AbstractRule
|
|||
|
||||
public function validate($input)
|
||||
{
|
||||
if ($input === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$hasReference = $this->hasReference($input);
|
||||
if ($this->mandatory && !$hasReference) {
|
||||
return false;
|
||||
|
|
|
@ -28,8 +28,7 @@ abstract class AbstractRule implements Validatable
|
|||
|
||||
public function __invoke($input)
|
||||
{
|
||||
return !is_a($this, __NAMESPACE__.'\\NotEmpty')
|
||||
&& $input === '' || $this->validate($input);
|
||||
return $this->validate($input);
|
||||
}
|
||||
|
||||
public function addOr()
|
||||
|
|
|
@ -22,6 +22,10 @@ abstract class AbstractSearcher extends AbstractRule
|
|||
return in_array($input, $this->haystack);
|
||||
}
|
||||
|
||||
if ($input === null || $input === '') {
|
||||
return ($input == $this->haystack);
|
||||
}
|
||||
|
||||
return (false !== mb_stripos($this->haystack, $input, 0, mb_detect_encoding($input)));
|
||||
}
|
||||
|
||||
|
@ -31,6 +35,10 @@ abstract class AbstractSearcher extends AbstractRule
|
|||
return in_array($input, $this->haystack, true);
|
||||
}
|
||||
|
||||
if ($input === null || $input === '') {
|
||||
return ($input === $this->haystack);
|
||||
}
|
||||
|
||||
return (false !== mb_strpos($this->haystack, $input, 0, mb_detect_encoding($input)));
|
||||
}
|
||||
|
||||
|
|
|
@ -88,13 +88,12 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerStaticDummyRules
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
*/
|
||||
public function testValidationCheckShouldNotFailOnEmptyInput($v1, $v2, $v3)
|
||||
public function testValidationCheckShouldFailOnEmptyInput($v1, $v2, $v3)
|
||||
{
|
||||
$o = new AllOf($v1, $v2, $v3);
|
||||
$this->assertTrue($o->__invoke(''));
|
||||
$this->assertTrue($o->check(''));
|
||||
$this->assertTrue($o->assert(''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,7 +78,6 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidAlnum()
|
||||
{
|
||||
return array(
|
||||
array('', ''),
|
||||
array('alganet', ''),
|
||||
array('alganet', 'alganet'),
|
||||
array('0alg-anet0', '0-9'),
|
||||
|
@ -100,6 +99,7 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidAlnum()
|
||||
{
|
||||
return array(
|
||||
array('', ''),
|
||||
array('@#$', ''),
|
||||
array('_', ''),
|
||||
array('dgç', ''),
|
||||
|
|
|
@ -78,7 +78,6 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidAlpha()
|
||||
{
|
||||
return array(
|
||||
array('', ''),
|
||||
array('alganet', ''),
|
||||
array('alganet', 'alganet'),
|
||||
array('0alg-anet0', '0-9'),
|
||||
|
@ -98,6 +97,7 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidAlpha()
|
||||
{
|
||||
return array(
|
||||
array('', ''),
|
||||
array('@#$', ''),
|
||||
array('_', ''),
|
||||
array('dgç', ''),
|
||||
|
|
|
@ -52,7 +52,6 @@ class ArrTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForArray()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(array()),
|
||||
array(array(1, 2, 3)),
|
||||
array(new TestAccess()),
|
||||
|
@ -69,6 +68,7 @@ class ArrTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotArray()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array(121),
|
||||
array(new \stdClass()),
|
||||
|
|
|
@ -83,9 +83,20 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($validator->__invoke($obj));
|
||||
$this->assertTrue($validator->assert($obj));
|
||||
$this->assertTrue($validator->check($obj));
|
||||
$this->assertTrue($validator->__invoke(''));
|
||||
$this->assertTrue($validator->assert(''));
|
||||
$this->assertTrue($validator->check(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\AttributeException
|
||||
*/
|
||||
public function testShouldNotValidateEmptyString()
|
||||
{
|
||||
$subValidator = new Length(1, 3);
|
||||
$validator = new Attribute('bar', $subValidator);
|
||||
$obj = new \stdClass();
|
||||
$obj->bar = 'foo';
|
||||
|
||||
$this->assertFalse($validator->__invoke(''));
|
||||
$validator->assert('');
|
||||
}
|
||||
|
||||
public function testExtraValidatorRulesForAttribute_should_fail_if_invalid()
|
||||
|
|
|
@ -65,13 +65,6 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForBase()
|
||||
{
|
||||
return array(
|
||||
array(2, ''),
|
||||
array(3, ''),
|
||||
array(8, ''),
|
||||
array(16, ''),
|
||||
array(20, ''),
|
||||
array(50, ''),
|
||||
array(62, ''),
|
||||
array(2, '011010001'),
|
||||
array(3, '0120122001'),
|
||||
array(8, '01234567520'),
|
||||
|
@ -85,6 +78,13 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidBase()
|
||||
{
|
||||
return array(
|
||||
array(2, ''),
|
||||
array(3, ''),
|
||||
array(8, ''),
|
||||
array(16, ''),
|
||||
array(20, ''),
|
||||
array(50, ''),
|
||||
array(62, ''),
|
||||
array(2, '01210103001'),
|
||||
array(3, '0120125f2001'),
|
||||
array(8, '01234dfZ567520'),
|
||||
|
|
|
@ -23,8 +23,6 @@ class BetweenTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerValid()
|
||||
{
|
||||
return array(
|
||||
array(10, 20, false, ''),
|
||||
array(10, 20, true, ''),
|
||||
array(0, 1, true, 0),
|
||||
array(0, 1, true, 1),
|
||||
array(10, 20, false, 15),
|
||||
|
@ -44,6 +42,8 @@ class BetweenTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerInvalid()
|
||||
{
|
||||
return array(
|
||||
array(10, 20, false, ''),
|
||||
array(10, 20, true, ''),
|
||||
array(0, 1, false, 0),
|
||||
array(0, 1, false, 1),
|
||||
array(0, 1, false, 2),
|
||||
|
|
|
@ -21,7 +21,6 @@ class BoolTest extends \PHPUnit_Framework_TestCase
|
|||
public function testBooleanValuesONLYShouldReturnTrue()
|
||||
{
|
||||
$validator = new Bool();
|
||||
$this->assertTrue($validator->__invoke(''));
|
||||
$this->assertTrue($validator->__invoke(true));
|
||||
$this->assertTrue($validator->__invoke(false));
|
||||
$this->assertTrue($validator->assert(true));
|
||||
|
@ -42,6 +41,7 @@ class BoolTest extends \PHPUnit_Framework_TestCase
|
|||
public function testInvalidBooleanValuesShouldReturnFalse()
|
||||
{
|
||||
$validator = new Bool();
|
||||
$this->assertFalse($validator->__invoke(''));
|
||||
$this->assertFalse($validator->__invoke('foo'));
|
||||
$this->assertFalse($validator->__invoke(123123));
|
||||
$this->assertFalse($validator->__invoke(new \stdClass()));
|
||||
|
|
|
@ -42,10 +42,12 @@ class CallbackTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($rule->validate(new \stdClass()));
|
||||
}
|
||||
|
||||
public function testCallbackValidatorShouldReturnTrueForEmptyString()
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\CallbackException
|
||||
*/
|
||||
public function testCallbackValidatorShouldReturnFalseForEmptyString()
|
||||
{
|
||||
$this->assertTrue($this->truthy->assert(''));
|
||||
$this->assertTrue($this->falsy->assert(''));
|
||||
$this->falsy->assert('');
|
||||
}
|
||||
|
||||
public function testCallbackValidatorShouldReturnTrueIfCallbackReturnsTrue()
|
||||
|
|
|
@ -68,7 +68,6 @@ class CnhTest extends \PHPUnit_Framework_TestCase
|
|||
public function validCnhProvider()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('02650306461'),
|
||||
array('04397322870'),
|
||||
array('04375701302'),
|
||||
|
@ -129,6 +128,7 @@ class CnhTest extends \PHPUnit_Framework_TestCase
|
|||
public function notIntegerCnhProvider()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('F265F3F6461'),
|
||||
array('F439732287F'),
|
||||
array('F43757F13F2'),
|
||||
|
|
|
@ -76,7 +76,6 @@ class CntrlTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidCntrl()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array("\n"),
|
||||
array("\r"),
|
||||
array("\t"),
|
||||
|
@ -88,6 +87,7 @@ class CntrlTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidCntrl()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('16-50'),
|
||||
array('a'),
|
||||
array(' '),
|
||||
|
|
|
@ -76,7 +76,6 @@ class ConsonantTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidConsonants()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('b'),
|
||||
array('c'),
|
||||
array('d'),
|
||||
|
@ -94,6 +93,7 @@ class ConsonantTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidConsonants()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('16'),
|
||||
array('aeiou'),
|
||||
|
|
|
@ -43,7 +43,6 @@ class ContainsTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForContains()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('foo', array('bar', 'foo')),
|
||||
array('foo', 'barbazFOO'),
|
||||
array('foo', 'barbazfoo'),
|
||||
|
@ -56,6 +55,7 @@ class ContainsTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotContains()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('bat', array('bar', 'foo')),
|
||||
array('foo', 'barfaabaz'),
|
||||
array('foo', 'barbazFOO', true),
|
||||
|
|
|
@ -71,7 +71,6 @@ class CpfTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerValidFormattedCpf()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('342.444.198-88'),
|
||||
array('342.444.198.88'),
|
||||
array('350.45261819'),
|
||||
|
@ -83,7 +82,6 @@ class CpfTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerValidUnformattedCpf()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('11598647644'),
|
||||
array('86734718697'),
|
||||
array('86223423284'),
|
||||
|
@ -95,6 +93,7 @@ class CpfTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerInvalidFormattedCpf()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('000.000.000-00'),
|
||||
array('111.222.444-05'),
|
||||
array('999999999.99'),
|
||||
|
|
|
@ -48,7 +48,6 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForCreditCard()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('5376 7473 9720 8720'), // MasterCard
|
||||
array('4024.0071.5336.1885'), // Visa 16
|
||||
array('4024 007 193 879'), // Visa 13
|
||||
|
@ -60,6 +59,7 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotCreditCard()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('it isnt my credit card number'),
|
||||
array('&stR@ng3|) (|-|@r$'),
|
||||
|
|
|
@ -27,11 +27,25 @@ class DateTest extends \PHPUnit_Framework_TestCase
|
|||
$this->dateValidator = new Date();
|
||||
}
|
||||
|
||||
public function testDateEmptyShouldValidate()
|
||||
public function testDateEmptyShouldNotValidate()
|
||||
{
|
||||
$this->assertTrue($this->dateValidator->__invoke(''));
|
||||
$this->assertTrue($this->dateValidator->check(''));
|
||||
$this->assertTrue($this->dateValidator->assert(''));
|
||||
$this->assertFalse($this->dateValidator->__invoke(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\DateException
|
||||
*/
|
||||
public function testDateEmptyShouldNotCheck()
|
||||
{
|
||||
$this->dateValidator->check('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\DateException
|
||||
*/
|
||||
public function testDateEmptyShouldNotAssert()
|
||||
{
|
||||
$this->dateValidator->assert('');
|
||||
}
|
||||
|
||||
public function testDateWithoutFormatShouldValidate()
|
||||
|
|
|
@ -76,7 +76,6 @@ class DigitTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidDigits()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array("\n\t"),
|
||||
array(' '),
|
||||
array(165),
|
||||
|
@ -93,6 +92,7 @@ class DigitTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidDigits()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('16-50'),
|
||||
array('a'),
|
||||
|
|
|
@ -73,7 +73,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase
|
|||
sys_get_temp_dir().DIRECTORY_SEPARATOR.'dataprovider-5',
|
||||
);
|
||||
|
||||
return array(array('')) + array_map(
|
||||
return array_map(
|
||||
function ($directory) {
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0766, true);
|
||||
|
@ -89,6 +89,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return array_chunk(
|
||||
array(
|
||||
'',
|
||||
__FILE__,
|
||||
__DIR__.'/../../../../../README.md',
|
||||
__DIR__.'/../../../../../composer.json',
|
||||
|
|
|
@ -120,7 +120,6 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidEmail()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('test@test.com'),
|
||||
array('mail+mail@gmail.com'),
|
||||
array('mail.email@e.test.com'),
|
||||
|
@ -131,6 +130,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidEmail()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('test@test'),
|
||||
array('test'),
|
||||
array('test@тест.рф'),
|
||||
|
|
|
@ -43,7 +43,6 @@ class EndsWithTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForEndsWith()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('foo', array('bar', 'foo')),
|
||||
array('foo', 'barbazFOO'),
|
||||
array('foo', 'barbazfoo'),
|
||||
|
@ -56,6 +55,7 @@ class EndsWithTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotEndsWith()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('bat', array('bar', 'foo')),
|
||||
array('foo', 'barfaabaz'),
|
||||
array('foo', 'barbazFOO', true),
|
||||
|
|
|
@ -43,7 +43,6 @@ class EqualsTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForEquals()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('foo', 'foo'),
|
||||
array(10, '10'),
|
||||
);
|
||||
|
@ -52,6 +51,7 @@ class EqualsTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotEquals()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('foo', 'bar'),
|
||||
array(10, '10', true),
|
||||
);
|
||||
|
|
|
@ -48,7 +48,6 @@ class FloatTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForFloat()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(165),
|
||||
array(1),
|
||||
array(0),
|
||||
|
@ -64,6 +63,7 @@ class FloatTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotFloat()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('a'),
|
||||
array(' '),
|
||||
|
|
|
@ -76,7 +76,6 @@ class GraphTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidGraph()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('LKA#@%.54'),
|
||||
array('foobar'),
|
||||
array('16-50'),
|
||||
|
@ -88,6 +87,7 @@ class GraphTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidGraph()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array("foo\nbar"),
|
||||
array("foo\tbar"),
|
||||
|
|
|
@ -53,7 +53,10 @@ class InTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForIn()
|
||||
{
|
||||
return array(
|
||||
array('', 'barfoobaz'),
|
||||
array('', array('')),
|
||||
array(null, array(null)),
|
||||
array('0', array('0')),
|
||||
array(0, array(0)),
|
||||
array('foo', array('foo', 'bar')),
|
||||
array('foo', 'barfoobaz'),
|
||||
array('foo', 'foobarbaz'),
|
||||
|
@ -66,6 +69,14 @@ class InTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotIn()
|
||||
{
|
||||
return array(
|
||||
array(null, '0'),
|
||||
array(null, 0, true),
|
||||
array(null, '', true),
|
||||
array(null, array()),
|
||||
array('', 'barfoobaz'),
|
||||
array(null, 'barfoobaz'),
|
||||
array(0, 'barfoobaz'),
|
||||
array('0', 'barfoobaz'),
|
||||
array('bat', array('foo', 'bar')),
|
||||
array('foo', 'barfaabaz'),
|
||||
array('foo', 'faabarbaz'),
|
||||
|
|
|
@ -25,11 +25,29 @@ class InstanceTest extends \PHPUnit_Framework_TestCase
|
|||
$this->instanceValidator = new Instance('ArrayObject');
|
||||
}
|
||||
|
||||
public function testInstanceValidationShouldReturnFalseForEmpty()
|
||||
{
|
||||
$this->assertFalse($this->instanceValidator->__invoke(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\InstanceException
|
||||
*/
|
||||
public function testInstanceValidationShouldNotAssertEmpty()
|
||||
{
|
||||
$this->instanceValidator->assert('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\InstanceException
|
||||
*/
|
||||
public function testInstanceValidationShouldNotCheckEmpty()
|
||||
{
|
||||
$this->instanceValidator->check('');
|
||||
}
|
||||
|
||||
public function testInstanceValidationShouldReturnTrueForValidInstances()
|
||||
{
|
||||
$this->assertTrue($this->instanceValidator->__invoke(''));
|
||||
$this->assertTrue($this->instanceValidator->assert(''));
|
||||
$this->assertTrue($this->instanceValidator->check(''));
|
||||
$this->assertTrue($this->instanceValidator->__invoke(new \ArrayObject()));
|
||||
$this->assertTrue($this->instanceValidator->assert(new \ArrayObject()));
|
||||
$this->assertTrue($this->instanceValidator->check(new \ArrayObject()));
|
||||
|
|
|
@ -48,7 +48,6 @@ class IntTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInt()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(16),
|
||||
array('165'),
|
||||
array(123456),
|
||||
|
@ -59,6 +58,7 @@ class IntTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotInt()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('a'),
|
||||
array(' '),
|
||||
|
|
|
@ -65,7 +65,6 @@ class IpTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForIp()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('127.0.0.1'),
|
||||
);
|
||||
}
|
||||
|
@ -96,6 +95,7 @@ class IpTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotIp()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('j'),
|
||||
array(' '),
|
||||
|
|
|
@ -44,10 +44,14 @@ class JsonTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertFalse($this->json->assert('{foo:bar}'));
|
||||
}
|
||||
|
||||
public function testInvalidJsonsNotBeValid()
|
||||
{
|
||||
$this->assertFalse($this->json->validate(''));
|
||||
}
|
||||
|
||||
public function providerForPass()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('2'),
|
||||
array('"abc"'),
|
||||
array('[1,2,3]'),
|
||||
|
|
|
@ -28,14 +28,30 @@ class KeyTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($validator->validate($obj));
|
||||
}
|
||||
|
||||
public function testEmptyInputMustReturnTrue()
|
||||
public function testEmptyInputMustReturnFalse()
|
||||
{
|
||||
$validator = new Key('someEmptyKey');
|
||||
$input = '';
|
||||
|
||||
$this->assertTrue($validator->assert($input));
|
||||
$this->assertTrue($validator->check($input));
|
||||
$this->assertTrue($validator->validate($input));
|
||||
$this->assertFalse($validator->validate($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\KeyException
|
||||
*/
|
||||
public function testEmptyInputMustNotAssert()
|
||||
{
|
||||
$validator = new Key('someEmptyKey');
|
||||
$validator->assert('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\KeyException
|
||||
*/
|
||||
public function testEmptyInputMustNotCheck()
|
||||
{
|
||||
$validator = new Key('someEmptyKey');
|
||||
$validator->check('');
|
||||
}
|
||||
|
||||
public function testArrayWithEmptyKeyShouldReturnTrue()
|
||||
|
|
|
@ -29,7 +29,6 @@ class LeapYearTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testValidLeapDate()
|
||||
{
|
||||
$this->assertTrue($this->leapYearValidator->__invoke(''));
|
||||
$this->assertTrue($this->leapYearValidator->__invoke('2008'));
|
||||
$this->assertTrue($this->leapYearValidator->__invoke('2008-02-29'));
|
||||
$this->assertTrue($this->leapYearValidator->__invoke(2008));
|
||||
|
@ -39,6 +38,7 @@ class LeapYearTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testInvalidLeapDate()
|
||||
{
|
||||
$this->assertFalse($this->leapYearValidator->__invoke(''));
|
||||
$this->assertFalse($this->leapYearValidator->__invoke('2009'));
|
||||
$this->assertFalse($this->leapYearValidator->__invoke('2009-02-29'));
|
||||
$this->assertFalse($this->leapYearValidator->__invoke(2009));
|
||||
|
|
|
@ -65,7 +65,6 @@ class LengthTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidLength()
|
||||
{
|
||||
return array(
|
||||
array('', 1, 15),
|
||||
array('alganet', 1, 15),
|
||||
array('ççççç', 4, 6),
|
||||
array(range(1, 20), 1, 30),
|
||||
|
@ -78,6 +77,7 @@ class LengthTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidLengthInclusive()
|
||||
{
|
||||
return array(
|
||||
array('', 1, 15),
|
||||
array('alganet', 1, 7),
|
||||
array(range(1, 20), 1, 20),
|
||||
array('alganet', 7, null), //null is a valid max length, means "no maximum",
|
||||
|
|
|
@ -48,7 +48,6 @@ class MacAddressTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForMacAddress()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('00:11:22:33:44:55'),
|
||||
array('66-77-88-99-aa-bb'),
|
||||
array('AF:0F:bd:12:44:ba'),
|
||||
|
@ -59,6 +58,7 @@ class MacAddressTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotMacAddress()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('00-1122:33:44:55'),
|
||||
array('66-77--99-jj-bb'),
|
||||
array('HH:0F-bd:12:44:ba'),
|
||||
|
|
|
@ -45,8 +45,6 @@ class MinTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidMin()
|
||||
{
|
||||
return array(
|
||||
array(100, true, ''),
|
||||
array(100, false, ''),
|
||||
array(100, false, 165.0),
|
||||
array(-100, false, 200),
|
||||
array(200, true, 200),
|
||||
|
@ -66,6 +64,8 @@ class MinTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidMin()
|
||||
{
|
||||
return array(
|
||||
array(100, true, ''),
|
||||
array(100, false, ''),
|
||||
array(500, false, 300),
|
||||
array(0, false, -250),
|
||||
array(0, false, -50),
|
||||
|
|
|
@ -48,7 +48,6 @@ class NegativeTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNegative()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('-1.44'),
|
||||
array(-1e-5),
|
||||
array(-10),
|
||||
|
@ -58,6 +57,7 @@ class NegativeTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotNegative()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(0),
|
||||
array(-0),
|
||||
array(null),
|
||||
|
|
|
@ -55,6 +55,7 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidNot()
|
||||
{
|
||||
return array(
|
||||
array(new Int(), ''),
|
||||
array(new Int(), 'aaa'),
|
||||
array(new AllOf(new NoWhitespace(), new Digit()), 'as df'),
|
||||
array(new AllOf(new NoWhitespace(), new Digit()), '12 34'),
|
||||
|
@ -68,7 +69,6 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidNot()
|
||||
{
|
||||
return array(
|
||||
array(new Int(), ''),
|
||||
array(new Int(), 123),
|
||||
array(new AllOf(new OneOf(new Numeric(), new Int())), 13.37),
|
||||
array(new OneOf(new Numeric(), new Int()), 13.37),
|
||||
|
|
|
@ -48,7 +48,6 @@ class NumericTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNumeric()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(165),
|
||||
array(165.0),
|
||||
array(-165),
|
||||
|
@ -61,6 +60,7 @@ class NumericTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotNumeric()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('a'),
|
||||
array(' '),
|
||||
|
|
|
@ -48,7 +48,6 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForObject()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(new \stdClass()),
|
||||
array(new \ArrayObject()),
|
||||
);
|
||||
|
@ -57,6 +56,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotObject()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array(121),
|
||||
array(array()),
|
||||
|
|
|
@ -48,7 +48,6 @@ class OddTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForOdd()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(-5),
|
||||
array(-1),
|
||||
array(1),
|
||||
|
@ -59,6 +58,7 @@ class OddTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotOdd()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(-2),
|
||||
array(-0),
|
||||
array(0),
|
||||
|
|
|
@ -48,7 +48,6 @@ class PerfectSquareTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForPerfectSquare()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(1),
|
||||
array(9),
|
||||
array(25),
|
||||
|
@ -65,6 +64,7 @@ class PerfectSquareTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotPerfectSquare()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array(7),
|
||||
array(-1),
|
||||
|
|
|
@ -48,7 +48,6 @@ class PhoneTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForPhone()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('+5-555-555-5555'),
|
||||
array('+5 555 555 5555'),
|
||||
array('+5.555.555.5555'),
|
||||
|
@ -100,6 +99,7 @@ class PhoneTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotPhone()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('123'),
|
||||
array('s555-5555'),
|
||||
array('555-555'),
|
||||
|
|
|
@ -48,7 +48,6 @@ class PositiveTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForPositive()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(16),
|
||||
array('165'),
|
||||
array(123456),
|
||||
|
@ -59,6 +58,7 @@ class PositiveTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotPositive()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('a'),
|
||||
array(' '),
|
||||
|
|
|
@ -48,7 +48,6 @@ class PrimeNumberTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForPrimeNumber()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(3),
|
||||
array(5),
|
||||
array(7),
|
||||
|
@ -61,6 +60,7 @@ class PrimeNumberTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotPrimeNumber()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array(0),
|
||||
array(10),
|
||||
|
|
|
@ -76,7 +76,6 @@ class PrntTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidPrint()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(' '),
|
||||
array('LKA#@%.54'),
|
||||
array('foobar'),
|
||||
|
@ -90,6 +89,7 @@ class PrntTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidPrint()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('foo'.chr(7).'bar'),
|
||||
array('foo'.chr(10).'bar'),
|
||||
|
|
|
@ -76,7 +76,6 @@ class PunctTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidPunct()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('.'),
|
||||
array(',;:'),
|
||||
array('-@#$*'),
|
||||
|
@ -87,6 +86,7 @@ class PunctTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidPunct()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('16-50'),
|
||||
array('a'),
|
||||
array(' '),
|
||||
|
|
|
@ -48,7 +48,6 @@ class SlugTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerValidSlug()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('o-rato-roeu-o-rei-de-roma'),
|
||||
array('o-alganet-e-um-feio'),
|
||||
array('a-e-i-o-u'),
|
||||
|
@ -59,6 +58,7 @@ class SlugTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerInvalidSlug()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('o-alganet-é-um-feio'),
|
||||
array('á-é-í-ó-ú'),
|
||||
array('-assim-nao-pode'),
|
||||
|
|
|
@ -76,7 +76,6 @@ class SpaceTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidSpace()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array("\n"),
|
||||
array(' '),
|
||||
array(' '),
|
||||
|
@ -88,6 +87,7 @@ class SpaceTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidSpace()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('16-50'),
|
||||
array('a'),
|
||||
array('Foo'),
|
||||
|
|
|
@ -43,7 +43,6 @@ class StartsWithTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForStartsWith()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('foo', array('foo', 'bar')),
|
||||
array('foo', 'FOObarbaz'),
|
||||
array('foo', 'foobarbaz'),
|
||||
|
@ -56,6 +55,7 @@ class StartsWithTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotStartsWith()
|
||||
{
|
||||
return array(
|
||||
array('foo', ''),
|
||||
array('bat', array('foo', 'bar')),
|
||||
array('foo', 'barfaabaz'),
|
||||
array('foo', 'FOObarbaz', true),
|
||||
|
|
|
@ -43,7 +43,6 @@ class VersionTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidVersion()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('1.0.0'),
|
||||
array('1.0.0-alpha'),
|
||||
array('1.0.0-alpha.1'),
|
||||
|
@ -57,6 +56,7 @@ class VersionTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidVersion()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('1.3.7--'),
|
||||
array('1.3.7++'),
|
||||
array('foo'),
|
||||
|
|
|
@ -76,7 +76,6 @@ class VowelTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForValidVowels()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('a'),
|
||||
array('e'),
|
||||
array('i'),
|
||||
|
@ -92,6 +91,7 @@ class VowelTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForInvalidVowels()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('16'),
|
||||
array('F'),
|
||||
|
|
|
@ -65,7 +65,6 @@ class XdigitTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForXdigit()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('FFF'),
|
||||
array('15'),
|
||||
array('DE12FA'),
|
||||
|
@ -77,6 +76,7 @@ class XdigitTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerForNotXdigit()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('j'),
|
||||
array(' '),
|
||||
|
|
Loading…
Reference in a new issue