- Splitted up ValidationException into simple exceptions and composite exceptions

- Changed the string formater from sprintf to custom function. Exception parameters should be more readable now.
	- Several refactorings on the exception reporting model
	- Improved builders ( new v(array('int', 'positive', 'between'=>array(1,256))); is now possible, great for dependency injection.
	Note: There are nasty things on this commit. Duplicated code, orphan methods and such. Next step is a nice quality-wide refactoring.
This commit is contained in:
Alexandre 2011-02-10 18:49:48 -02:00
parent bf5ed1e64d
commit 895ce93ed1
77 changed files with 584 additions and 624 deletions

View file

@ -19,6 +19,7 @@ class ExceptionIterator extends RecursiveArrayIterator
public function hasChildren()
{
if (!$this->current() instanceof AbstractCompositeException) return false;
return (bool) $this->current()->getRelated($this->fullRelated);
}
@ -27,4 +28,4 @@ class ExceptionIterator extends RecursiveArrayIterator
return new static($this->current()->getRelated($this->fullRelated), $this->fullRelated);
}
}
}

View file

@ -1,21 +1,68 @@
<?php
namespace Respect\Validation\Exceptions;
use RecursiveIteratorIterator;
use RecursiveTreeIterator;
use Respect\Validation\ExceptionIterator;
class AbstractCompositeException extends AbstractRelatedException
class AbstractCompositeException extends ValidationException
{
const NONE = 0;
const SOME = 1;
protected $related = array();
public static $defaultTemplates = array(
self::NONE => 'All of the %3$d required rules must pass for %1$s',
self::SOME => 'These %2$d rules must pass for %1$s',
self::NONE => 'All of the required rules must pass for {{name}}',
self::SOME => 'These rules must pass for {{name}}',
);
public function chooseTemplate($name, $numFailed, $numRequired, $numTotal)
public function chooseTemplate()
{
return $numFailed === $numTotal ? static::NONE : static::SOME;
$numRules = $this->getParam('passed');
$numFailed = count($this->getRelated());
return $numRules === $numFailed ? static::NONE : static::SOME;
}
public function setContext($context)
{
parent::setContext($context);
foreach ($this->related as $r)
$r->setContext($context);
}
public function getIterator($full=false, $mode=self::ITERATE_ALL)
{
$exceptionIterator = new ExceptionIterator($this, $full);
if ($mode == self::ITERATE_ALL)
return new RecursiveIteratorIterator($exceptionIterator, 1);
else
return new RecursiveTreeIterator($exceptionIterator);
}
public function findRelated()
{
$target = $this;
$path = func_get_args();
while (!empty($path) && $target !== false)
$target = $this->getRelatedByName(array_shift($path));
return $target;
}
public function getRelatedByName($name)
{
foreach ($this->getIterator(true) as $e)
if ($e->getId() === $name)
return $e;
return false;
}
public function addRelated(ValidationException $related)
{
$this->related[] = $related;
return $this;
}
public function getMainMessage()
{
if (1 === count($this->related))
@ -25,13 +72,22 @@ class AbstractCompositeException extends AbstractRelatedException
else
return parent::getMainMessage();
}
public function setRelated(array $relatedExceptions)
{
foreach ($relatedExceptions as $related)
$this->addRelated($related);
return $this;
}
public function getRelated($full=false)
{
if (!$full && 1 === count($this->related))
return $this->related[0]->getRelated(false);
if ($this->related[0] instanceof AbstractCompositeException)
return $this->related[0]->getRelated(false);
else
return array();
else
return parent::getRelated($full);
return $this->related;
}
}
}

View file

@ -2,15 +2,23 @@
namespace Respect\Validation\Exceptions;
abstract class AbstractRelatedException extends ValidationException
class AbstractRelatedException extends AbstractCompositeException
{
public function getMainMessage()
{
$vars = $this->getParams();
$vars['name'] = $this->getName();
return static::format($this->getTemplate(), $vars);
}
public function getRelated($full=false)
{
if (!$full && 1 === count($this->related))
return $this->related[0]->getRelated(true);
else
return parent::getRelated($full);
return $this->related;
}
public function chooseTemplate()
{
return 0;
}
}
}

View file

@ -6,8 +6,8 @@ class AllOfException extends AbstractCompositeException
{
public static $defaultTemplates = array(
self::NONE => 'All of the %3$d required rules must pass for %1$s',
self::SOME => 'These %2$d rules must pass for %1$s',
self::NONE => 'All of the {{failed}} required rules must pass for {{name}}',
self::SOME => 'These {{failed}} rules must pass for {{name}}',
);
}
}

View file

@ -6,8 +6,8 @@ class AlnumException extends AlphaException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must contain only letters (a-z) and digits (0-9)',
self::EXTRA => '%s must contain only letters (a-z), digits (0-9) and "%s"'
self::STANDARD => '{{name}} must contain only letters (a-z) and digits (0-9)',
self::EXTRA => '{{name}} must contain only letters (a-z), digits (0-9) and "{{additionalChars}}"'
);
}
}

View file

@ -7,13 +7,13 @@ class AlphaException extends ValidationException
const EXTRA = 1;
public static $defaultTemplates = array(
self::STANDARD => '%s must contain only letters (a-z)',
self::EXTRA => '%s must contain only letters (a-z) and "%s"'
self::STANDARD => '{{name}} must contain only letters (a-z)',
self::EXTRA => '{{name}} must contain only letters (a-z) and "{{additionalChars}}"'
);
public function chooseTemplate($name, $additionalCharacters=null)
public function chooseTemplate()
{
return empty($additionalCharacters) ? static::STANDARD : static::EXTRA;
return $this->getParam('additionalChars') ? static::STANDARD : static::EXTRA;
}
}
}

View file

@ -6,7 +6,7 @@ class ArrException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be an array',
self::STANDARD => '{{name}} must be an array',
);
}
}

View file

@ -6,8 +6,8 @@ class AtLeastException extends AbstractCompositeException
{
public static $defaultTemplates = array(
self::NONE => 'At least %3$d of %4$d rules must pass for %1$s',
self::SOME => 'At least %3$d of %4$d rules must pass for %1$s, only %2$d passed',
self::NONE => 'At least {{howMany}} of the {{failed}} required rules must pass for {{name}}',
self::SOME => 'At least {{howMany}} of the {{failed}} required rules must pass for {{name}}, only {{passed}} passed.',
);
}
}

View file

@ -2,18 +2,18 @@
namespace Respect\Validation\Exceptions;
class AttributeException extends AbstractRelatedException
class AttributeException extends AbstractCompositeException
{
const NOT_PRESENT = 0;
const INVALID = 1;
public static $defaultTemplates = array(
self::NOT_PRESENT => '%1$s must be present',
self::INVALID => 'Attribute %2$s must be valid on %1$s',
self::NOT_PRESENT => 'Attribute {{reference}} must be present on {{name}}',
self::INVALID => 'Attribute {{reference}} must be valid on {{name}}',
);
public function chooseTemplate($name, $attributeName, $hasTheAttribute)
public function chooseTemplate()
{
return $hasTheAttribute ? static::INVALID : static::NOT_PRESENT;
return $this->getParam('hasReference') ? static::INVALID : static::NOT_PRESENT;
}
}
}

View file

@ -2,34 +2,33 @@
namespace Respect\Validation\Exceptions;
class BetweenException extends ValidationException
class BetweenException extends AbstractCompositeException
{
const BOTH = 0;
const LOWER = 1;
const GREATER = 2;
public static $defaultTemplates = array(
self::BOTH => '%s must be between %s and %s',
self::LOWER => '%s must be greater than %2$s',
self::GREATER => '%s must be lower than %3$s',
self::BOTH => '{{name}} must be between {{minValue}} and {{maxValue}}',
self::LOWER => '{{name}} must be greater than {{minValue}}',
self::GREATER => '{{name}} must be lower than {{maxValue}}',
);
public function configure($name, $min, $max)
public function configure($name, array $params=array())
{
return parent::configure(
$name, ValidationException::stringify($min), //TODO find a better way
ValidationException::stringify($max)
);
$params['minValue'] = static::stringify($params['minValue']);
$params['maxValue'] = static::stringify($params['maxValue']);
return parent::configure($name, $params);
}
public function chooseTemplate($name, $min, $max)
public function chooseTemplate()
{
if (is_null($min))
if (!$this->getParam('minValue'))
return static::GREATER;
elseif (is_null($max))
elseif (!$this->getParam('maxValue'))
return static::LOWER;
else
return static::BOTH;
}
}
}

View file

@ -4,6 +4,5 @@ namespace Respect\Validation\Exceptions;
class CallException extends AbstractCompositeException
{
}

View file

@ -2,11 +2,11 @@
namespace Respect\Validation\Exceptions;
class CallbackException extends ValidationException
class CallbackException extends AbstractRelatedException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be valid',
self::STANDARD => '{{name}} must be valid',
);
}
}

View file

@ -7,14 +7,20 @@ class DateException extends ValidationException
const FORMAT = 1;
public static $defaultTemplates = array(
self::STANDARD => '%s must be a valid date',
//TODO reformat to reflect number of digits, so Y-m-d becomes YYYY-mm-dd
self::FORMAT => '%s must be a valid date in the format %s'
self::STANDARD => '{{name}} must be a valid date',
self::FORMAT => '{{name}} must be a valid date. Sample format: {{format}}'
);
public function chooseTemplate($name, $format)
public function configure($name, array $params=array())
{
return empty($format) ? static::STANDARD : static::FORMAT;
$params['format'] = date($params['format'],
strtotime('2005-12-30 01:02:03'));
return parent::configure($name, $params);
}
}
public function chooseTemplate()
{
return $this->getParam('format') ? static::FORMAT : static::STANDARD;
}
}

View file

@ -2,11 +2,12 @@
namespace Respect\Validation\Exceptions;
class DigitsException extends ValidationException
class DigitsException extends AlphaException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must contain only digits (0-9)',
self::STANDARD => '{{name}} must contain only digits (0-9)',
self::EXTRA => '{{name}} must contain only digits (0-9) and "{{additionalChars}}"'
);
}
}

View file

@ -2,11 +2,11 @@
namespace Respect\Validation\Exceptions;
class EachException extends ValidationException
class EachException extends AbstractRelatedException
{
public static $defaultTemplates = array(
self::STANDARD => 'Each item in %s must be valid',
self::STANDARD => 'Each item in {{name}} must be valid',
);
}
}

View file

@ -8,13 +8,13 @@ class EqualsException extends ValidationException
const IDENTICAL = 0;
public static $defaultTemplates = array(
self::EQUALS => '%s must be equals %s',
self::IDENTICAL => '%s must be identical as %s',
self::EQUALS => '{{name}} must be equals {{compareTo}}',
self::IDENTICAL => '{{name}} must be identical as {{compareTo}}',
);
public function chooseTemplate($name, $equals, $identical)
public function chooseTemplate()
{
return ($identical) ? static::IDENTICAL : static::EQUALS;
return $this->getParam('identical') ? static::IDENTICAL : static::EQUALS;
}
}
}

View file

@ -6,7 +6,7 @@ class FloatException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be a float number',
self::STANDARD => '{{name}} must be a float number',
);
}
}

View file

@ -6,7 +6,7 @@ class HexaException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be a hexadecimal number',
self::STANDARD => '{{name}} must be a hexadecimal number',
);
}
}

View file

@ -6,7 +6,7 @@ class InException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be in (%s)',
self::STANDARD => '{{name}} must be in ({{haystack}})',
);
}
}

View file

@ -6,7 +6,7 @@ class InstanceException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be an instance of %s',
self::STANDARD => '{{name}} must be an instance of {{instanceName}}',
);
}
}

View file

@ -6,7 +6,7 @@ class IntException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be an integer number',
self::STANDARD => '{{name}} must be an integer number',
);
}
}

View file

@ -6,7 +6,7 @@ class IpException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be an IP address',
self::STANDARD => '{{name}} must be an IP address',
);
}
}

View file

@ -4,9 +4,10 @@ namespace Respect\Validation\Exceptions;
class KeyException extends AttributeException
{
public static $defaultTemplates = array(
self::NOT_PRESENT => '%1$s must be present',
self::INVALID => 'Key %2$s must be valid on %1$s',
self::NOT_PRESENT => 'Key {{reference}} must be present on {{name}}',
self::INVALID => 'Key {{reference}} must be valid on {{name}}',
);
}
}

View file

@ -6,9 +6,9 @@ class LengthException extends BetweenException
{
public static $defaultTemplates = array(
self::BOTH => '%s must have a length between %d and %d',
self::LOWER => '%s must have a length greater than %2$d',
self::GREATER => '%s must have a length lower than %3$d',
self::BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}',
self::LOWER => '{{name}} must have a length greater than {{minValue}}',
self::GREATER => '{{name}} must have a length lower than {{maxValue}}',
);
}
}

View file

@ -7,19 +7,13 @@ class MaxException extends ValidationException
const INCLUSIVE = 1;
public static $defaultTemplates = array(
self::STANDARD => '%s must be lower than %s',
self::INCLUSIVE => '%s must be lower than %s (inclusive)',
self::STANDARD => '{{name}} must be lower than {{maxValue}}',
self::INCLUSIVE => '{{name}} must be lower than or equals {{maxValue}}',
);
public function cnofigure($name, $max, $inclusive)
public function chooseTemplate()
{
return parent::configure($name, ValidationException::stringify($max),
$inclusive);//TODO find a better way
return $this->getParam('inclusive') ? static::INCLUSIVE : static::STANDARD;
}
public function chooseTemplate($name, $max, $inclusive)
{
return $inclusive ? static::INCLUSIVE : static::STANDARD;
}
}
}

View file

@ -5,20 +5,15 @@ namespace Respect\Validation\Exceptions;
class MinException extends ValidationException
{
const INCLUSIVE = 1;
public static $defaultTemplates = array(
self::STANDARD => '%s must be greater than %s',
self::INCLUSIVE => '%s must be greater than %s (inclusive)',
self::STANDARD => '{{name}} must be greater than {{minValue}}',
self::INCLUSIVE => '{{name}} must be greater than or equals {{minValue}}',
);
public function cnofigure($name, $min, $inclusive)
public function chooseTemplate()
{
return parent::configure($name, ValidationException::stringify($min),
$inclusive);//TODO find a better way
return $this->getParam('inclusive') ? static::INCLUSIVE : static::STANDARD;
}
public function chooseTemplate($name, $min, $inclusive)
{
return $inclusive ? static::INCLUSIVE : static::STANDARD;
}
}
}

View file

@ -2,12 +2,7 @@
namespace Respect\Validation\Exceptions;
class MostOfException extends AbstractCompositeException
class MostOfException extends AtLeastException
{
public static $defaultTemplates = array(
self::NONE => 'At least %3$d of %4$d rules must pass for %1$s',
self::SOME => 'At least %3$d of %4$d rules must pass, only %2$d passed for %1$s',
);
}
}

View file

@ -6,7 +6,7 @@ class NegativeException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be negative',
self::STANDARD => '{{name}} must be negative',
);
}
}

View file

@ -6,7 +6,7 @@ class NoWhitespaceException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must not contain whitespace',
self::STANDARD => '{{name}} must not contain whitespace',
);
}
}

View file

@ -2,11 +2,15 @@
namespace Respect\Validation\Exceptions;
class NoneOfException extends ValidationException
class NoneOfException extends AbstractCompositeException
{
public static $defaultTemplates = array(
self::STANDARD => 'None of these rules must pass for %1$s',
self::STANDARD => 'None of these rules must pass for {{name}}',
);
public function chooseTemplate() {
return 0;
}
}
}

View file

@ -8,12 +8,12 @@ class NotEmptyException extends ValidationException
const NAMED = 1;
public static $defaultTemplates = array(
self::STANDARD => 'The value must not be empty',
self::NAMED => '%s must not be empty',
self::NAMED => '{{name}} must not be empty',
);
public function chooseTemplate($name)
public function chooseTemplate()
{
return empty($name) ? static::STANDARD : static::NAMED;
return $this->getName() == "" ? static::STANDARD : static::NAMED;
}
}
}

View file

@ -6,7 +6,7 @@ class NullValueException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be null',
self::STANDARD => '{{name}} must be null',
);
}
}

View file

@ -6,7 +6,7 @@ class NumericException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be numeric',
self::STANDARD => '{{name}} must be numeric',
);
}
}

View file

@ -6,7 +6,7 @@ class ObjectException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be an object',
self::STANDARD => '{{name}} must be an object',
);
}
}

View file

@ -2,12 +2,11 @@
namespace Respect\Validation\Exceptions;
class OneOfException extends AbstractCompositeException
class OneOfException extends AbstractRelatedException
{
public static $defaultTemplates = array(
self::NONE => 'At least one of %4$d rules must pass for %1$s',
self::SOME => 'At least one of %4$d rules must pass for %1$s, only %2$d passed',
self::STANDARD => 'At least one of these rules must pass for {{name}}',
);
}
}

View file

@ -6,7 +6,7 @@ class PositiveException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be positive',
self::STANDARD => '{{name}} must be positive',
);
}
}

View file

@ -6,7 +6,7 @@ class RegexException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must validate against %s',
self::STANDARD => '{{name}} must validate against {{regex}}',
);
}
}

View file

@ -6,7 +6,7 @@ class SfException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s',
self::STANDARD => '{{name}}',
);
}
}

View file

@ -6,7 +6,7 @@ class StringException extends ValidationException
{
public static $defaultTemplates = array(
self::STANDARD => '%s must be a string',
self::STANDARD => '{{name}} must be a string',
);
}
}

View file

@ -5,10 +5,7 @@ namespace Respect\Validation\Exceptions;
use DateTime;
use Exception;
use InvalidArgumentException;
use RecursiveIteratorIterator;
use RecursiveTreeIterator;
use Respect\Validation\ExceptionIterator;
use Respect\Validation\Reportable;
use Respect\Validation\Validatable;
class ValidationException extends InvalidArgumentException
{
@ -20,17 +17,18 @@ class ValidationException extends InvalidArgumentException
);
protected $context = null;
protected $id = '';
protected $params = array();
protected $related = array();
protected $name = 'validation';
protected $template = '';
protected $validator = null;
public static function create($name=null)
public static function format($template, array $vars=array())
{
$i = new static;
if (func_get_args() > 0)
return call_user_func_array(array($i, 'configure'), func_get_args());
else
return $i;
return preg_replace_callback(
'/{{(\w+)}}/',
function($match) use($vars) {
return $vars[$match[1]];
}, $template
);
}
public static function stringify($value)
@ -53,35 +51,20 @@ class ValidationException extends InvalidArgumentException
return $this->getMainMessage();
}
public function addRelated(ValidationException $related)
{
$this->related[] = $related;
return $this;
}
public function chooseTemplate()
{
return key(static::$defaultTemplates);
}
public function configure($name)
public function configure($name, array $params = array())
{
$this->params = func_get_args();
foreach ($this->params as &$p)
$p = static::stringify($p);
$this->setName($name);
$this->setParams($params);
$this->message = $this->getMainMessage();
$this->guessId();
return $this;
}
public function findRelated()
{
$target = $this;
$path = func_get_args();
while (!empty($path) && $target !== false)
$target = $this->getRelatedByName(array_shift($path));
return $target;
}
public function getFullMessage()
{
@ -93,60 +76,41 @@ class ValidationException extends InvalidArgumentException
public function getName()
{
return $this->params[0];
return $this->name;
}
public function getId()
{
return $this->id;
}
public function getIterator($full=false, $mode=self::ITERATE_ALL)
{
$exceptionIterator = new ExceptionIterator($this, $full);
if ($mode == self::ITERATE_ALL)
return new RecursiveIteratorIterator($exceptionIterator, 1);
else
return new RecursiveTreeIterator($exceptionIterator);
}
public function getMainMessage()
{
$sprintfParams = $this->getParams();
if (empty($sprintfParams))
return $this->message;
array_unshift($sprintfParams, $this->getTemplate());
return call_user_func_array('sprintf', $sprintfParams);
$vars = $this->getParams();
$vars['name'] = $this->getName();
return static::format($this->getTemplate(), $vars);
}
public function getParam($name)
{
return $this->hasParam($name) ? $this->params[$name] : false;
}
public function hasParam($name)
{
return isset($this->params[$name]);
}
public function getParams()
{
$params = array_slice($this->params, 1);
array_unshift($params, $this->getName());
return $params;
return $this->params;
}
public function getRelated()
{
return $this->related;
}
public function getRelatedByName($name)
{
foreach ($this->getIterator(true) as $e)
if ($e->getId() === $name)
return $e;
return false;
}
public function getTemplate()
{
if (!empty($this->template))
return $this->template;
$templateKey = call_user_func_array(
array($this, 'chooseTemplate'), $this->getParams()
);
$templateKey = $this->chooseTemplate();
if (is_null($this->context))
$this->template = static::$defaultTemplates[$templateKey];
else
@ -157,8 +121,6 @@ class ValidationException extends InvalidArgumentException
public function setContext($context)
{
$this->context = $context;
foreach ($this->related as $r)
$r->setContext($context);
}
public function setId($id)
@ -169,17 +131,17 @@ class ValidationException extends InvalidArgumentException
public function setName($name)
{
$this->params[0] = static::stringify($name);
$this->name = static::stringify($name);
return $this;
}
public function setRelated(array $relatedExceptions)
public function setParams(array $params)
{
foreach ($relatedExceptions as $related)
$this->addRelated($related);
return $this;
$this->params = array_map(array(get_called_class(), 'stringify'),
$params);
}
public function setTemplate($template)
{
$this->template = $template;
@ -194,4 +156,4 @@ class ValidationException extends InvalidArgumentException
$this->setId($id);
}
}
}

View file

@ -2,11 +2,11 @@
namespace Respect\Validation\Exceptions;
class ZendException extends ValidationException
class ZendException extends AbstractRelatedException
{
public static $defaultTemplates = array(
self::STANDARD => '%s',
self::STANDARD => '{{name}}',
);
}
}

View file

@ -20,37 +20,25 @@ abstract class AbstractComposite extends AbstractRule implements Validatable
public function addRule($validator, $arguments=array())
{
$this->appendRule(
Validator::buildRule($validator, $arguments)
);
if (!$validator instanceof Validatable)
$validator = Validator::buildRule($validator, $arguments);
$this->appendRule($validator);
}
public function addRules(array $validators, $prefix='')
public function addRules(array $validators)
{
foreach ($validators as $validatorKey => $validatorSpec) {
if (is_object($validatorSpec)) {
$this->addRule($validatorSpec);
continue;
} elseif (is_numeric($validatorKey)) {
$validatorName = $validatorSpec;
$validatorArgs = array();
} else {
$validatorName = $validatorKey;
if (!empty($validatorSpec) && !is_array($validatorSpec))
throw new ComponentException(
sprintf(
'Arguments for array-specified validators must be an array, you provided %s',
$validatorSpec
)
);
$validatorArgs = empty($validatorSpec) ? array() : $validatorSpec;
}
if (!empty($prefix))
$validatorName = $prefix . '\\' . $validatorName;
$this->addRule($validatorName, $validatorArgs);
foreach ($validators as $key => $spec) {
if ($spec instanceof Validatable)
$this->appendRule($spec);
if (is_numeric($key) && is_array($spec))
$this->addRules($spec);
elseif (is_array($spec))
$this->addRule($key, $spec);
else
$this->addRule($spec);
}
}
public function getRules()
{
return $this->rules;
@ -88,4 +76,4 @@ abstract class AbstractComposite extends AbstractRule implements Validatable
return $exceptions;
}
}
}

View file

@ -10,13 +10,13 @@ use Respect\Validation\Exceptions\ValidationException;
abstract class AbstractRelated extends AbstractRule implements Validatable
{
protected $mandatory = true;
protected $reference = '';
protected $referenceValidator;
public $mandatory = true;
public $reference = '';
public $referenceValidator;
abstract protected function hasReference($input);
abstract public function hasReference($input);
abstract protected function getReferenceValue($input);
abstract public function getReferenceValue($input);
public function __construct($reference, Validatable $validator=null,
$mandatory=true)
@ -36,10 +36,14 @@ abstract class AbstractRelated extends AbstractRule implements Validatable
$this->getReferenceValue($input)
);
} catch (ValidationException $e) {
throw $this->reportError($input, array($e));
throw $this->reportError(
$input, array('hasReference' => true)
)->addRelated($e);
} catch (ReflectionException $e) {
if ($this->mandatory)
throw $this->reportError($input);
throw $this->reportError(
$input, array('hasReference' => false)
);
}
return true;
}
@ -47,7 +51,9 @@ abstract class AbstractRelated extends AbstractRule implements Validatable
public function check($input)
{
if ($this->mandatory && !$this->hasReference($input))
throw $this->reportError($input);
throw $this->reportError(
$input, array('hasReference' => false)
);
if (!is_null($this->referenceValidator))
$this->referenceValidator->check(
$this->getReferenceValue($input)
@ -55,12 +61,6 @@ abstract class AbstractRelated extends AbstractRule implements Validatable
return true;
}
public function reportError($input, array $relatedExceptions=array())
{
return parent::reportError($input, $relatedExceptions, $this->reference,
!empty($relatedExceptions))->setId($this->reference);
}
public function validate($input)
{
if ($this->mandatory && !$this->hasReference($input))
@ -71,4 +71,4 @@ abstract class AbstractRelated extends AbstractRule implements Validatable
return true;
}
}
}

View file

@ -57,19 +57,16 @@ abstract class AbstractRule implements Validatable
return!empty($this->exception);
}
public function reportError($input, array $related=array())
public function reportError($input, array $extraParams=array())
{
if ($this->hasException())
return $this->getException();
$exception = $this->createException()->setRelated($related);
$parameters = array();
if (func_num_args() > 2)
$parameters = array_slice(func_get_args(), 2);
$exception = $this->createException();
$input = ValidationException::stringify($input);
$exceptionInput = $this->getName() ? : "\"$input\"";
array_unshift($parameters, $exceptionInput);
call_user_func_array(array($exception, 'configure'), $parameters);
$name = $this->getName() ? : "\"$input\"";
$params = array_merge($extraParams, get_object_vars($this));
$exception->configure($name, $params);
return $exception;
}
@ -85,4 +82,4 @@ abstract class AbstractRule implements Validatable
return $this;
}
}
}

View file

@ -9,16 +9,23 @@ class AllOf extends AbstractComposite
{
$exceptions = $this->validateRules($input);
$numRules = count($this->rules);
$numExceptions = count($exceptions);
$summary = array(
'total' => $numRules,
'failed' => $numExceptions,
'passed' => $numRules-$numExceptions
);
if (!empty($exceptions))
throw $this->reportError($input, $exceptions, count($exceptions),
$numRules, $numRules);
throw $this->reportError($input, $summary)->setRelated($exceptions);
return true;
}
public function check($input)
{
foreach ($this->getRules() as $v)
$v->check($input);
if (!$v->check($input))
return false;
return true;
}
public function validate($input)
@ -29,4 +36,4 @@ class AllOf extends AbstractComposite
return true;
}
}
}

View file

@ -5,7 +5,7 @@ namespace Respect\Validation\Rules;
class Alnum extends Alpha
{
protected $additionalChars = '';
protected $stringFormat = '#^([a-zA-Z0-9]|\s)+$#';
public $additionalChars = '';
public $stringFormat = '/^\s*[a-zA-Z0-9]+([a-zA-Z0-9]|\s)*$/';
}
}

View file

@ -7,8 +7,8 @@ use Respect\Validation\Exceptions\ComponentException;
class Alpha extends AbstractRule
{
protected $additionalChars = '';
protected $stringFormat = '#^([a-zA-Z]|\s)+$#';
public $additionalChars = '';
public $stringFormat = '/^\s*[a-zA-Z]+([a-zA-Z]|\s)*$/';
public function __construct($additionalChars='')
{
@ -19,17 +19,13 @@ class Alpha extends AbstractRule
$this->additionalChars = $additionalChars;
}
public function reportError($input, array $related=array())
{
return parent::reportError($input, $related, $this->additionalChars);
}
public function validate($input)
{
return is_string($input) && preg_match(
$this->stringFormat,
str_replace(str_split($this->additionalChars), '', $input)
);
if (!is_scalar($input))
return false;
$cleanInput = str_replace(str_split($this->additionalChars), '', $input);
return ($cleanInput !== $input && $cleanInput === '')
|| preg_match($this->stringFormat, $cleanInput);
}
}
}

View file

@ -5,7 +5,7 @@ namespace Respect\Validation\Rules;
class AtLeast extends AbstractComposite
{
protected $howMany = 1;
public $howMany = 1;
public function __construct($howMany, $rules=array())
{
@ -19,9 +19,14 @@ class AtLeast extends AbstractComposite
$exceptions = $this->validateRules($input);
$numRules = count($validators);
$numExceptions = count($exceptions);
if ($this->howMany > ($numRules - $numExceptions))
throw $this->reportError($input, $exceptions, $numExceptions,
$this->howMany, $numRules);
$numPassed = $numRules - $numExceptions;
$summary = array(
'total' => $numRules,
'failed' => $numExceptions,
'passed' => $numPassed
);
if ($this->howMany > $numPassed)
throw $this->reportError($input, $summary)->setRelated($exceptions);
return true;
}
@ -39,9 +44,9 @@ class AtLeast extends AbstractComposite
}
if ($pass >= $this->howMany)
return true;
if (count($exceptions) > (count($validators) - $this->howMany))
throw $this->reportError($input, $exceptions,
count($exceptions), $this->howMany);
if (count($exceptions) > ($numPassed = count($validators) - $this->howMany))
throw $this->reportError($input, array('passed' => $numPassed))
->setRelated($exceptions);
}
return false;
}
@ -64,4 +69,4 @@ class AtLeast extends AbstractComposite
return false;
}
}
}

View file

@ -19,16 +19,16 @@ class Attribute extends AbstractRelated
parent::__construct($reference, $referenceValidator, $mandatory);
}
protected function getReferenceValue($input)
public function getReferenceValue($input)
{
$propertyMirror = new ReflectionProperty($input, $this->reference);
$propertyMirror->setAccessible(true);
return $propertyMirror->getValue($input);
}
protected function hasReference($input)
public function hasReference($input)
{
return @property_exists($input, $this->reference);
}
}
}

View file

@ -8,13 +8,13 @@ use Respect\Validation\Exceptions\ValidationException;
class Between extends AllOf
{
protected $min;
protected $max;
public $minValue;
public $maxValue;
public function __construct($min=null, $max=null, $inclusive=false)
{
$this->min = $min;
$this->max = $max;
$this->minValue = $min;
$this->maxValue = $max;
if (!is_null($min) && !is_null($max) && $min > $max)
throw new ComponentException(
sprintf(
@ -27,9 +27,4 @@ class Between extends AllOf
$this->addRule(new Max($max, $inclusive));
}
public function reportError($input, array $relatedExceptions=array())
{
return parent::reportError($input, array(), $this->min, $this->max);
}
}
}

View file

@ -5,15 +5,14 @@ namespace Respect\Validation\Rules;
class Call extends AbstractRelated
{
protected function getReferenceValue($input)
public function getReferenceValue($input)
{
return call_user_func($this->reference, $input);
}
protected function hasReference($input)
public function hasReference($input)
{
return is_callable($this->reference);
}
}
}

View file

@ -7,7 +7,7 @@ use Respect\Validation\Exceptions\ComponentException;
class Callback extends AbstractRule
{
protected $callback;
public $callback;
public function __construct($callback)
{
@ -18,14 +18,9 @@ class Callback extends AbstractRule
$this->callback = $callback;
}
public function reportError($input, array $related=array())
{
return parent::reportError($input, $related, $this->callback);
}
public function validate($input)
{
return call_user_func($this->callback, $input);
}
}
}

View file

@ -6,8 +6,8 @@ use DateTime;
class Date extends AbstractRule
{
const FORMAT_DEFAULT = DateTime::RFC1036;
protected $format = self::FORMAT_DEFAULT;
public $format = null;
protected function formatDate(DateTime $date)
{
@ -19,10 +19,6 @@ class Date extends AbstractRule
$this->format = $format;
}
public function reportError($input, array $related=array())
{
return parent::reportError($input, $related, $this->format);
}
public function validate($input)
{
if ($input instanceof DateTime)
@ -35,4 +31,4 @@ class Date extends AbstractRule
return date($this->format, strtotime($input)) == $input;
}
}
}

View file

@ -2,12 +2,10 @@
namespace Respect\Validation\Rules;
class Digits extends AbstractRule
class Digits extends Alpha
{
public function validate($input)
{
return ctype_digit((string) $input);
}
public $additionalChars = '';
public $stringFormat = '/^\s*[0-9]+([0-9]|\s)*$/';
}
}

View file

@ -9,7 +9,8 @@ use Respect\Validation\Exceptions\ValidationException;
class Each extends AbstractRule
{
protected $itemValidator;
public $itemValidator;
public $keyValidator;
public function __construct(Validatable $itemValidator = null,
Validatable $keyValidator=null)
@ -42,7 +43,7 @@ class Each extends AbstractRule
}
}
if (!empty($exceptions))
throw $this->reportError($input, $exceptions, count($exceptions));
throw $this->reportError($input)->setRelated($exceptions);
return true;
}
@ -72,4 +73,4 @@ class Each extends AbstractRule
return true;
}
}
}

View file

@ -5,27 +5,26 @@ namespace Respect\Validation\Rules;
class Equals extends AbstractRule
{
protected $identical = false;
protected $param = null;
public $compareIdentical = false;
public $compareTo = null;
public function __construct($param, $identical=false)
public function __construct($compareTo, $compareIdentical=false)
{
$this->param = $param;
$this->identical = $identical;
$this->compareTo = $compareTo;
$this->compareIdentical = $compareIdentical;
}
public function reportError($input, array $related=array())
public function reportError($input, array $extraParams=array())
{
return parent::reportError($input, $related, $this->param,
$this->identical);
return parent::reportError($input, $extraParams);
}
public function validate($input)
{
if ($this->identical)
return $input === $this->param;
if ($this->compareIdentical)
return $input === $this->compareTo;
else
return $input == $this->param;
return $input == $this->compareTo;
}
}
}

View file

@ -5,36 +5,35 @@ namespace Respect\Validation\Rules;
class In extends AbstractRule
{
protected $options;
protected $strict;
public $haystack;
public $compareIdentical;
public function __construct($options, $strict=false)
public function __construct($haystack, $compareIdentical=false)
{
$this->options = $options;
$this->strict = $strict;
$this->haystack = $haystack;
$this->compareIdentical = $compareIdentical;
}
public function reportError($input, array $related=array())
public function reportError($input, array $extraParams=array())
{
if (is_array($this->options))
$options = implode(',', $this->options);
if (is_array($this->haystack))
$haystack = implode(',', $this->haystack);
else
$options = $this->options;
return parent::reportError($input, $related,
$options, $this->strict);
$haystack = $this->haystack;
return parent::reportError($input, $extraParams);
}
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;
if (is_array($this->haystack))
return in_array($input, $this->haystack, $this->compareIdentical);
elseif (is_string($this->haystack))
if ($this->haystack)
return mb_strpos($this->haystack, $input) !== false;
else
return mb_stripos($this->options, $input) !== false;
return mb_stripos($this->haystacko, $input) !== false;
else
return false;
}
}
}

View file

@ -5,21 +5,21 @@ namespace Respect\Validation\Rules;
class Instance extends AbstractRule
{
public $instance;
public $instanceName;
public function __construct($instance)
public function __construct($instanceName)
{
$this->instance = $instance;
$this->instanceName = $instanceName;
}
public function reportError($input, array $related=array())
public function reportError($input, array $extraParams=array())
{
return parent::reportError($input, $related, $this->instance);
return parent::reportError($input, $extraParams);
}
public function validate($input)
{
return $input instanceof $this->instance;
return $input instanceof $this->instanceName;
}
}
}

View file

@ -5,16 +5,18 @@ namespace Respect\Validation\Rules;
class Ip extends AbstractRule
{
public function __construct($options=null)
public $ipOptions;
public function __construct($ipOptions=null)
{
$this->options = $options;
$this->ipOptions = $ipOptions;
}
public function validate($input)
{
return filter_var(
$input, FILTER_VALIDATE_IP, array('flags' => $this->options)
$input, FILTER_VALIDATE_IP, array('flags' => $this->ipOptions)
);
}
}
}

View file

@ -18,14 +18,14 @@ class Key extends AbstractRelated
parent::__construct($reference, $referenceValidator, $mandatory);
}
protected function getReferenceValue($input)
public function getReferenceValue($input)
{
return @$input[$this->reference];
}
protected function hasReference($input)
public function hasReference($input)
{
return array_key_exists($this->reference, $input);
}
}
}

View file

@ -4,23 +4,20 @@ namespace Respect\Validation\Rules;
use Countable;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidException;
use Respect\Validation\Exceptions\LengthException;
use Respect\Validation\Exceptions\NotNumericException;
use Respect\Validation\Rules\AbstractRule;
use Respect\Validation\Validator;
class Length extends AbstractRule
{
protected $min;
protected $max;
protected $inclusive;
public $minValue;
public $maxValue;
public $inclusive;
public function __construct($min=null, $max=null, $inclusive=true)
{
$this->min = $min;
$this->max = $max;
$this->minValue = $min;
$this->maxValue = $max;
$this->inclusive = $inclusive;
$paramValidator = new OneOf(new Numeric, new NullValue);
if (!$paramValidator->validate($min))
@ -40,11 +37,6 @@ class Length extends AbstractRule
}
}
public function reportError($input, array $related=array())
{
return parent::reportError($input, $related, $this->min, $this->max);
}
public function validate($input)
{
return $this->validateMin($input) && $this->validateMax($input);
@ -63,23 +55,23 @@ class Length extends AbstractRule
protected function validateMin($input)
{
$length = $this->extractLength($input);
if (is_null($this->min))
if (is_null($this->minValue))
return true;
if ($this->inclusive)
return $length >= $this->min;
return $length >= $this->minValue;
else
return $length > $this->min;
return $length > $this->minValue;
}
protected function validateMax($input)
{
$length = $this->extractLength($input);
if (is_null($this->max))
if (is_null($this->maxValue))
return true;
if ($this->inclusive)
return $length <= $this->max;
return $length <= $this->maxValue;
else
return $length < $this->max;
return $length < $this->maxValue;
}
}
}

View file

@ -5,27 +5,21 @@ namespace Respect\Validation\Rules;
class Max extends AbstractRule
{
protected $inclusive;
protected $max;
public $maxValue;
public $inclusive;
public function __construct($maxValue, $inclusive=false)
{
$this->max = $maxValue;
$this->maxValue = $maxValue;
$this->inclusive = $inclusive;
}
public function reportError($input, array $related=array())
{
return parent::reportError($input, $related, $this->max,
$this->inclusive);
}
public function validate($input)
{
if ($this->inclusive)
return $input <= $this->max;
return $input <= $this->maxValue;
else
return $input < $this->max;
return $input < $this->maxValue;
}
}
}

View file

@ -5,27 +5,21 @@ namespace Respect\Validation\Rules;
class Min extends AbstractRule
{
protected $inclusive;
protected $min;
public $inclusive;
public $minValue;
public function __construct($minValue, $inclusive=false)
{
$this->min = $minValue;
$this->minValue = $minValue;
$this->inclusive = $inclusive;
}
public function reportError($input, array $related=array())
{
return parent::reportError($input, $related, $this->min,
$this->inclusive);
}
public function validate($input)
{
if ($this->inclusive)
return $input >= $this->min;
return $input >= $this->minValue;
else
return $input > $this->min;
return $input > $this->minValue;
}
}
}

View file

@ -11,8 +11,7 @@ class NoneOf extends AbstractComposite
$numRules = count($this->getRules());
$numExceptions = count($exceptions);
if ($numRules !== $numExceptions)
throw $this->reportError($input, $exceptions, $numExceptions, 0,
$numRules);
throw $this->reportError($input)->setRelated($exceptions);
return true;
}
@ -27,4 +26,4 @@ class NoneOf extends AbstractComposite
));
}
}
}

View file

@ -11,9 +11,9 @@ class OneOf extends AbstractComposite
$exceptions = $this->validateRules($input);
$numRules = count($validators);
$numExceptions = count($exceptions);
$numPassed = $numRules - $numExceptions;
if ($numExceptions === $numRules)
throw $this->reportError($input, $exceptions, $numExceptions, 1,
$numRules);
throw $this->reportError($input)->setRelated($exceptions);
return true;
}
@ -25,4 +25,4 @@ class OneOf extends AbstractComposite
return false;
}
}
}

View file

@ -5,20 +5,16 @@ namespace Respect\Validation\Rules;
class Regex extends AbstractRule
{
protected $regex;
public $regex;
public function __construct($regex)
{
$this->regex = $regex;
}
public function reportError($input, array $related=array())
{
return parent::reportError($input, $related, $this->regex);
}
public function validate($input)
{
return preg_match("/{$this->regex}/", $input);
}
}
}

View file

@ -8,8 +8,8 @@ use Symfony\Component\Validator\ConstraintViolation;
class Sf extends AbstractRule
{
public $name;
protected $constraint;
protected $name;
protected $messages = array();
protected $validator;
@ -48,4 +48,4 @@ class Sf extends AbstractRule
return $this->validator->isValid($input, $this->constraint);
}
}
}

View file

@ -7,11 +7,13 @@ use ReflectionClass;
class Zend extends AbstractRule
{
public $name;
protected $messages = array();
protected $zendValidator;
public function __construct($name, $params=array())
{
$this->name = $name;
$validatorName = explode('_', $name);
$validatorName = array_map('ucfirst', $validatorName);
$validatorName = implode('\\', $validatorName);
@ -27,9 +29,9 @@ class Zend extends AbstractRule
if (!$this->validate($input)) {
$exceptions = array();
foreach ($this->zendValidator->getMessages() as $m) {
$exceptions[] = $this->createException()->configure($m);
$exceptions[] = $this->createException()->configure($m, get_object_vars($this));
}
throw $this->reportError($input, $exceptions);
throw $this->reportError($input)->setRelated($exceptions);
}
return true;
}
@ -39,4 +41,4 @@ class Zend extends AbstractRule
return $this->zendValidator->isValid($input);
}
}
}

View file

@ -59,12 +59,6 @@ class Validator extends AllOf
return $this;
}
public function __get($property)
{
$this->applyParts(func_get_args());
return $this;
}
public function createException()
{
return new AllOfException;
@ -118,4 +112,4 @@ class Validator extends AllOf
$this->ruleName = $ruleName;
}
}
}

View file

@ -10,8 +10,8 @@
<email>alexandre@gaigalas.net</email>
<active>yes</active>
</lead>
<date>2011-02-09</date>
<time>18:39:22</time>
<date>2011-02-10</date>
<time>18:49:40</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
@ -28,90 +28,90 @@ First Version
<dir baseinstalldir="Respect/Validation" name="/">
<file baseinstalldir="Respect/Validation" md5sum="4ef5c6ff21a7382ac26d74354a9c2ece" name="Contexts/AbstractContext.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="a99e9fcc3f89d82a4b6dfd0fbe487014" name="Contexts/Form.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="d86abeebb741799bfb2aa26aa7bd0983" name="Exceptions/AbstractCompositeException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="0224a04fb381c031061f45f181210d2a" name="Exceptions/AbstractRelatedException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="52c3d7d8bc943a2f1c4b9278cc5a1fd4" name="Exceptions/AllOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="8fc898cfc51fc4c30449a3c6bf8fe9c0" name="Exceptions/AlnumException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="6bab373131ee34cb3a15819532f91866" name="Exceptions/AlphaException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="fb77e1abb84699cae2b66794081223af" name="Exceptions/ArrException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="b1040c95c20d0ddaf1338be5756825de" name="Exceptions/AtLeastException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="8cca21f2184ddeb22baa9793f9039ad5" name="Exceptions/AttributeException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="614fc76aeb66b6ff877278e5b2e3cbd7" name="Exceptions/BetweenException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="96af569a01acf55649f85bdc09c92d9b" name="Exceptions/CallbackException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="061a1ee3b851b2e309a8c4fc02f9a5a0" name="Exceptions/CallException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="571c9ba5e526d69bb85c721a07894b6d" name="Exceptions/AbstractCompositeException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="529c6da1fb1b18ec8c95d571362898d7" name="Exceptions/AbstractRelatedException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="3ca12be55a230b4a1096b680714b3222" name="Exceptions/AllOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="ae818fe09029e856ed02ce70273da0f5" name="Exceptions/AlnumException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="a4e7f3830a04d92bf48ae2e88bb8d488" name="Exceptions/AlphaException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="023aeb25a9aca6311c81e96aa4abf4f8" name="Exceptions/ArrException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="307d62a5000949c783dcec2c6b27b578" name="Exceptions/AtLeastException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="8c5fc5d7c717c87681f7be2c4b5cb505" name="Exceptions/AttributeException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="a2e69b7b2391149e2f0d06d7679b1e84" name="Exceptions/BetweenException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="b6c595b7fcb32a829bf04377fb2baf99" name="Exceptions/CallbackException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="f63902e4f4c6a626bb3dc65997db33d3" name="Exceptions/CallException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="b22f51d15eb7d8fffceadcaf237948f0" name="Exceptions/ComponentException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="a5583e9a0a33a45921414eaed396a358" name="Exceptions/DateException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="b21b7329839a035e35e1afbd27a87d86" name="Exceptions/DigitsException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="091f09cdd40ebc8ac0a8aac4b428e07d" name="Exceptions/EachException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="144469b1c08ae3dc12ecbc5d94291718" name="Exceptions/EqualsException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="c2c37b3e56ebdccba8672f0d5ac0e17a" name="Exceptions/FloatException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="bd2948e8cd79ef47329fca9396ab20a6" name="Exceptions/HexaException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="f146b4cac6921fb9dabb28c3324067b3" name="Exceptions/InException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="9d12aefab2090fca90fce40bea3ec127" name="Exceptions/InstanceException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="237124f983d278b3637bf3a8ac516820" name="Exceptions/IntException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="de32b207559aa2140c5e3b096bbbbc9b" name="Exceptions/IpException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="ebabd22dc2bcabc8b754d1459fc71dab" name="Exceptions/KeyException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="bcc2af9930e9515c4485be6eca13b131" name="Exceptions/LengthException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="2981e6b50997656f22d7f260b7e9d9d9" name="Exceptions/MaxException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="bc021ee31447285489b99e09e9f72156" name="Exceptions/MinException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="720c138a0d4386382788f61f41bccfa8" name="Exceptions/MostOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="54671f8ad89de8fc3d339541624ae86f" name="Exceptions/NegativeException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="732304a26e500e94b6061af9618f2d8b" name="Exceptions/NoneOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="fcd41203ecb8cabc63f8b519f407fc29" name="Exceptions/NotEmptyException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="9b888276cb2109cd6974f49255cf3102" name="Exceptions/NoWhitespaceException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="955a2ce58b344c019873ecc6083318c4" name="Exceptions/NullValueException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="771d29cdf00cb91af4e642a6567ccd0c" name="Exceptions/NumericException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="1a1b6ceec43a4a4ba0d8ab014c3dbca3" name="Exceptions/ObjectException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="899e998ea7908f3856ba388895db0ccf" name="Exceptions/OneOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="2d39834ef0aa8213f78cf2911c997a6b" name="Exceptions/PositiveException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="ab412d1b4edc9c2e05ca1a736de307fd" name="Exceptions/RegexException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="9d312b877f954696df3059eaa7c567b3" name="Exceptions/SfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="ee7ab5470e9cee15c5b0f0e5549d4828" name="Exceptions/StringException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="6c3a342838ed6937a7166ce7ec048b6b" name="Exceptions/ValidationException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="f82ca20630380b0b9d6335a2942d1c84" name="Exceptions/ZendException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="0a6ce27c93ef4f062973c3faa1c1dd2a" name="Rules/AbstractComposite.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="780c5a7a20ab65b5ff8e3d1647c1f90b" name="Rules/AbstractRelated.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="901437e9f6a4610242c042d93fc44285" name="Rules/AbstractRule.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="6a1e115625f44ff71bfe39fa198e40e3" name="Rules/AllOf.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="a431d0ef3c154cb2c5fe7a07bbd56acf" name="Rules/Alnum.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="5cb583f88d4bfb66cf87223947d39cb8" name="Rules/Alpha.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="94bd17781e0cdc8e1d901dd1409d99ec" name="Exceptions/DateException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="294cc49907860578e0afc8f6b67849c0" name="Exceptions/DigitsException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="f74d89c59037c225fc59191f4e601615" name="Exceptions/EachException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="48dda2bfad790b78fd0952b3d1425415" name="Exceptions/EqualsException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="9aa8e37c1e8d11335fbdf073eb40c31f" name="Exceptions/FloatException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="d5b41b6bd10891ed842c2285f0975c6d" name="Exceptions/HexaException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="226e2b87e3bd8d6a3cfeb359ed575b54" name="Exceptions/InException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="0af3b65700bafe2995ddede9c7fc8147" name="Exceptions/InstanceException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="0a858e482f0a5b88a927be1d35af826e" name="Exceptions/IntException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="fd73d54dc27f09db248f15241131a574" name="Exceptions/IpException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="c8f156b64c435a0b0be2858e644c0ce9" name="Exceptions/KeyException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="fd217a043271989aa9fdd1d14ee11887" name="Exceptions/LengthException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="2b9d32dfeb050be51824bb783fe6b38b" name="Exceptions/MaxException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="aa9cba4e18c3084fc118cad99bd5b143" name="Exceptions/MinException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="5f7e12383771ce84388845282ac648d8" name="Exceptions/MostOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="d6892816424411abf0f873c11d13c28f" name="Exceptions/NegativeException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="774a5c5df499cfecd58d22b22322419e" name="Exceptions/NoneOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="372a75be4ae60271e882674190e94a3b" name="Exceptions/NotEmptyException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="700f78b12af170fd83a7828019a7e501" name="Exceptions/NoWhitespaceException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="dee4d709a8359d8afb6b4fed4d1def65" name="Exceptions/NullValueException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="4b8c8c6a3ce99d706e9e7040872f1f48" name="Exceptions/NumericException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="d3b1289ccb22f11759ce19dc92fbe98d" name="Exceptions/ObjectException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="c01b0defc26ea5771bb1fb0cad37bdc3" name="Exceptions/OneOfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="7df34686076be3531c9bbfca3926728b" name="Exceptions/PositiveException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="cb0971a4379482977ddf22a675581255" name="Exceptions/RegexException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="d0498462a420d57ca74fa47e3c8c6194" name="Exceptions/SfException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="a9d0825a244e0b7d6412777c01367650" name="Exceptions/StringException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="cf5979cee838a1267557e41aaae6e084" name="Exceptions/ValidationException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="250fe508ea6c6fa437d8cd37ac1dc697" name="Exceptions/ZendException.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="3677faf1ead7b088e4572cc9c2260bd2" name="Rules/AbstractComposite.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="afcc674a1b283927c4703dd346ca4528" name="Rules/AbstractRelated.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="5eb9b01455189808ae5a9928abda2b76" name="Rules/AbstractRule.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="40d19b8a9f0a0bc60ba6786df0056cea" name="Rules/AllOf.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="7b002c1fab94b46f85c5cb79c50a3c2d" name="Rules/Alnum.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="1f552b16151f61c07ef84a58d7b00754" name="Rules/Alpha.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="25f54c2c1f3d756afb759261c164f8b6" name="Rules/Arr.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="1a03ead07f42b92f344e0fef3bd0ca9b" name="Rules/AtLeast.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="fe981422ba021c8ddd6b0f9803077d01" name="Rules/Attribute.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="c834993e3f8b03ad149034a174a726fd" name="Rules/Between.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="e62cc6a2ae6f1e5b4477668a5ef80cf7" name="Rules/Call.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="a25aa021f8c5d59a1eabae3f2d02182e" name="Rules/Callback.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="88aa7cf2b186bf9386f5391135d1ae0b" name="Rules/Date.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="f6cee7a9c23415c07318af3dbcdba94b" name="Rules/Digits.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="2af88453b285b88079469b3e1dfd939b" name="Rules/Each.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="274db8c9bb7cf03afc154a2c981a846e" name="Rules/Equals.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="9eba4fdf3110d9302b2a80271a3c1f21" name="Rules/AtLeast.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="320aac2002443d72b2a5fc9e494bdaa7" name="Rules/Attribute.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="ca4e19a40d5b248a915198c10cde2630" name="Rules/Between.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="952c2d9d0f61c1613d43554a0fd17e42" name="Rules/Call.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="fc648db054e8001969516e07bd331a26" name="Rules/Callback.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="f460a19d4b469051add54992877ef23e" name="Rules/Date.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="9f72c097ae08a41b0b612799b01d7465" name="Rules/Digits.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="32044ec5ec01ffe2ffa3316a8ecfba21" name="Rules/Each.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="01d224d7f90af4df2ff2eacb6b1c64b4" 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="bf7ac2561935bbc53e83c68cc806a222" name="Rules/In.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="dd45a88cd46b43fadc38ab81cd26dd48" name="Rules/Instance.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="bbbe54813d655580145eed1f871c9162" name="Rules/In.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="34c42f6e0ca06eea6549f0e02e222604" 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="a8ad631deef46684e5a72a00d6611567" name="Rules/Key.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="61b609da7a2c2ec6a6ecf5705bc2460a" name="Rules/Length.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="e83796652f6f382d0359b4fc73c6979c" name="Rules/Max.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="bb1f452f39700db064bed02ab0121c66" name="Rules/Min.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="e2a7b74c52fb1471488bafcfa1029184" name="Rules/Ip.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="4c2c89e577f1295118a8e31b7f4f4938" name="Rules/Key.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="c492374621fb02d2cb5fc8ac519eac2a" name="Rules/Length.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="bae9afe4982f0f8234de4cee675c84da" name="Rules/Max.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="9c3f0d53300b2fbb9cc4721e141bd7be" 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="4f9f5feb5c72b0d436a5c02ffddd8465" name="Rules/NoneOf.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="95d2397abf99304388c03f725d5d10c4" 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" />
<file baseinstalldir="Respect/Validation" md5sum="c5d8a9ee171e6acf3bdab26ef08350c2" name="Rules/NullValue.php" role="php" />
<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="05dd2d2108851f2ba1237ffb9be51ec7" name="Rules/OneOf.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="d65551272c52774e0067b2318c234654" name="Rules/OneOf.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="2b9e4d588eefda35f48b2360dcf5b36d" name="Rules/Positive.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="507bfc98d795bc1035bb453f522b3e57" name="Rules/Regex.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="e67ee6162bbf07e28ddb0f6f3cc55047" name="Rules/Sf.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="c6cc0755ba8b36aebaa6ad7670fc5124" name="Rules/Regex.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="fad11bb57927795ef56cd97e57b5bb50" name="Rules/Sf.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="d3cf890b95664760156f902207242250" name="Rules/String.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="8f8b0eb1acf16eb5e07f4391218340b1" name="Rules/Zend.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="183d34b3e0d1bab169b43a150dc1cdd1" name="ExceptionIterator.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="78e821eafd2d8ea59b5f038a488d0b2c" name="Rules/Zend.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="0cb1b7919e6276beb1e82aa27133ef30" name="ExceptionIterator.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="e2df3f7c6104d57ff0cea651c6cc80c3" name="Validatable.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="13211c7a903f978e3ffe75845d34cc66" name="Validator.php" role="php" />
<file baseinstalldir="Respect/Validation" md5sum="4a90179028b0787f531982548f7861ee" name="Validator.php" role="php" />
</dir>
</contents>
<dependencies>
@ -135,7 +135,7 @@ First Version
<release>alpha</release>
<api>alpha</api>
</stability>
<date>2011-02-09</date>
<date>2011-02-10</date>
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
<notes>
First Version

View file

@ -0,0 +1,31 @@
<?php
namespace Respect\Validation;
use Respect\Validation\Validator as v;
use Respect\Validation\Exceptions\ValidationException;
class CombinedMessagesTest extends \PHPUnit_Framework_TestCase
{
public function testIntPositiveBetween()
{
$int = v::int()->positive()->between(0, 256)->setName('Meu Campo');
try {
$int->assert(null);
} catch (ValidationException $e) {
//echo $e->getFullMessage() . PHP_EOL;
}
}
public function testScreenName()
{
$int = v::alnum('_')->noWhitespace()->length(1, 15);
try {
$int->assert(null);
} catch (ValidationException $e) {
//echo $e->getFullMessage() . PHP_EOL;
}
}
}

View file

@ -1,64 +0,0 @@
<?php
namespace Respect\Validation\Exceptions;
class ValidationExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$e = ValidationException::create(new \stdClass, 'bar');
$this->assertEquals(
array('Object of class stdClass', 'bar'),
$e->getParams()
);
$this->assertEquals('validation', $e->getId());
}
public function testConfigure()
{
$e = new ValidationException;
$e->configure(new \stdClass, 'bar');
$this->assertEquals(
array('Object of class stdClass', 'bar'),
$e->getParams()
);
$this->assertEquals('validation', $e->getId());
}
public function testGetRelatedByName()
{
$a = new ValidationException;
$a1 = new ValidationException;
$a2 = new ValidationException;
$a11 = new ValidationException;
$a21 = new ValidationException;
$a->setId('foo');
$a1->setId('bar1');
$a2->setId('bar2');
$a11->setId('baz1');
$a21->setId('baz2');
$a1->addRelated($a11);
$a2->addRelated($a21);
$a->addRelated($a1);
$a->addRelated($a2);
$this->assertEquals($a1, $a->findRelated('bar1'));
$this->assertEquals($a11, $a->findRelated('bar1', 'baz1'));
$this->assertEquals($a2, $a->findRelated('bar2'));
$this->assertEquals($a21, $a->findRelated('bar2', 'baz2'));
$this->assertEquals(false, $a->findRelated('zzz', 'xxx'));
$this->assertEquals(false, $a->findRelated('bar1', 'xx'));
}
public function testGetMainMessage()
{
$e = ValidationException::create('foo');
$e->setTemplate('Validation baz %s');
$this->assertEquals('Validation baz foo', $e->getMainMessage());
$this->assertEquals($e->getMainMessage(), (string) $e);
}
}

View file

@ -57,7 +57,7 @@ class AbstractRelatedTest extends \PHPUnit_Framework_TestCase
'', new NotEmpty, false, false
);
//overriding exception cause mocks cant handle createException properly
$mock->setException(new \Respect\Validation\Exceptions\ValidationException(''));
$mock->setException(new \Respect\Validation\Exceptions\AbstractRelatedException(''));
$this->assertFalse($mock->assert('bla'));
}
@ -70,7 +70,7 @@ class AbstractRelatedTest extends \PHPUnit_Framework_TestCase
'', null, true, false
);
//overriding exception cause mocks cant handle createException properly
$mock->setException(new \Respect\Validation\Exceptions\ValidationException(''));
$mock->setException(new \Respect\Validation\Exceptions\AbstractRelatedException(''));
$this->assertFalse($mock->assert('bla'));
}
@ -85,4 +85,4 @@ class AbstractRelatedTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($mock->check('bla'));
}
}
}

View file

@ -46,6 +46,7 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
{
return array(
array('alganet', ''),
array('alganet', 'alganet'),
array('0alg-anet0', '0-9'),
array('1', ''),
array('a', ''),
@ -53,8 +54,10 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
array('rubinho_', '_'),
array('google.com', '.'),
array('alganet alganet', ''),
array("\n", ''),
array("\t", ''),
array("\nabc", ''),
array("\tdef", ''),
array("\nabc \t", ''),
array(0, ''),
);
}
@ -63,14 +66,15 @@ class AlnumTest extends \PHPUnit_Framework_TestCase
return array(
array('@#$', ''),
array('_', ''),
array("\t", ''),
array("\n", ''),
array('', ''),
array('dgç', ''),
array(1e21, ''),
array(0, ''),
array(1e21, ''), //evaluates to "1.0E+21"
array(null, ''),
array(new \stdClass, ''),
array(array(), ''),
);
}
}
}

View file

@ -46,14 +46,16 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
{
return array(
array('alganet', ''),
array('alganet', 'alganet'),
array('0alg-anet0', '0-9'),
array('a', ''),
array('foobar', ''),
array('rubinho_', '_'),
array('google.com', '.'),
array('alganet alganet', ''),
array("\n", ''),
array("\t", ''),
array("\nabc", ''),
array("\tdef", ''),
array("\nabc \t", ''),
);
}
@ -63,6 +65,8 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
array('@#$', ''),
array('_', ''),
array('', ''),
array("\t", ''),
array("\n", ''),
array('dgç', ''),
array('122al', ''),
array('122', ''),
@ -75,4 +79,4 @@ class AlphaTest extends \PHPUnit_Framework_TestCase
);
}
}
}

View file

@ -5,32 +5,44 @@ namespace Respect\Validation\Rules;
class DigitsTest extends \PHPUnit_Framework_TestCase
{
protected $object;
protected function setUp()
{
$this->object = new Digits;
}
/**
* @dataProvider providerForDigits
*
* @dataProvider providerForValidDigits
*/
public function testDigits($input)
public function testDigitsValid($validDigits, $aditional='')
{
$this->assertTrue($this->object->assert($input));
$validator = new Digits($aditional);
$this->assertTrue($validator->validate($validDigits));
}
/**
* @dataProvider providerForNotDigits
* @dataProvider providerForInvalidDigits
* @expectedException Respect\Validation\Exceptions\DigitsException
*/
public function testNotDigits($input)
public function testDigitsInvalid($invalidDigits, $aditional='')
{
$this->assertTrue($this->object->assert($input));
$validator = new Digits($aditional);
$validator->assert($invalidDigits);
}
public function providerForDigits()
/**
* @dataProvider providerForInvalidParams
* @expectedException Respect\Validation\Exceptions\ComponentException
*/
public function testInvalidParameters($aditional)
{
$validator = new Digits($aditional);
}
public function providerForInvalidParams()
{
return array(
array(new \stdClass),
array(array()),
array(0x2)
);
}
public function providerForValidDigits()
{
return array(
array(165),
@ -38,21 +50,26 @@ class DigitsTest extends \PHPUnit_Framework_TestCase
array('01650'),
array('165'),
array('1650'),
array('16 50'),
array("\n5\t"),
array('16-50', '-'),
);
}
public function providerForNotDigits()
public function providerForInvalidDigits()
{
return array(
array(null),
array('16-50'),
array('a'),
array(' '),
array('Foo'),
array(''),
array("\n\t"),
array('12.1'),
array('-12'),
array(-12),
);
}
}
}

View file

@ -18,7 +18,7 @@ class IpTest extends \PHPUnit_Framework_TestCase
*/
public function testIp($input, $options=null)
{
$this->object->options = $options;
$this->object->ipOptions = $options;
$this->assertTrue($this->object->assert($input));
}
@ -28,7 +28,7 @@ class IpTest extends \PHPUnit_Framework_TestCase
*/
public function testNotIp($input, $options=null)
{
$this->object->options = $options;
$this->object->ipOptions = $options;
$this->assertTrue($this->object->assert($input));
}
@ -51,4 +51,4 @@ class IpTest extends \PHPUnit_Framework_TestCase
);
}
}
}