mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 11:52:34 +02:00
Several new validators (Int, In, Negative, Positive, String). Refactored Length to work with strings and arrays. Better tests for several validators. Updated README and PEAR package file.
This commit is contained in:
parent
896fe166c8
commit
9a5536dd69
|
@ -27,12 +27,12 @@ h3. Chained validation
|
|||
$username = 'alganet';
|
||||
$validUsername = v::alnum()
|
||||
->noWhitespace()
|
||||
->stringLength(1,15)
|
||||
->length(1,15)
|
||||
->validate($username);
|
||||
</pre>
|
||||
<pre>
|
||||
//Date between two ranges using a specific format
|
||||
$someDate = '2010-10-15';
|
||||
$someDate = new DateTime('2010-10-15');
|
||||
$validDate = v::date('Y-m-d')
|
||||
->between(
|
||||
new DateTime('2009-01-01'),
|
||||
|
@ -45,15 +45,15 @@ h3. Validating object attributes
|
|||
$user->name = 'Alexandre';
|
||||
$user->birthdate = '1987-07-01';
|
||||
$validUser = v::all(
|
||||
v::hasAttribute('name', v::notEmpty()),
|
||||
v::hasAttribute('birthdate, v::date('Y-m-d'))
|
||||
v::attribute('name', v::notEmpty()),
|
||||
v::attribute('birthdate, v::date('Y-m-d'))
|
||||
);</pre>
|
||||
|
||||
h3. Combining rules (v::oneOf, v::allOf, v::atLeast, v::mostOf, v::noneOf)
|
||||
|
||||
<pre>$validDate = v::oneOf(
|
||||
v::date('Y-m-d'),
|
||||
v::date('y-m-d'), //two-digit year
|
||||
v::date('y m d'),
|
||||
v::date('d/m/Y')
|
||||
);</pre>
|
||||
|
||||
|
@ -66,7 +66,7 @@ h3. Compositing rules
|
|||
$valid = v::atLeast(2, array(
|
||||
v::oneOf(v::numeric(), v::alnum()),
|
||||
v::date('Ymd'),
|
||||
v::stringLength(3,12)->noWhitespace()
|
||||
v::string()->length(3,12)->noWhitespace()
|
||||
));</pre>
|
||||
|
||||
h3. Cool, informative exceptions:
|
||||
|
@ -75,14 +75,14 @@ h3. Cool, informative exceptions:
|
|||
$username = '#$% #odjfubgihdbfgihbdfighb';
|
||||
$validUsername = v::alnum('_')
|
||||
->noWhitespace()
|
||||
->stringLength(1,15)
|
||||
->length(1,15)
|
||||
->assert($username);
|
||||
} catch(v\Exceptions\InvalidException $e) {
|
||||
/*
|
||||
Respect\Validation\Exceptions\InvalidException:
|
||||
#$% #odjfubgihdbfgihbdfighb does not contains only letters and digits (including _)
|
||||
#$% #odjfubgihdbfgihbdfighb contains spaces, tabs, line breaks or other not allowed charaters.
|
||||
#$% #odjfubgihdbfgihbdfighb exceeds the maximum of 15 characters
|
||||
Respect\Validation\Exceptions\AllOfException: None of 3 required rules passed
|
||||
-"#$% #odjfubgihdbfgihbdfighb" does not contain only letters, digits and "_"
|
||||
-"#$% #odjfubgihdbfgihbdfighb" contains whitespace
|
||||
-"#$% #odjfubgihdbfgihbdfighb" length is not between 1 and 15
|
||||
*/
|
||||
echo $e->getMessage();
|
||||
}</pre>
|
||||
|
|
|
@ -4,9 +4,9 @@ namespace Respect\Validation\Exceptions;
|
|||
|
||||
class FloatException extends ValidationException
|
||||
{
|
||||
const INVALID_= 'Float_1';
|
||||
const INVALID_FLOAT= 'Float_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_ => '"%s" is not a valid float',
|
||||
self::INVALID_FLOAT => '"%s" is not a valid float',
|
||||
);
|
||||
|
||||
|
||||
}
|
|
@ -8,5 +8,5 @@ class HexaException extends ValidationException
|
|||
public static $defaultTemplates = array(
|
||||
self::INVALID_HEXA => '"%s" is not a valid hexadecimal number',
|
||||
);
|
||||
|
||||
|
||||
}
|
12
library/Respect/Validation/Exceptions/InException.php
Normal file
12
library/Respect/Validation/Exceptions/InException.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class InException extends ValidationException
|
||||
{
|
||||
const INVALID_IN = 'In_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_IN => '"%s" is not in %s',
|
||||
);
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ class InstanceException extends ValidationException
|
|||
{
|
||||
const INVALID_INSTANCE= 'Instance_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_INSTANCE => '"%s" is not an instance "%s"',
|
||||
self::INVALID_INSTANCE => '"%s" is not an instance of "%s"',
|
||||
);
|
||||
|
||||
}
|
12
library/Respect/Validation/Exceptions/IntException.php
Normal file
12
library/Respect/Validation/Exceptions/IntException.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class IntException extends ValidationException
|
||||
{
|
||||
const INVALID_INT= 'Int_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_INT => '"%s" is not a valid integer number',
|
||||
);
|
||||
|
||||
}
|
12
library/Respect/Validation/Exceptions/LengthException.php
Normal file
12
library/Respect/Validation/Exceptions/LengthException.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class LengthException extends ValidationException
|
||||
{
|
||||
const INVALID_LENGTH= 'Length_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_LENGTH => '"%s" length is not between %d and %d',
|
||||
);
|
||||
|
||||
}
|
|
@ -5,8 +5,17 @@ namespace Respect\Validation\Exceptions;
|
|||
class MaxException extends ValidationException
|
||||
{
|
||||
const INVALID_MAX= 'Max_1';
|
||||
const INVALID_MAX_INCLUSIVE= 'Max_2';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_MAX => '%s is greater than %s',
|
||||
self::INVALID_MAX_INCLUSIVE => '%s is greater than %s (inclusive)',
|
||||
);
|
||||
public function chooseTemplate($input, $inclusive)
|
||||
{
|
||||
if ($inclusive)
|
||||
return self::INVALID_MAX;
|
||||
else
|
||||
return self::INVALID_MAX_INCLUSIVE;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,8 +5,18 @@ namespace Respect\Validation\Exceptions;
|
|||
class MinException extends ValidationException
|
||||
{
|
||||
const INVALID_MIN= 'Min_1';
|
||||
const INVALID_MIN_INCLUSIVE= 'Min_2';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_MIN => '%s is lower than %s',
|
||||
self::INVALID_MIN_INCLUSIVE => '%s is lower than %s (inclusive)',
|
||||
);
|
||||
|
||||
public function chooseTemplate($input, $inclusive)
|
||||
{
|
||||
if ($inclusive)
|
||||
return self::INVALID_MIN;
|
||||
else
|
||||
return self::INVALID_MIN_INCLUSIVE;
|
||||
}
|
||||
|
||||
}
|
12
library/Respect/Validation/Exceptions/NegativeException.php
Normal file
12
library/Respect/Validation/Exceptions/NegativeException.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class NegativeException extends ValidationException
|
||||
{
|
||||
const INVALID_NEGATIVE= 'Negative_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_NEGATIVE => '%d is not a negative number',
|
||||
);
|
||||
|
||||
}
|
|
@ -6,8 +6,8 @@ class OneOfException extends AbstractCompositeException
|
|||
{
|
||||
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_NONE => 'None of the %3$d rules passed',
|
||||
self::INVALID_SOME => '%2$d of the %3$d rules did not passed',
|
||||
self::INVALID_NONE => 'None of the %4$d rules passed',
|
||||
self::INVALID_SOME => '%2$d of the %4$d rules did not passed',
|
||||
);
|
||||
|
||||
}
|
12
library/Respect/Validation/Exceptions/PositiveException.php
Normal file
12
library/Respect/Validation/Exceptions/PositiveException.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class PositiveException extends ValidationException
|
||||
{
|
||||
const INVALID_POSITIVE= 'Positive_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_POSITIVE => '%d is not a positive number',
|
||||
);
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ class RegexException extends ValidationException
|
|||
{
|
||||
const INVALID_REGEX= 'Regex_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_REGEX => '"%s" did not validated against the "%s" expression',
|
||||
self::INVALID_REGEX => '"%s" is invalid',
|
||||
);
|
||||
|
||||
}
|
12
library/Respect/Validation/Exceptions/StringException.php
Normal file
12
library/Respect/Validation/Exceptions/StringException.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class StringException extends ValidationException
|
||||
{
|
||||
const INVALID_STRING= 'String_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_STRING => '"%s" is not a valid string',
|
||||
);
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class StringLengthException extends ValidationException
|
||||
{
|
||||
const INVALID_LENGTH= 'StringLength_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_LENGTH => '"%s" length out of bounds',
|
||||
);
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ class Alnum extends Alpha
|
|||
{
|
||||
|
||||
protected $additionalChars = '';
|
||||
protected $stringFormat = '#^[a-zA-Z0-9]+$#';
|
||||
protected $stringFormat = '#^([a-zA-Z0-9]|\s)+$#';
|
||||
|
||||
public function assert($input)
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ class Alpha extends AbstractRule
|
|||
{
|
||||
|
||||
protected $additionalChars = '';
|
||||
protected $stringFormat = '#^[a-zA-Z]+$#';
|
||||
protected $stringFormat = '#^([a-zA-Z]|\s)+$#';
|
||||
|
||||
public function __construct($additionalChars='')
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ use Respect\Validation\Exceptions\ValidationException;
|
|||
class Between extends AllOf
|
||||
{
|
||||
|
||||
public function __construct($min=null, $max=null)
|
||||
public function __construct($min=null, $max=null, $inclusive=false)
|
||||
{
|
||||
if (!is_null($min) && !is_null($max) && $min > $max)
|
||||
throw new ComponentException(
|
||||
|
@ -17,9 +17,9 @@ class Between extends AllOf
|
|||
)
|
||||
);
|
||||
if (!is_null($min))
|
||||
$this->addRule(new Min($min));
|
||||
$this->addRule(new Min($min, $inclusive));
|
||||
if (!is_null($max))
|
||||
$this->addRule(new Max($max));
|
||||
$this->addRule(new Max($max, $inclusive));
|
||||
}
|
||||
|
||||
}
|
40
library/Respect/Validation/Rules/In.php
Normal file
40
library/Respect/Validation/Rules/In.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class In extends AbstractRule
|
||||
{
|
||||
|
||||
protected $options;
|
||||
protected $strict;
|
||||
|
||||
public function __construct($options, $strict=false)
|
||||
{
|
||||
$this->options = $options;
|
||||
$this->strict = $strict;
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
if (is_array($this->options))
|
||||
return in_array($input, $this->options, $this->strict);
|
||||
elseif (is_string($this->options))
|
||||
if ($this->strict)
|
||||
return mb_strpos($this->options, $input) !== false;
|
||||
else
|
||||
return mb_stripos($this->options, $input) !== false;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function assert($input)
|
||||
{
|
||||
if (!$this->validate($input))
|
||||
throw $this->getException() ? : $this->createException()
|
||||
->configure(
|
||||
$input, print_r($this->options, true), $this->strict
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
13
library/Respect/Validation/Rules/Int.php
Normal file
13
library/Respect/Validation/Rules/Int.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Int extends AbstractRule
|
||||
{
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return is_numeric($input) && (int) $input == $input;
|
||||
}
|
||||
|
||||
}
|
89
library/Respect/Validation/Rules/Length.php
Normal file
89
library/Respect/Validation/Rules/Length.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Rules\AbstractRule;
|
||||
use Respect\Validation\Exceptions\LengthException;
|
||||
use Respect\Validation\Validator;
|
||||
use Respect\Validation\Exceptions\NotNumericException;
|
||||
use Respect\Validation\Exceptions\ComponentException;
|
||||
use Respect\Validation\Exceptions\InvalidException;
|
||||
|
||||
class Length extends AbstractRule
|
||||
{
|
||||
|
||||
protected $min;
|
||||
protected $max;
|
||||
protected $inclusive;
|
||||
|
||||
public function __construct($min=null, $max=null, $inclusive=true)
|
||||
{
|
||||
$this->min = $min;
|
||||
$this->max = $max;
|
||||
$this->inclusive = $inclusive;
|
||||
$paramValidator = new OneOf(new Numeric, new NullValue);
|
||||
if (!$paramValidator->validate($min))
|
||||
throw new ComponentException(
|
||||
sprintf('%s is not a valid numeric length', $min)
|
||||
);
|
||||
|
||||
if (!$paramValidator->validate($max))
|
||||
throw new ComponentException(
|
||||
sprintf('%s is not a valid numeric length', $max)
|
||||
);
|
||||
|
||||
if (!is_null($min) && !is_null($max) && $min > $max) {
|
||||
throw new ComponentException(
|
||||
sprintf('%s cannot be less than %s for validation', $min, $max)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function extractLength($input)
|
||||
{
|
||||
if (is_string($input))
|
||||
return mb_strlen($input);
|
||||
elseif (is_array($input))
|
||||
return count($input);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function validateMin($input)
|
||||
{
|
||||
$length = $this->extractLength($input);
|
||||
if (is_null($this->min))
|
||||
return true;
|
||||
if ($this->inclusive)
|
||||
return $length >= $this->min;
|
||||
else
|
||||
return $length > $this->min;
|
||||
}
|
||||
|
||||
public function validateMax($input)
|
||||
{
|
||||
$length = $this->extractLength($input);
|
||||
if (is_null($this->max))
|
||||
return true;
|
||||
if ($this->inclusive)
|
||||
return $length <= $this->max;
|
||||
else
|
||||
return $length < $this->max;
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return $this->validateMin($input) && $this->validateMax($input);
|
||||
}
|
||||
|
||||
public function assert($input)
|
||||
{
|
||||
if (!$this->validate($input))
|
||||
throw $this->getException() ? : $this->createException()
|
||||
->configure(
|
||||
$input, $this->min, $this->max
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,22 +6,27 @@ class Max extends AbstractRule
|
|||
{
|
||||
|
||||
protected $max;
|
||||
protected $inclusive;
|
||||
|
||||
public function __construct($maxValue)
|
||||
public function __construct($maxValue, $inclusive=false)
|
||||
{
|
||||
$this->max = $maxValue;
|
||||
$this->inclusive = $inclusive;
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return $input <= $this->max;
|
||||
if ($this->inclusive)
|
||||
return $input <= $this->max;
|
||||
else
|
||||
return $input < $this->max;
|
||||
}
|
||||
|
||||
public function assert($input)
|
||||
{
|
||||
if (!$this->validate($input))
|
||||
throw $this->getException() ? : $this->createException()
|
||||
->configure($input, $this->max);
|
||||
->configure($input, $this->max, $this->inclusive);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,22 +6,27 @@ class Min extends AbstractRule
|
|||
{
|
||||
|
||||
protected $min;
|
||||
protected $inclusive;
|
||||
|
||||
public function __construct($minValue)
|
||||
public function __construct($minValue, $inclusive=false)
|
||||
{
|
||||
$this->min = $minValue;
|
||||
$this->inclusive = $inclusive;
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return $input >= $this->min;
|
||||
if ($this->inclusive)
|
||||
return $input >= $this->min;
|
||||
else
|
||||
return $input > $this->min;
|
||||
}
|
||||
|
||||
public function assert($input)
|
||||
{
|
||||
if (!$this->validate($input))
|
||||
throw $this->getException() ? : $this->createException()
|
||||
->configure($input, $this->min);
|
||||
->configure($input, $this->min, $this->inclusive);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
13
library/Respect/Validation/Rules/Negative.php
Normal file
13
library/Respect/Validation/Rules/Negative.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Negative extends AbstractRule
|
||||
{
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return $input < 0;
|
||||
}
|
||||
|
||||
}
|
13
library/Respect/Validation/Rules/Positive.php
Normal file
13
library/Respect/Validation/Rules/Positive.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Positive extends AbstractRule
|
||||
{
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return $input > 0;
|
||||
}
|
||||
|
||||
}
|
13
library/Respect/Validation/Rules/String.php
Normal file
13
library/Respect/Validation/Rules/String.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class String extends AbstractRule
|
||||
{
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return is_string($input);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Validatable;
|
||||
use Respect\Validation\Exceptions\ComponentException;
|
||||
|
||||
class StringLength extends Between
|
||||
{
|
||||
|
||||
public function __construct($min=null, $max=null)
|
||||
{
|
||||
$paramValidator = new OneOf(new Numeric, new NullValue);
|
||||
if (!$paramValidator->validate($min))
|
||||
throw new ComponentException(
|
||||
sprintf('%s is not a valid numeric length', $min)
|
||||
);
|
||||
|
||||
if (!$paramValidator->validate($max))
|
||||
throw new ComponentException(
|
||||
sprintf('%s is not a valid numeric length', $max)
|
||||
);
|
||||
if (!is_null($min) && !is_null($max) && $min > $max)
|
||||
throw new ComponentException(
|
||||
sprintf(
|
||||
'%s cannot be less than %s for validation', $min, $max
|
||||
)
|
||||
);
|
||||
if (!is_null($min))
|
||||
$this->addRule(new Call('strlen', new Min($min)));
|
||||
if (!is_null($max))
|
||||
$this->addRule(new Call('strlen', new Max($max)));
|
||||
}
|
||||
|
||||
}
|
|
@ -10,8 +10,8 @@
|
|||
<email>alexandre@gaigalas.net</email>
|
||||
<active>yes</active>
|
||||
</lead>
|
||||
<date>2010-12-06</date>
|
||||
<time>18:35:30</time>
|
||||
<date>2010-12-07</date>
|
||||
<time>17:17:32</time>
|
||||
<version>
|
||||
<release>0.1.0</release>
|
||||
<api>0.1.0</api>
|
||||
|
@ -31,56 +31,69 @@ First Version
|
|||
<file baseinstalldir="Respect/Validation" md5sum="4289b2053b7ab5c91fcc405f8faaff41" name="Exceptions/AlnumException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="e35e1c9f991cfb639905d7b3e1adf158" name="Exceptions/AlphaException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="67e61d17308657a5d4f7b85cb35bb9d9" name="Exceptions/ArrException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="8a83d51575c06ad013e09d52bc04c86a" name="Exceptions/AtLeastException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="46cb557a64f078d55acc85b7c6120d17" name="Exceptions/AtLeastException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="0bc8177eb2b29c60511effe6e74e3e19" name="Exceptions/AttributeException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="9b8af2fd7fbcaf5b209f5eb0c7481205" name="Exceptions/BetweenException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="14ad1a0e0bd01b8c406040b7a8644f1d" name="Exceptions/CallbackException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ddae18ee18fd6fc523e8c5bb473911fc" name="Exceptions/CallException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="dccb83d6730328467bd0935caea42b04" name="Exceptions/ComponentException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="6f69e750f52d701e4e36e69f1b157ce1" name="Exceptions/DateException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="aa654a828c3bd02c067d34a4c121ea33" name="Exceptions/DigitsException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ea8bc62d6101b8d4af6b4fcd2b1fcd89" name="Exceptions/EachException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="547caec40bef5dafe3a34705cf886620" name="Exceptions/FloatException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="6de960b36003ab8d0954a1198380e684" name="Exceptions/HexaException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="e920410e8f9e48a382d2c27842f9c921" name="Exceptions/InstanceException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="fb5de51195fbd1973c3663d7c3fda8b8" name="Exceptions/EqualsException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d811e37b91d4ad52b0c3db6d3462206a" name="Exceptions/FloatException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="8594832e050435e5c73e79280c45addc" name="Exceptions/HexaException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ce6dfb62cdcc171345eabe6cef5fd366" name="Exceptions/InException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="c6367809734bc027c2fd51fbd4653653" name="Exceptions/InstanceException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="3625c35fdff055bcfb63ba5b15aa0c08" name="Exceptions/IntException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="f9066799ff7408038755c422ede9cde5" name="Exceptions/IpException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="10917fb1b09f27bb48390b1538311239" name="Exceptions/KeyException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="4d38e3cc170cb821162dbea3aa8bc966" name="Exceptions/MaxException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d728feb109706bc544df45e1a3e7faf7" name="Exceptions/MinException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="b3cb24a88fbac14bf7942a53ee84100a" name="Exceptions/LengthException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d53024a7f3e05e850e9ec5591f4f4cf8" name="Exceptions/MaxException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="159cf702d687addff38791230d1a0afc" name="Exceptions/MinException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="61678af7b5c5d3b6593a8e74f08d98da" name="Exceptions/MostOfException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="dbdd46e305da7d5a65e17015380bd474" name="Exceptions/NegativeException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="8e72696f3e00c044be35cc3b324548f1" name="Exceptions/NoneOfException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="037674a96816f614f630145dc3d43e93" name="Exceptions/NotEmptyException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="bcc206e96a0dbe7bd03569b20669b2d4" name="Exceptions/NoWhitespaceException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="989d2e511e58cd69d0c20c16a4c6546f" name="Exceptions/NullValueException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="6707081a6d24242408fb7dab382e73d2" name="Exceptions/NumericException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="8ba1174f2e8b9e4152b35206876a539d" name="Exceptions/ObjectException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="2e222d5efb3f98acc41d06caf4026216" name="Exceptions/OneOfException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="4093b2f14cc1b7d5edf64d9e8e3d2b4b" name="Exceptions/RegexException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="2f078aa5cfb3a8b0a7e89e2edbe8d075" name="Exceptions/OneOfException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="9e7a1a64ebf8366f3d2f60ab8e623ec7" name="Exceptions/PositiveException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="aa3eb09ebf08837c75d7d7dd744ecdfc" name="Exceptions/RegexException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="8a6bbc2d9bc72292c12116b7acf54c28" name="Exceptions/SfException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="0ddb89d6bbcc92aa5c6ae47129a824df" name="Exceptions/StringLengthException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="6b8d7ffcb82edaccbefccbfe44dbc22d" name="Exceptions/StringException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="b1996ee3bc0a331e7cedfaba804cd485" name="Exceptions/ValidationException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d6bebfa5a114db5f77965c854c190b83" name="Exceptions/ZendException.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="afb715ca150a699600581cf0662e3ea8" name="Rules/AbstractComposite.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="03ebbdde20f2f314cefea975194a7f5b" name="Rules/AbstractRelated.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="606deb5261dbd86da531a35abcd05ea2" name="Rules/AbstractRule.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="b67df2d035ec4c7894a8d625def11eaa" name="Rules/AbstractRelated.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ae731c4b8fcc4b2d5e470b8c1faae6dd" name="Rules/AbstractRule.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="77a90010ca6ea9c687426b1b870770ec" name="Rules/AllOf.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="7131a2645c17a47a04c1d26d193b193f" name="Rules/Alnum.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="8bec0e99237449b7a44e8256f343c30b" name="Rules/Alpha.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="698c5305baff4a40d732a0f2f9f9066c" name="Rules/Alnum.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="dc721027b68ebd939a50147ddf4e7ee0" name="Rules/Alpha.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="e20e974875347cf7c9b0ba76061138e2" name="Rules/Arr.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ce7093ba089f333cdf48a4b83f361716" name="Rules/AtLeast.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="da6806591fcc0a25ad55a0372dc7562f" name="Rules/Attribute.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="4f3adc89eba0f5eddb5fe5fddadf2bdc" name="Rules/Between.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="6828c2d9826a7ad523d5b96378c1042d" name="Rules/Callback.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="46b15803d4f90d1d7b1462b1aa2c9951" name="Rules/AtLeast.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="90a42cc5da8ea72e1ca54137482c432c" name="Rules/Attribute.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="0e5a580ff3090d106df1e02c5882ef57" name="Rules/Between.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d51ab5f4b302720d988d39f84e145851" name="Rules/Call.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="b6837ae1fd632cedab0a460fd0ed8ea2" name="Rules/Callback.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ac564489c5972033525c5994cea1c241" name="Rules/Date.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="f6cee7a9c23415c07318af3dbcdba94b" name="Rules/Digits.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="2963b04502fabb796b174dcb7ef775ad" name="Rules/Each.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="f6d3f7db9ed0898460e1e330ffb4e965" name="Rules/Equals.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="3374c2cf568efc7326468193878792bd" name="Rules/Float.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="cf8c4770ebb3021bd1737b677c7270c9" name="Rules/Hexa.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="0ed55a1ab9c8929c2dbe0cc8b35d2dab" name="Rules/In.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="e4fa200037c4bf6880bf0f5766218171" name="Rules/Instance.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="fbeec7c032013e067e72c9704ba8537f" name="Rules/Int.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="3a083becb83c264973b097207d6e4c7a" name="Rules/Ip.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="55731a422e14d5eecb69d450bb6ab296" name="Rules/Key.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ffd7f013f1305b52f6c389c7b6ccf3a9" name="Rules/Max.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="456846e08f55dac3582928baf8e2ede0" name="Rules/Min.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="9ab0c98ff2b5c373ab408f72a168bb0e" name="Rules/Key.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="45c2e39ae885b3f31e7c795bac227c33" name="Rules/Length.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="72e9a94595f32bf43ea19a53609f4d3a" name="Rules/Max.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="2b92961085bcea290ed15dab67e0064b" name="Rules/Min.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="1e7ba06c790b75a168a98e3972d38aa6" name="Rules/MostOf.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="ecf7ebf9af5c2c963dbde65efc5cfad2" name="Rules/Negative.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="4a301f41432c8f6c15074733082aff66" name="Rules/NoneOf.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="0aaf71cbd1de8bcd583e560fc80042f5" name="Rules/NotEmpty.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="a8a1d7a823cd22f3446b8db96f30f2fc" name="Rules/NoWhitespace.php" role="php" />
|
||||
|
@ -88,12 +101,13 @@ First Version
|
|||
<file baseinstalldir="Respect/Validation" md5sum="34ed73b15119f9fa8e54d61009fcf0a4" name="Rules/Numeric.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="8a6462204bffbb3eead42a1b92b7d17e" name="Rules/Object.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="1e26108f3e6bfde46239aa1726d4775b" name="Rules/OneOf.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="2b9e4d588eefda35f48b2360dcf5b36d" name="Rules/Positive.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d3f2e2142375c8e944a3abe9b2e22674" name="Rules/Regex.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="668cb6704593d7a9170b71d5715b609d" name="Rules/Sf.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="12ef308e6e9817bcf22479129c798136" name="Rules/StringLength.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d3cf890b95664760156f902207242250" name="Rules/String.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="d4b83a1935ed3deea7484f6acba38a2c" name="Rules/Zend.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="46726308b13c6de33004cf4f9e7ff510" name="Validatable.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="b91c9986abf731c3c7d217857e7f2511" name="Validator.php" role="php" />
|
||||
<file baseinstalldir="Respect/Validation" md5sum="2d08eae5e1809dda0b843ee4d8c37828" name="Validator.php" role="php" />
|
||||
</dir>
|
||||
</contents>
|
||||
<dependencies>
|
||||
|
@ -117,7 +131,7 @@ First Version
|
|||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2010-12-06</date>
|
||||
<date>2010-12-07</date>
|
||||
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
|
||||
<notes>
|
||||
First Version
|
||||
|
|
|
@ -16,7 +16,7 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidAlnum
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\AlnumException
|
||||
*/
|
||||
public function testAlnumInvalid($invalidAlnum, $aditional)
|
||||
{
|
||||
|
@ -52,6 +52,9 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
|
|||
array('foobar', ''),
|
||||
array('rubinho_', '_'),
|
||||
array('google.com', '.'),
|
||||
array('alganet alganet', ''),
|
||||
array("\n", ''),
|
||||
array("\t", ''),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -62,7 +65,6 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
|
|||
array('_', ''),
|
||||
array('', ''),
|
||||
array('dgç', ''),
|
||||
array('alganet alganet', ''),
|
||||
array(1e21, ''),
|
||||
array(0, ''),
|
||||
array(null, ''),
|
||||
|
|
|
@ -16,7 +16,7 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidAlpha
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\AlphaException
|
||||
*/
|
||||
public function testAlphaInvalid($invalidAlpha, $aditional)
|
||||
{
|
||||
|
@ -51,6 +51,9 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
|
|||
array('foobar', ''),
|
||||
array('rubinho_', '_'),
|
||||
array('google.com', '.'),
|
||||
array('alganet alganet', ''),
|
||||
array("\n", ''),
|
||||
array("\t", ''),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -64,7 +67,6 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
|
|||
array('122al', ''),
|
||||
array('122', ''),
|
||||
array(11123, ''),
|
||||
array('alganet alganet', ''),
|
||||
array(1e21, ''),
|
||||
array(0, ''),
|
||||
array(null, ''),
|
||||
|
|
|
@ -23,7 +23,7 @@ class ArrTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotArray
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\ArrException
|
||||
*/
|
||||
public function testNotArray($input)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ class AtLeastTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\AtLeastException
|
||||
*/
|
||||
public function testInvalid()
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\AttributeException
|
||||
*/
|
||||
public function testNotNull()
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testValidatorAttribute()
|
||||
{
|
||||
$subValidator = new StringLength(1, 3);
|
||||
$subValidator = new Length(1, 3);
|
||||
$validator = new Attribute('bar', $subValidator);
|
||||
$obj = new \stdClass;
|
||||
$obj->bar = 'foo';
|
||||
|
@ -60,7 +60,7 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testValidatorPrivateAttribute()
|
||||
{
|
||||
$subValidator = new StringLength(1, 3);
|
||||
$subValidator = new Length(1, 3);
|
||||
$validator = new Attribute('bar', $subValidator);
|
||||
$obj = new PrivClass;
|
||||
$this->assertTrue($validator->assert($obj));
|
||||
|
|
|
@ -11,15 +11,17 @@ class BetweenTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerValid()
|
||||
{
|
||||
return array(
|
||||
array(0, 1, 0),
|
||||
array(0, 1, 1),
|
||||
array(10, 20, 15),
|
||||
array(10, 20, 20),
|
||||
array(-10, 20, -5),
|
||||
array(-10, 20, 0),
|
||||
array(0, 1, true, 0),
|
||||
array(0, 1, true, 1),
|
||||
array(10, 20, false, 15),
|
||||
array(10, 20, true, 20),
|
||||
array(-10, 20, false, -5),
|
||||
array(-10, 20, false, 0),
|
||||
array('a', 'z', false, 'j'),
|
||||
array(
|
||||
new DateTime('yesterday'),
|
||||
new DateTime('tomorrow'),
|
||||
false,
|
||||
new DateTime('now')
|
||||
),
|
||||
);
|
||||
|
@ -28,31 +30,39 @@ class BetweenTest extends \PHPUnit_Framework_TestCase
|
|||
public function providerInvalid()
|
||||
{
|
||||
return array(
|
||||
array(0, 1, 2),
|
||||
array(0, 1, -1),
|
||||
array(10, 20, 999),
|
||||
array(-10, 20, -11),
|
||||
array(0, 1, false, 0),
|
||||
array(0, 1, false, 1),
|
||||
array(0, 1, false, 2),
|
||||
array(0, 1, false, -1),
|
||||
array(10, 20, false, 999),
|
||||
array(10, 20, false, 20),
|
||||
array(-10, 20, false, -11),
|
||||
array('a', 'j', false, 'z'),
|
||||
array(
|
||||
new DateTime('yesterday'),
|
||||
new DateTime('now'),
|
||||
false,
|
||||
new DateTime('tomorrow')
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerValid
|
||||
*/
|
||||
public function testBetweenBounds($min, $max, $input)
|
||||
public function testBetweenBounds($min, $max, $inclusive, $input)
|
||||
{
|
||||
$o = new Between($min, $max);
|
||||
$this->assertTrue($o->assert($input));
|
||||
$o = new Between($min, $max);
|
||||
$o = new Between($min, $max, $inclusive);
|
||||
$this->assertTrue($o->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerInvalid
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\BetweenException
|
||||
*/
|
||||
public function testNotBetweenBounds($min, $max, $input)
|
||||
public function testNotBetweenBounds($min, $max, $inclusive, $input)
|
||||
{
|
||||
$o = new Between($min, $max);
|
||||
$o = new Between($min, $max, $inclusive);
|
||||
$this->assertTrue($o->assert($input));
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,33 @@ namespace Respect\Validation\Rules;
|
|||
class CallTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function callbackThis()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testCallbackOk()
|
||||
{
|
||||
$v = new Call('str_split', new Arr);
|
||||
$this->assertTrue($v->assert('test'));
|
||||
}
|
||||
|
||||
public function testCallbackObject()
|
||||
{
|
||||
$v = new Call(array($this, 'callbackThis'), new Arr);
|
||||
$this->assertTrue($v->assert('test'));
|
||||
}
|
||||
|
||||
public function testCallbackClosure()
|
||||
{
|
||||
$v = new Call(function() {
|
||||
return array();
|
||||
}, new Arr);
|
||||
$this->assertTrue($v->assert('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\CallException
|
||||
*/
|
||||
public function testCallbackNot()
|
||||
{
|
||||
|
|
|
@ -5,6 +5,11 @@ namespace Respect\Validation\Rules;
|
|||
class CallbackTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function callbackThis()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function testCallbackOk()
|
||||
{
|
||||
$v = new Callback(function() {
|
||||
|
@ -14,7 +19,7 @@ class CallbackTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\CallbackException
|
||||
*/
|
||||
public function testCallbackNot()
|
||||
{
|
||||
|
@ -24,6 +29,18 @@ class CallbackTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($v->assert('w poiur'));
|
||||
}
|
||||
|
||||
public function testCallbackObject()
|
||||
{
|
||||
$v = new Callback(array($this, 'callbackThis'));
|
||||
$this->assertTrue($v->assert('test'));
|
||||
}
|
||||
|
||||
public function testCallbackString()
|
||||
{
|
||||
$v = new Callback('is_string');
|
||||
$this->assertTrue($v->assert('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ComponentException
|
||||
*/
|
||||
|
|
|
@ -34,17 +34,14 @@ class DateTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertFalse($this->object->validate('aids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
*/
|
||||
public function testDateFormat()
|
||||
{
|
||||
$this->object = new Date('Y-m-');
|
||||
$this->object = new Date('Y-m-d');
|
||||
$this->assertTrue($this->object->assert('2009-09-09'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\DateException
|
||||
*/
|
||||
public function testInvalidDateFormat()
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ class DigitsTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotDigits
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\DigitsException
|
||||
*/
|
||||
public function testNotDigits($input)
|
||||
{
|
||||
|
@ -35,6 +35,7 @@ class DigitsTest extends \PHPUnit_Framework_TestCase
|
|||
return array(
|
||||
array(165),
|
||||
array(1650),
|
||||
array('01650'),
|
||||
array('165'),
|
||||
array('1650'),
|
||||
);
|
||||
|
|
|
@ -28,6 +28,7 @@ class EachTest extends \PHPUnit_Framework_TestCase
|
|||
$result = $v->assert(array('', 2, 3, 4, 5));
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\EachException
|
||||
*/
|
||||
|
|
|
@ -23,7 +23,7 @@ class FloatTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotFloat
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\FloatException
|
||||
*/
|
||||
public function testNotFloat($input)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ class HexaTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotHexa
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\HexaException
|
||||
*/
|
||||
public function testNotHexa($input)
|
||||
{
|
||||
|
@ -36,6 +36,8 @@ class HexaTest extends \PHPUnit_Framework_TestCase
|
|||
array('FFF'),
|
||||
array('15'),
|
||||
array('DE12FA'),
|
||||
array('1234567890abcdef'),
|
||||
array(0x123),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -47,6 +49,7 @@ class HexaTest extends \PHPUnit_Framework_TestCase
|
|||
array(' '),
|
||||
array('Foo'),
|
||||
array(''),
|
||||
array('1.5'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
51
tests/library/Respect/Validation/Rules/InTest.php
Normal file
51
tests/library/Respect/Validation/Rules/InTest.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class InTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @dataProvider providerForIn
|
||||
*
|
||||
*/
|
||||
public function testIn($input, $options=null)
|
||||
{
|
||||
$v = new In($options);
|
||||
$this->assertTrue($v->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNotIn
|
||||
* @expectedException Respect\Validation\Exceptions\InException
|
||||
*/
|
||||
public function testNotIn($input, $options, $strict=false)
|
||||
{
|
||||
$v = new In($options, $strict);
|
||||
$this->assertFalse($v->assert($input));
|
||||
}
|
||||
|
||||
public function providerForIn()
|
||||
{
|
||||
return array(
|
||||
array('foo', array('foo', 'bar')),
|
||||
array('foo', 'barfoobaz'),
|
||||
array('foo', 'foobarbaz'),
|
||||
array('foo', 'barbazfoo'),
|
||||
array('1', array(1, 2, 3)),
|
||||
array('1', array('1', 2, 3), true),
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForNotIn()
|
||||
{
|
||||
return array(
|
||||
array('bat', array('foo', 'bar')),
|
||||
array('foo', 'barfaabaz'),
|
||||
array('foo', 'faabarbaz'),
|
||||
array('foo', 'baabazfaa'),
|
||||
array('1', array(1, 2, 3), true),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ class InstanceTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\InstanceException
|
||||
*/
|
||||
public function testNotInstance()
|
||||
{
|
||||
|
|
56
tests/library/Respect/Validation/Rules/IntTest.php
Normal file
56
tests/library/Respect/Validation/Rules/IntTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class IntTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $object;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Int;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForInt
|
||||
*
|
||||
*/
|
||||
public function testInt($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNotInt
|
||||
* @expectedException Respect\Validation\Exceptions\IntException
|
||||
*/
|
||||
public function testNotInt($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
public function providerForInt()
|
||||
{
|
||||
return array(
|
||||
array(16),
|
||||
array('165'),
|
||||
array(123456),
|
||||
array(1e10),
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForNotInt()
|
||||
{
|
||||
return array(
|
||||
array(null),
|
||||
array('a'),
|
||||
array(' '),
|
||||
array('Foo'),
|
||||
array(''),
|
||||
array('1.44'),
|
||||
array(1e-5),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -24,7 +24,7 @@ class IpTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotIp
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\IpException
|
||||
*/
|
||||
public function testNotIp($input, $options=null)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ class KeyTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\KeyException
|
||||
*/
|
||||
public function testNotNull()
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ class KeyTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testValidatorAttribute()
|
||||
{
|
||||
$subValidator = new StringLength(1, 3);
|
||||
$subValidator = new Length(1, 3);
|
||||
$validator = new Key('bar', $subValidator);
|
||||
$obj = array();
|
||||
$obj['bar'] = 'foo';
|
||||
|
|
|
@ -2,35 +2,35 @@
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class StringLengthTest extends \PHPUnit_Framework_TestCase
|
||||
class LengthTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @dataProvider providerForValidLenght
|
||||
*/
|
||||
public function testStringLengthValid($string, $min, $max)
|
||||
public function testLengthValid($string, $min, $max)
|
||||
{
|
||||
$validator = new StringLength($min, $max);
|
||||
$validator = new Length($min, $max);
|
||||
$this->assertTrue($validator->assert($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForInvalidLenght
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\LengthException
|
||||
*/
|
||||
public function testStringLengthInvalid($string, $min, $max)
|
||||
public function testLengthInvalid($string, $min, $max)
|
||||
{
|
||||
$validator = new StringLength($min, $max);
|
||||
$validator = new Length($min, $max);
|
||||
$this->assertFalse($validator->assert($string));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider providerForComponentException
|
||||
* @expectedException Respect\Validation\Exceptions\ComponentException
|
||||
*/
|
||||
public function testStringLengthComponentException($string,$min,$max)
|
||||
public function testLengthComponentException($string, $min, $max)
|
||||
{
|
||||
$validator = new StringLength($min, $max);
|
||||
$validator = new Length($min, $max);
|
||||
$this->assertFalse($validator->assert($string));
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,9 @@ class StringLengthTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return array(
|
||||
array('alganet', 1, 15),
|
||||
array('alganet',1,null), //null is a valid max length, means "no maximum",
|
||||
array('alganet',null,15) //null is a valid min length, means "no minimum"
|
||||
array(range(1, 20), 1, 30),
|
||||
array('alganet', 1, null), //null is a valid max length, means "no maximum",
|
||||
array('alganet', null, 15) //null is a valid min length, means "no minimum"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -47,14 +48,15 @@ class StringLengthTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return array(
|
||||
array('alganet', 1, 3),
|
||||
array(range(1, 50), 1, 30),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function providerForComponentException()
|
||||
{
|
||||
return array(
|
||||
array('alganet','a',15),
|
||||
array('alganet',1,'abc d'),
|
||||
array('alganet', 'a', 15),
|
||||
array('alganet', 1, 'abc d'),
|
||||
);
|
||||
}
|
||||
|
|
@ -9,38 +9,39 @@ class MaxTest extends \PHPUnit_Framework_TestCase
|
|||
* @dataProvider providerForValidMax
|
||||
*
|
||||
*/
|
||||
public function testMax($maxValue, $input)
|
||||
public function testMax($maxValue, $inclusive, $input)
|
||||
{
|
||||
$max = new Max($maxValue);
|
||||
$max = new Max($maxValue, $inclusive);
|
||||
$this->assertTrue($max->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForInvalidMax
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\MaxException
|
||||
*/
|
||||
public function testNotMax($maxValue, $input)
|
||||
public function testNotMax($maxValue, $inclusive, $input)
|
||||
{
|
||||
$max = new Max($maxValue);
|
||||
$max = new Max($maxValue, $inclusive);
|
||||
$this->assertTrue($max->assert($input));
|
||||
}
|
||||
|
||||
public function providerForValidMax()
|
||||
{
|
||||
return array(
|
||||
array(200, 165.0),
|
||||
array(200, -200),
|
||||
array(200, 200),
|
||||
array(200, 0),
|
||||
array(200, false, 165.0),
|
||||
array(200, false, -200),
|
||||
array(200, true, 200),
|
||||
array(200, false, 0),
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForInvalidMax()
|
||||
{
|
||||
return array(
|
||||
array(200, 300),
|
||||
array(200, 250),
|
||||
array(200, 1500),
|
||||
array(200, false, 300),
|
||||
array(200, false, 250),
|
||||
array(200, false, 1500),
|
||||
array(200, false, 200),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,38 +9,39 @@ class MinTest extends \PHPUnit_Framework_TestCase
|
|||
* @dataProvider providerForValidMin
|
||||
*
|
||||
*/
|
||||
public function testMin($minValue, $input)
|
||||
public function testMin($minValue, $inclusive, $input)
|
||||
{
|
||||
$min = new Min($minValue);
|
||||
$min = new Min($minValue, $inclusive);
|
||||
$this->assertTrue($min->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForInvalidMin
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\MinException
|
||||
*/
|
||||
public function testNotMin($minValue, $input)
|
||||
public function testNotMin($minValue, $inclusive, $input)
|
||||
{
|
||||
$min = new Min($minValue);
|
||||
$min = new Min($minValue, $inclusive);
|
||||
$this->assertTrue($min->assert($input));
|
||||
}
|
||||
|
||||
public function providerForValidMin()
|
||||
{
|
||||
return array(
|
||||
array(100, 165.0),
|
||||
array(-100, 200),
|
||||
array(200, 200),
|
||||
array(200, 300),
|
||||
array(100, false, 165.0),
|
||||
array(-100, false, 200),
|
||||
array(200, true, 200),
|
||||
array(200, false, 300),
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForInvalidMin()
|
||||
{
|
||||
return array(
|
||||
array(500, 300),
|
||||
array(0, -250),
|
||||
array(0, -50),
|
||||
array(500, false, 300),
|
||||
array(0, false, -250),
|
||||
array(0, false, -50),
|
||||
array(50, false, 50),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class MostOfTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\MostOfException
|
||||
*/
|
||||
public function testInvalid()
|
||||
{
|
||||
|
|
59
tests/library/Respect/Validation/Rules/NegativeTest.php
Normal file
59
tests/library/Respect/Validation/Rules/NegativeTest.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class NegativeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $object;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Negative;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNegative
|
||||
*
|
||||
*/
|
||||
public function testNegative($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNotNegative
|
||||
* @expectedException Respect\Validation\Exceptions\NegativeException
|
||||
*/
|
||||
public function testNotNegative($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
public function providerForNegative()
|
||||
{
|
||||
return array(
|
||||
array('-1.44'),
|
||||
array(-1e-5),
|
||||
array(-10),
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForNotNegative()
|
||||
{
|
||||
return array(
|
||||
array(0),
|
||||
array(-0),
|
||||
array(null),
|
||||
array('a'),
|
||||
array(' '),
|
||||
array('Foo'),
|
||||
array(''),
|
||||
array(16),
|
||||
array('165'),
|
||||
array(123456),
|
||||
array(1e10),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ class NoWhitespaceTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\NoWhitespaceException
|
||||
*/
|
||||
public function testWhitespace()
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ class NoneOfTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\NoneOfException
|
||||
*/
|
||||
public function testInvalid()
|
||||
{
|
||||
|
|
|
@ -12,17 +12,44 @@ class NotEmptyTest extends \PHPUnit_Framework_TestCase
|
|||
$this->object = new NotEmpty;
|
||||
}
|
||||
|
||||
public function testStringNotEmpty()
|
||||
/**
|
||||
* @dataProvider providerForNotEmpty
|
||||
*/
|
||||
public function testStringNotEmpty($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert('xsdfgf'));
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @dataProvider providerForEmpty
|
||||
* @expectedException Respect\Validation\Exceptions\NotEmptyException
|
||||
*/
|
||||
public function testStringEmpty()
|
||||
public function testStringEmpty($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert(' '));
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
public function providerForNotEmpty()
|
||||
{
|
||||
return array(
|
||||
array(1),
|
||||
array(' oi'),
|
||||
array(array(5)),
|
||||
array(array(0)),
|
||||
array(new \stdClass)
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForEmpty()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(' '),
|
||||
array("\n"),
|
||||
array(false),
|
||||
array(null),
|
||||
array(array())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ class NullValueTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\NullValueException
|
||||
*/
|
||||
public function testNotNull()
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ class NumericTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotNumeric
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\NumericException
|
||||
*/
|
||||
public function testNotNumeric($input)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotObject
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\ObjectException
|
||||
*/
|
||||
public function testNotObject($input)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ class OneOfTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\OneOfException
|
||||
*/
|
||||
public function testInvalid()
|
||||
{
|
||||
|
|
59
tests/library/Respect/Validation/Rules/PositiveTest.php
Normal file
59
tests/library/Respect/Validation/Rules/PositiveTest.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class PositiveTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $object;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Positive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForPositive
|
||||
*
|
||||
*/
|
||||
public function testPositive($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNotPositive
|
||||
* @expectedException Respect\Validation\Exceptions\PositiveException
|
||||
*/
|
||||
public function testNotPositive($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
public function providerForPositive()
|
||||
{
|
||||
return array(
|
||||
array(16),
|
||||
array('165'),
|
||||
array(123456),
|
||||
array(1e10),
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForNotPositive()
|
||||
{
|
||||
return array(
|
||||
array(null),
|
||||
array('a'),
|
||||
array(' '),
|
||||
array('Foo'),
|
||||
array(''),
|
||||
array('-1.44'),
|
||||
array(-1e-5),
|
||||
array(0),
|
||||
array(-0),
|
||||
array(-10),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ class RegexTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\RegexException
|
||||
*/
|
||||
public function testRegexNot()
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ class SfTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\SfException
|
||||
*/
|
||||
public function testParamsNot()
|
||||
{
|
||||
|
|
51
tests/library/Respect/Validation/Rules/StringTest.php
Normal file
51
tests/library/Respect/Validation/Rules/StringTest.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class StringTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $object;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new String;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForString
|
||||
*
|
||||
*/
|
||||
public function testString($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNotString
|
||||
* @expectedException Respect\Validation\Exceptions\StringException
|
||||
*/
|
||||
public function testNotString($input)
|
||||
{
|
||||
$this->assertTrue($this->object->assert($input));
|
||||
}
|
||||
|
||||
public function providerForString()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('165.7'),
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForNotString()
|
||||
{
|
||||
return array(
|
||||
array(null),
|
||||
array(array()),
|
||||
array(new \stdClass),
|
||||
array(150)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,58 +5,162 @@ namespace Respect\Validation;
|
|||
class ValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testValidateSimple()
|
||||
public function testAlnum()
|
||||
{
|
||||
$v = Validator::notEmpty()->validate('foo');
|
||||
$this->assertTrue($v);
|
||||
Validator::alnum()->assert('abc 123');
|
||||
Validator::alnum('_')->assert('a_bc _123');
|
||||
}
|
||||
|
||||
public function testValidateArguments()
|
||||
public function testAlpha()
|
||||
{
|
||||
$v = Validator::between(10, 20)->validate(15);
|
||||
$this->assertTrue($v);
|
||||
Validator::alpha()->assert('ab c');
|
||||
Validator::alpha('.')->assert('a. b.c');
|
||||
}
|
||||
|
||||
public function testValidateFluent()
|
||||
public function testArr()
|
||||
{
|
||||
$v = Validator::between(10, 20)->validate(15);
|
||||
$this->assertTrue($v);
|
||||
Validator::arr()->assert(array());
|
||||
}
|
||||
|
||||
public function testValidateFluentChain()
|
||||
public function testBetween()
|
||||
{
|
||||
$v = Validator::between(10, 20)->notEmpty()
|
||||
->assert(15);
|
||||
$this->assertTrue($v);
|
||||
Validator::between(5, 15)->assert(10);
|
||||
Validator::between('a', 'f')->assert('b');
|
||||
}
|
||||
|
||||
public function testValidatorComposite()
|
||||
public function testDate()
|
||||
{
|
||||
Validator::date('Y-m-d')->assert('2010-10-10');
|
||||
Validator::date()->assert('Jan 10 2008');
|
||||
}
|
||||
|
||||
public function testDigits()
|
||||
{
|
||||
Validator::digits()->assert('02384');
|
||||
}
|
||||
|
||||
public function testEquals()
|
||||
{
|
||||
Validator::equals('foobar')->assert('foobar');
|
||||
}
|
||||
|
||||
public function testFloat()
|
||||
{
|
||||
Validator::float()->assert(1.5);
|
||||
}
|
||||
|
||||
public function testHexa()
|
||||
{
|
||||
Validator::hexa()->assert('FAFAF');
|
||||
}
|
||||
|
||||
public function testIn()
|
||||
{
|
||||
Validator::in(array(1, 1, 2, 3, 5, 8))->assert(5);
|
||||
}
|
||||
|
||||
public function testInstance()
|
||||
{
|
||||
Validator::instance('\stdClass')->assert(new \stdClass);
|
||||
}
|
||||
|
||||
public function testInt()
|
||||
{
|
||||
Validator::int()->assert(1548);
|
||||
}
|
||||
|
||||
public function testIp()
|
||||
{
|
||||
Validator::ip()->assert('200.226.220.222');
|
||||
}
|
||||
|
||||
public function testLength()
|
||||
{
|
||||
Validator::length(5, 10)->assert('foobar');
|
||||
Validator::length(5, 10)->assert(array(1, 2, 3, 4, 5));
|
||||
}
|
||||
|
||||
public function testMax()
|
||||
{
|
||||
Validator::max(5)->assert(3);
|
||||
}
|
||||
|
||||
public function testMin()
|
||||
{
|
||||
Validator::min(5)->assert(7);
|
||||
}
|
||||
|
||||
public function testNegative()
|
||||
{
|
||||
Validator::negative()->assert(-5);
|
||||
}
|
||||
|
||||
public function testPositive()
|
||||
{
|
||||
Validator::positive()->assert(3);
|
||||
}
|
||||
|
||||
public function testNoWhitespace()
|
||||
{
|
||||
Validator::noWhitespace()->assert('abc');
|
||||
}
|
||||
|
||||
public function testNotEmpty()
|
||||
{
|
||||
Validator::notEmpty()->assert('aaa');
|
||||
}
|
||||
|
||||
public function testNullValue()
|
||||
{
|
||||
Validator::nullValue()->assert(null);
|
||||
}
|
||||
|
||||
public function testNumeric()
|
||||
{
|
||||
Validator::numeric()->assert(1.56e-5);
|
||||
}
|
||||
|
||||
public function testObject()
|
||||
{
|
||||
Validator::object()->assert(new \DateTime());
|
||||
}
|
||||
|
||||
public function testRegex()
|
||||
{
|
||||
Validator::regex('[a-f]+')->assert('abcdef');
|
||||
}
|
||||
|
||||
public function testString()
|
||||
{
|
||||
Validator::string()->assert('Hello World');
|
||||
}
|
||||
|
||||
public function testAllOf()
|
||||
{
|
||||
Validator::allOf(
|
||||
Validator::string(), //any string
|
||||
Validator::length(5, 20), //between 5 and 20 chars
|
||||
Validator::noWhitespace() //no whitespace allowed
|
||||
)->assert('alganet');
|
||||
|
||||
//same as
|
||||
|
||||
Validator::string()
|
||||
->length(5, 20)
|
||||
->noWhitespace()
|
||||
->assert('alganet');
|
||||
}
|
||||
|
||||
public function testOneOf()
|
||||
{
|
||||
$v = Validator::oneOf(
|
||||
Validator::notEmpty(), Validator::between(10, 20)
|
||||
)->validate(15);
|
||||
$this->assertTrue($v);
|
||||
}
|
||||
|
||||
public function testValidatorCompositeTwitterUsername()
|
||||
{
|
||||
$v = Validator::alnum('_')
|
||||
->noWhitespace()
|
||||
->stringLength(1, 15)
|
||||
->assert('alganet');
|
||||
$this->assertTrue($v);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
*/
|
||||
public function testValidatorCompositeTwitterUsernameInvalid()
|
||||
{
|
||||
$v = Validator::alnum('_')
|
||||
->noWhitespace()
|
||||
->stringLength(1, 15)
|
||||
->assert('#$% #odjfubgihdbfgihbdfighb');
|
||||
$this->assertTrue($v);
|
||||
Validator::int()->positive(), //positive integer or;
|
||||
Validator::float()->negative(), //negative float or;
|
||||
Validator::nullValue() //null
|
||||
);
|
||||
$v->assert(null);
|
||||
$v->assert(12);
|
||||
$v->assert(-12.5);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue