minor #11485 [Validator] Constraint validators now use the 2.5 API (webmozart)
This PR was squashed before being merged into the 2.5 branch (closes #11485). Discussion ---------- [Validator] Constraint validators now use the 2.5 API | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See the comments in #11049 for the origin of this PR. Currently, the 2.5 API needs to use `LegacyExecutionContextFactory` because the constraint validators rely on methods from the old `ExecutionContext` class (like `validate()`, `validateValue()`). Consequently it is impossible to switch to the pure 2.5 API and check whether all calls to deprecated methods were removed from application code. This is fixed now. This PR also introduces a complete test suite to test each constraint validator against all three APIs: 2.4, 2.5-BC and 2.5. Currently, some tests are not executed yet when running the complete test suite is run. I expect this to be fixed soon (ticket: sebastianbergmann/phpunit#529, pr: sebastianbergmann/phpunit#1327). Commits -------295e5bb
[Validator] Fixed failing tests3bd6d80
[Validator] CS fixes870a41a
[FrameworkBundle] Made ConstraintValidatorFactory aware of the legacy validators7504448
[Validator] Added extensive test coverage for the constraint validators for the different APIs8e461af
[Validator] Constraint validators now use the 2.5 API. For incompatible validators, legacy validators were created
This commit is contained in:
commit
a6a7f5d2f5
@ -718,6 +718,7 @@ class FrameworkExtension extends Extension
|
||||
switch ($config['api']) {
|
||||
case '2.4':
|
||||
$api = Validation::API_VERSION_2_4;
|
||||
$container->setParameter('validator.validator_factory.class', $container->getParameter('validator.legacy_validator_factory.class'));
|
||||
break;
|
||||
case '2.5':
|
||||
$api = Validation::API_VERSION_2_5;
|
||||
|
@ -11,6 +11,7 @@
|
||||
<parameter key="validator.mapping.cache.apc.class">Symfony\Component\Validator\Mapping\Cache\ApcCache</parameter>
|
||||
<parameter key="validator.mapping.cache.prefix" />
|
||||
<parameter key="validator.validator_factory.class">Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory</parameter>
|
||||
<parameter key="validator.legacy_validator_factory.class">Symfony\Bundle\FrameworkBundle\Validator\LegacyConstraintValidatorFactory</parameter>
|
||||
<parameter key="validator.expression.class">Symfony\Component\Validator\Constraints\ExpressionValidator</parameter>
|
||||
<parameter key="validator.email.class">Symfony\Component\Validator\Constraints\EmailValidator</parameter>
|
||||
</parameters>
|
||||
|
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Validator;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
|
||||
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* Like {@link ConstraintValidatorFactory}, but aware of services compatible
|
||||
* with the 2.4 API.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*
|
||||
* @see ConstraintValidatorFactory
|
||||
*/
|
||||
class LegacyConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
|
||||
{
|
||||
const BASE_NAMESPACE = 'Symfony\\Component\\Validator\\Constraints';
|
||||
|
||||
protected $container;
|
||||
protected $validators;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ContainerInterface $container The service container
|
||||
* @param array $validators An array of validators
|
||||
*/
|
||||
public function __construct(ContainerInterface $container, array $validators = array())
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->validators = $validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validator for the supplied constraint.
|
||||
*
|
||||
* @param Constraint $constraint A constraint
|
||||
*
|
||||
* @return ConstraintValidatorInterface A validator for the supplied constraint
|
||||
*
|
||||
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
|
||||
*/
|
||||
public function getInstance(Constraint $constraint)
|
||||
{
|
||||
$name = $constraint->validatedBy();
|
||||
|
||||
if (!isset($this->validators[$name])) {
|
||||
switch (get_class($constraint)) {
|
||||
case self::BASE_NAMESPACE.'\\All':
|
||||
$name = self::BASE_NAMESPACE.'\\LegacyAllValidator';
|
||||
break;
|
||||
case self::BASE_NAMESPACE.'\\Choice':
|
||||
$name = self::BASE_NAMESPACE.'\\LegacyChoiceValidator';
|
||||
break;
|
||||
case self::BASE_NAMESPACE.'\\Collection':
|
||||
$name = self::BASE_NAMESPACE.'\\LegacyCollectionValidator';
|
||||
break;
|
||||
case self::BASE_NAMESPACE.'\\Count':
|
||||
$name = self::BASE_NAMESPACE.'\\LegacyCountValidator';
|
||||
break;
|
||||
case self::BASE_NAMESPACE.'\\Length':
|
||||
$name = self::BASE_NAMESPACE.'\\LegacyLengthValidator';
|
||||
break;
|
||||
}
|
||||
|
||||
$this->validators[$name] = new $name();
|
||||
} elseif (is_string($this->validators[$name])) {
|
||||
$this->validators[$name] = $this->container->get($this->validators[$name]);
|
||||
}
|
||||
|
||||
if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
|
||||
throw new UnexpectedTypeException($this->validators[$name], 'Symfony\Component\Validator\ConstraintValidatorInterface');
|
||||
}
|
||||
|
||||
return $this->validators[$name];
|
||||
}
|
||||
}
|
@ -41,11 +41,10 @@ class AllValidator extends ConstraintValidator
|
||||
|
||||
$context = $this->context;
|
||||
$group = $context->getGroup();
|
||||
$validator = $context->getValidator()->inContext($context);
|
||||
|
||||
foreach ($value as $key => $element) {
|
||||
foreach ($constraint->constraints as $constr) {
|
||||
$context->validateValue($element, $constr, '['.$key.']', $group);
|
||||
}
|
||||
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints, $group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,25 +63,35 @@ class ChoiceValidator extends ConstraintValidator
|
||||
if ($constraint->multiple) {
|
||||
foreach ($value as $_value) {
|
||||
if (!in_array($_value, $choices, $constraint->strict)) {
|
||||
$this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value));
|
||||
$this->context->buildViolation($constraint->multipleMessage)
|
||||
->setParameter('{{ value }}', $_value)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($value);
|
||||
|
||||
if ($constraint->min !== null && $count < $constraint->min) {
|
||||
$this->context->addViolation($constraint->minMessage, array('{{ limit }}' => $constraint->min), null, (int) $constraint->min);
|
||||
$this->context->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setPlural((int) $constraint->min)
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($constraint->max !== null && $count > $constraint->max) {
|
||||
$this->context->addViolation($constraint->maxMessage, array('{{ limit }}' => $constraint->max), null, (int) $constraint->max);
|
||||
$this->context->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setPlural((int) $constraint->max)
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $value)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,29 +50,35 @@ class CollectionValidator extends ConstraintValidator
|
||||
// to validate() instead.
|
||||
$context = $this->context;
|
||||
$group = $context->getGroup();
|
||||
$validator = $context->getValidator()->inContext($context);
|
||||
|
||||
foreach ($constraint->fields as $field => $fieldConstraint) {
|
||||
if (
|
||||
// bug fix issue #2779
|
||||
(is_array($value) && array_key_exists($field, $value)) ||
|
||||
($value instanceof \ArrayAccess && $value->offsetExists($field))
|
||||
) {
|
||||
foreach ($fieldConstraint->constraints as $constr) {
|
||||
$context->validateValue($value[$field], $constr, '['.$field.']', $group);
|
||||
// bug fix issue #2779
|
||||
$existsInArray = is_array($value) && array_key_exists($field, $value);
|
||||
$existsInArrayAccess = $value instanceof \ArrayAccess && $value->offsetExists($field);
|
||||
|
||||
if ($existsInArray || $existsInArrayAccess) {
|
||||
if (count($fieldConstraint->constraints) > 0) {
|
||||
$validator->atPath('['.$field.']')
|
||||
->validate($value[$field], $fieldConstraint->constraints, $group);
|
||||
}
|
||||
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
||||
$context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
|
||||
'{{ field }}' => $field
|
||||
), null);
|
||||
$context->buildViolation($constraint->missingFieldsMessage)
|
||||
->atPath('['.$field.']')
|
||||
->setParameter('{{ field }}', $field)
|
||||
->setInvalidValue(null)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$constraint->allowExtraFields) {
|
||||
foreach ($value as $field => $fieldValue) {
|
||||
if (!isset($constraint->fields[$field])) {
|
||||
$context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
|
||||
'{{ field }}' => $field
|
||||
), $fieldValue);
|
||||
$context->buildViolation($constraint->extraFieldsMessage)
|
||||
->atPath('['.$field.']')
|
||||
->setParameter('{{ field }}', $field)
|
||||
->setInvalidValue($fieldValue)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,28 +36,34 @@ class CountValidator extends ConstraintValidator
|
||||
$count = count($value);
|
||||
|
||||
if ($constraint->min == $constraint->max && $count != $constraint->min) {
|
||||
$this->context->addViolation($constraint->exactMessage, array(
|
||||
'{{ count }}' => $count,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
$this->context->buildViolation($constraint->exactMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->max && $count > $constraint->max) {
|
||||
$this->context->addViolation($constraint->maxMessage, array(
|
||||
'{{ count }}' => $count,
|
||||
'{{ limit }}' => $constraint->max,
|
||||
), $value, (int) $constraint->max);
|
||||
$this->context->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->min && $count < $constraint->min) {
|
||||
$this->context->addViolation($constraint->minMessage, array(
|
||||
'{{ count }}' => $count,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
$this->context->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5.3, to be removed in 3.0.
|
||||
*/
|
||||
class LegacyAllValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$constraint instanceof All) {
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\All');
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($value) && !$value instanceof \Traversable) {
|
||||
throw new UnexpectedTypeException($value, 'array or Traversable');
|
||||
}
|
||||
|
||||
$context = $this->context;
|
||||
$group = $context->getGroup();
|
||||
|
||||
foreach ($value as $key => $element) {
|
||||
$context->validateValue($element, $constraint->constraints, '['.$key.']', $group);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* ChoiceValidator validates that the value is one of the expected values.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5.3, to be removed in 3.0.
|
||||
*/
|
||||
class LegacyChoiceValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$constraint instanceof Choice) {
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice');
|
||||
}
|
||||
|
||||
if (!$constraint->choices && !$constraint->callback) {
|
||||
throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice');
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($constraint->multiple && !is_array($value)) {
|
||||
throw new UnexpectedTypeException($value, 'array');
|
||||
}
|
||||
|
||||
if ($constraint->callback) {
|
||||
if (is_callable(array($this->context->getClassName(), $constraint->callback))) {
|
||||
$choices = call_user_func(array($this->context->getClassName(), $constraint->callback));
|
||||
} elseif (is_callable($constraint->callback)) {
|
||||
$choices = call_user_func($constraint->callback);
|
||||
} else {
|
||||
throw new ConstraintDefinitionException('The Choice constraint expects a valid callback');
|
||||
}
|
||||
} else {
|
||||
$choices = $constraint->choices;
|
||||
}
|
||||
|
||||
if ($constraint->multiple) {
|
||||
foreach ($value as $_value) {
|
||||
if (!in_array($_value, $choices, $constraint->strict)) {
|
||||
$this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value));
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($value);
|
||||
|
||||
if ($constraint->min !== null && $count < $constraint->min) {
|
||||
$this->context->addViolation($constraint->minMessage, array('{{ limit }}' => $constraint->min), $value, (int) $constraint->min);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($constraint->max !== null && $count > $constraint->max) {
|
||||
$this->context->addViolation($constraint->maxMessage, array('{{ limit }}' => $constraint->max), $value, (int) $constraint->max);
|
||||
|
||||
return;
|
||||
}
|
||||
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5.3, to be removed in 3.0.
|
||||
*/
|
||||
class LegacyCollectionValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$constraint instanceof Collection) {
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Collection');
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($value) && !($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
|
||||
throw new UnexpectedTypeException($value, 'array or Traversable and ArrayAccess');
|
||||
}
|
||||
|
||||
// We need to keep the initialized context when CollectionValidator
|
||||
// calls itself recursively (Collection constraints can be nested).
|
||||
// Since the context of the validator is overwritten when initialize()
|
||||
// is called for the nested constraint, the outer validator is
|
||||
// acting on the wrong context when the nested validation terminates.
|
||||
//
|
||||
// A better solution - which should be approached in Symfony 3.0 - is to
|
||||
// remove the initialize() method and pass the context as last argument
|
||||
// to validate() instead.
|
||||
$context = $this->context;
|
||||
$group = $context->getGroup();
|
||||
|
||||
foreach ($constraint->fields as $field => $fieldConstraint) {
|
||||
// bug fix issue #2779
|
||||
$existsInArray = is_array($value) && array_key_exists($field, $value);
|
||||
$existsInArrayAccess = $value instanceof \ArrayAccess && $value->offsetExists($field);
|
||||
|
||||
if ($existsInArray || $existsInArrayAccess) {
|
||||
if (count($fieldConstraint->constraints) > 0) {
|
||||
$context->validateValue($value[$field], $fieldConstraint->constraints, '['.$field.']', $group);
|
||||
}
|
||||
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
||||
$context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
|
||||
'{{ field }}' => $field
|
||||
), null);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$constraint->allowExtraFields) {
|
||||
foreach ($value as $field => $fieldValue) {
|
||||
if (!isset($constraint->fields[$field])) {
|
||||
$context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
|
||||
'{{ field }}' => $field
|
||||
), $fieldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5.3, to be removed in 3.0.
|
||||
*/
|
||||
class LegacyCountValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (null === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($value) && !$value instanceof \Countable) {
|
||||
throw new UnexpectedTypeException($value, 'array or \Countable');
|
||||
}
|
||||
|
||||
$count = count($value);
|
||||
|
||||
if ($constraint->min == $constraint->max && $count != $constraint->min) {
|
||||
$this->context->addViolation($constraint->exactMessage, array(
|
||||
'{{ count }}' => $count,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->max && $count > $constraint->max) {
|
||||
$this->context->addViolation($constraint->maxMessage, array(
|
||||
'{{ count }}' => $count,
|
||||
'{{ limit }}' => $constraint->max,
|
||||
), $value, (int) $constraint->max);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->min && $count < $constraint->min) {
|
||||
$this->context->addViolation($constraint->minMessage, array(
|
||||
'{{ count }}' => $count,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5.3, to be removed in 3.0.
|
||||
*/
|
||||
class LegacyLengthValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$constraint instanceof Length) {
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Length');
|
||||
}
|
||||
|
||||
if (null === $value || '' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
|
||||
throw new UnexpectedTypeException($value, 'string');
|
||||
}
|
||||
|
||||
$stringValue = (string) $value;
|
||||
|
||||
if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
|
||||
$length = grapheme_strlen($stringValue);
|
||||
} elseif (function_exists('mb_strlen')) {
|
||||
$length = mb_strlen($stringValue, $constraint->charset);
|
||||
} else {
|
||||
$length = strlen($stringValue);
|
||||
}
|
||||
|
||||
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
||||
$this->context->addViolation($constraint->exactMessage, array(
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->max && $length > $constraint->max) {
|
||||
$this->context->addViolation($constraint->maxMessage, array(
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->max,
|
||||
), $value, (int) $constraint->max);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->min && $length < $constraint->min) {
|
||||
$this->context->addViolation($constraint->minMessage, array(
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
}
|
||||
}
|
||||
}
|
@ -48,28 +48,34 @@ class LengthValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
||||
$this->context->addViolation($constraint->exactMessage, array(
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
$this->context->buildViolation($constraint->exactMessage)
|
||||
->setParameter('{{ value }}', $stringValue)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->max && $length > $constraint->max) {
|
||||
$this->context->addViolation($constraint->maxMessage, array(
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->max,
|
||||
), $value, (int) $constraint->max);
|
||||
$this->context->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ value }}', $stringValue)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->min && $length < $constraint->min) {
|
||||
$this->context->addViolation($constraint->minMessage, array(
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->min,
|
||||
), $value, (int) $constraint->min);
|
||||
$this->context->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ value }}', $stringValue)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\ExpressionValidator;
|
||||
|
||||
/**
|
||||
* Backwards compatible implementation of the {@link ConstraintValidatorFactoryInterface}.
|
||||
*
|
||||
* This class uses legacy constraint validators where possible to ensure
|
||||
* compatibility with the 2.4 validator API.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5.3, to be removed in 3.0.
|
||||
*/
|
||||
class LegacyConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
|
||||
{
|
||||
protected $validators = array();
|
||||
|
||||
private $propertyAccessor;
|
||||
|
||||
public function __construct($propertyAccessor = null)
|
||||
{
|
||||
$this->propertyAccessor = $propertyAccessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInstance(Constraint $constraint)
|
||||
{
|
||||
switch (get_class($constraint)) {
|
||||
case __NAMESPACE__.'\\Constraints\\All':
|
||||
$className = __NAMESPACE__.'\\Constraints\\LegacyAllValidator';
|
||||
break;
|
||||
case __NAMESPACE__.'\\Constraints\\Choice':
|
||||
$className = __NAMESPACE__.'\\Constraints\\LegacyChoiceValidator';
|
||||
break;
|
||||
case __NAMESPACE__.'\\Constraints\\Collection':
|
||||
$className = __NAMESPACE__.'\\Constraints\\LegacyCollectionValidator';
|
||||
break;
|
||||
case __NAMESPACE__.'\\Constraints\\Count':
|
||||
$className = __NAMESPACE__.'\\Constraints\\LegacyCountValidator';
|
||||
break;
|
||||
case __NAMESPACE__.'\\Constraints\\Length':
|
||||
$className = __NAMESPACE__.'\\Constraints\\LegacyLengthValidator';
|
||||
break;
|
||||
default:
|
||||
$className = $constraint->validatedBy();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isset($this->validators[$className])) {
|
||||
$this->validators[$className] = 'validator.expression' === $className
|
||||
? new ExpressionValidator($this->propertyAccessor)
|
||||
: new $className();
|
||||
}
|
||||
|
||||
return $this->validators[$className];
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\AbstractComparisonValidator;
|
||||
|
||||
class ComparisonTest_Class
|
||||
{
|
||||
@ -32,30 +31,15 @@ class ComparisonTest_Class
|
||||
/**
|
||||
* @author Daniel Holmes <daniel@danielholmes.org>
|
||||
*/
|
||||
abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_TestCase
|
||||
abstract class AbstractComparisonValidatorTestCase extends AbstractConstraintValidatorTest
|
||||
{
|
||||
private $validator;
|
||||
private $context;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->validator = $this->createValidator();
|
||||
$this->context = $this->getMockBuilder('Symfony\Component\Validator\ExecutionContext')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->validator->initialize($this->context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AbstractComparisonValidator
|
||||
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
|
||||
*/
|
||||
abstract protected function createValidator();
|
||||
|
||||
public function testThrowsConstraintExceptionIfNoValueOrProperty()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
$comparison = $this->createConstraint(array());
|
||||
|
||||
$this->validator->validate('some value', $comparison);
|
||||
}
|
||||
|
||||
@ -66,16 +50,11 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te
|
||||
*/
|
||||
public function testValidComparisonToValue($dirtyValue, $comparisonValue)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$constraint = $this->createConstraint(array('value' => $comparisonValue));
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyPath')
|
||||
->will($this->returnValue('property1'));
|
||||
|
||||
$this->validator->validate($dirtyValue, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,19 +74,13 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te
|
||||
$constraint = $this->createConstraint(array('value' => $comparedValue));
|
||||
$constraint->message = 'Constraint Message';
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyPath')
|
||||
->will($this->returnValue('property1'));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('Constraint Message', array(
|
||||
'{{ value }}' => $comparedValueString,
|
||||
'{{ compared_value }}' => $comparedValueString,
|
||||
'{{ compared_value_type }}' => $comparedValueType
|
||||
));
|
||||
|
||||
$this->validator->validate($dirtyValue, $constraint);
|
||||
|
||||
$this->assertViolation('Constraint Message', array(
|
||||
'{{ value }}' => $comparedValueString,
|
||||
'{{ compared_value }}' => $comparedValueString,
|
||||
'{{ compared_value_type }}' => $comparedValueType
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolation;
|
||||
use Symfony\Component\Validator\Context\ExecutionContext;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Context\LegacyExecutionContext;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\PropertyMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\StubGlobalExecutionContext;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ExecutionContextInterface
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var ConstraintValidatorInterface
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
protected $group;
|
||||
|
||||
protected $metadata;
|
||||
|
||||
protected $object;
|
||||
|
||||
protected $value;
|
||||
|
||||
protected $root;
|
||||
|
||||
protected $propertyPath;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->group = 'MyGroup';
|
||||
$this->metadata = null;
|
||||
$this->object = null;
|
||||
$this->value = 'InvalidValue';
|
||||
$this->root = 'root';
|
||||
$this->propertyPath = 'property.path';
|
||||
$this->context = $this->createContext();
|
||||
$this->validator = $this->createValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
}
|
||||
|
||||
protected function createContext()
|
||||
{
|
||||
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
|
||||
|
||||
if (Validation::API_VERSION_2_4 === $this->getApiVersion()) {
|
||||
return $this->getMockBuilder('Symfony\Component\Validator\ExecutionContext')
|
||||
->setConstructorArgs(array(
|
||||
new StubGlobalExecutionContext($this->root),
|
||||
$translator,
|
||||
null,
|
||||
$this->metadata,
|
||||
$this->value,
|
||||
$this->group,
|
||||
$this->propertyPath
|
||||
))
|
||||
->setMethods(array('validate', 'validateValue'))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
|
||||
$contextualValidator = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');
|
||||
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_5:
|
||||
$context = new ExecutionContext(
|
||||
$validator,
|
||||
$this->root,
|
||||
$translator
|
||||
);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$context = new LegacyExecutionContext(
|
||||
$validator,
|
||||
$this->root,
|
||||
$this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'),
|
||||
$translator
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException('Invalid API version');
|
||||
}
|
||||
|
||||
$context->setGroup($this->group);
|
||||
$context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
|
||||
|
||||
$validator->expects($this->any())
|
||||
->method('inContext')
|
||||
->with($context)
|
||||
->will($this->returnValue($contextualValidator));
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function createViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null)
|
||||
{
|
||||
return new ConstraintViolation(
|
||||
null,
|
||||
$message,
|
||||
$parameters,
|
||||
$this->root,
|
||||
$propertyPath,
|
||||
$invalidValue,
|
||||
$plural,
|
||||
$code
|
||||
);
|
||||
}
|
||||
|
||||
protected function setGroup($group)
|
||||
{
|
||||
$this->group = $group;
|
||||
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_4:
|
||||
$this->context = $this->createContext();
|
||||
$this->validator->initialize($this->context);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5:
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$this->context->setGroup($group);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setObject($object)
|
||||
{
|
||||
$this->object = $object;
|
||||
$this->metadata = is_object($object)
|
||||
? new ClassMetadata(get_class($object))
|
||||
: null;
|
||||
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_4:
|
||||
$this->context = $this->createContext();
|
||||
$this->validator->initialize($this->context);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5:
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setProperty($object, $property)
|
||||
{
|
||||
$this->object = $object;
|
||||
$this->metadata = is_object($object)
|
||||
? new PropertyMetadata(get_class($object), $property)
|
||||
: null;
|
||||
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_4:
|
||||
$this->context = $this->createContext();
|
||||
$this->validator->initialize($this->context);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5:
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_4:
|
||||
$this->context = $this->createContext();
|
||||
$this->validator->initialize($this->context);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5:
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setRoot($root)
|
||||
{
|
||||
$this->root = $root;
|
||||
$this->context = $this->createContext();
|
||||
$this->validator->initialize($this->context);
|
||||
}
|
||||
|
||||
protected function setPropertyPath($propertyPath)
|
||||
{
|
||||
$this->propertyPath = $propertyPath;
|
||||
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_4:
|
||||
$this->context = $this->createContext();
|
||||
$this->validator->initialize($this->context);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5:
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function expectValidateAt($i, $propertyPath, $value, $group)
|
||||
{
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_4:
|
||||
$this->context->expects($this->at($i))
|
||||
->method('validate')
|
||||
->with($value, $propertyPath, $group);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5:
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$validator = $this->context->getValidator()->inContext($this->context);
|
||||
$validator->expects($this->at(2 * $i))
|
||||
->method('atPath')
|
||||
->with($propertyPath)
|
||||
->will($this->returnValue($validator));
|
||||
$validator->expects($this->at(2 * $i + 1))
|
||||
->method('validate')
|
||||
->with($value, array(), $group);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group)
|
||||
{
|
||||
switch ($this->getApiVersion()) {
|
||||
case Validation::API_VERSION_2_4:
|
||||
$this->context->expects($this->at($i))
|
||||
->method('validateValue')
|
||||
->with($value, $constraints, $propertyPath, $group);
|
||||
break;
|
||||
case Validation::API_VERSION_2_5:
|
||||
case Validation::API_VERSION_2_5_BC:
|
||||
$contextualValidator = $this->context->getValidator()->inContext($this->context);
|
||||
$contextualValidator->expects($this->at(2 * $i))
|
||||
->method('atPath')
|
||||
->with($propertyPath)
|
||||
->will($this->returnValue($contextualValidator));
|
||||
$contextualValidator->expects($this->at(2 * $i + 1))
|
||||
->method('validate')
|
||||
->with($value, $constraints, $group);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function assertNoViolation()
|
||||
{
|
||||
$this->assertCount(0, $this->context->getViolations());
|
||||
}
|
||||
|
||||
protected function assertViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null)
|
||||
{
|
||||
$violations = $this->context->getViolations();
|
||||
|
||||
$this->assertCount(1, $violations);
|
||||
$this->assertEquals($this->createViolation($message, $parameters, $propertyPath, $invalidValue, $plural, $code), $violations[0]);
|
||||
}
|
||||
|
||||
protected function assertViolations(array $expected)
|
||||
{
|
||||
$violations = $this->context->getViolations();
|
||||
|
||||
$this->assertCount(count($expected), $violations);
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($expected as $violation) {
|
||||
$this->assertEquals($violation, $violations[$i++]);
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected function getApiVersion();
|
||||
|
||||
abstract protected function createValidator();
|
||||
}
|
@ -15,35 +15,25 @@ use Symfony\Component\Validator\Constraints\All;
|
||||
use Symfony\Component\Validator\Constraints\AllValidator;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class AllValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class AllValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new AllValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getGroup')
|
||||
->will($this->returnValue('MyGroup'));
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->validator = null;
|
||||
$this->context = null;
|
||||
return new AllValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new All(new Range(array('min' => 4))));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,18 +51,15 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$i = 1;
|
||||
$i = 0;
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$this->context->expects($this->at($i++))
|
||||
->method('validateValue')
|
||||
->with($value, $constraint, '['.$key.']', 'MyGroup');
|
||||
$this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint), 'MyGroup');
|
||||
}
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($array, new All($constraint));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,21 +71,16 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$constraint2 = new NotNull();
|
||||
|
||||
$constraints = array($constraint1, $constraint2);
|
||||
$i = 1;
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$this->context->expects($this->at($i++))
|
||||
->method('validateValue')
|
||||
->with($value, $constraint1, '['.$key.']', 'MyGroup');
|
||||
$this->context->expects($this->at($i++))
|
||||
->method('validateValue')
|
||||
->with($value, $constraint2, '['.$key.']', 'MyGroup');
|
||||
$this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint1, $constraint2), 'MyGroup');
|
||||
}
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($array, new All($constraints));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidArguments()
|
||||
|
@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Blank;
|
||||
use Symfony\Component\Validator\Constraints\BlankValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class BlankValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class BlankValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new BlankValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new BlankValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Blank());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testBlankIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Blank());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,13 +50,12 @@ class BlankValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $value,
|
||||
));
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation(
|
||||
'myMessage',
|
||||
array('{{ value }}' => $value)
|
||||
);
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
|
@ -14,13 +14,14 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\CallbackValidator;
|
||||
use Symfony\Component\Validator\ExecutionContext;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class CallbackValidatorTest_Class
|
||||
{
|
||||
public static function validateCallback($object, ExecutionContext $context)
|
||||
public static function validateCallback($object, ExecutionContextInterface $context)
|
||||
{
|
||||
$context->addViolation('Callback message', array('{{ value }}' => 'foobar'), 'invalidValue');
|
||||
$context->addViolation('Callback message', array('{{ value }}' => 'foobar'));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -28,45 +29,38 @@ class CallbackValidatorTest_Class
|
||||
|
||||
class CallbackValidatorTest_Object
|
||||
{
|
||||
public function validate(ExecutionContext $context)
|
||||
public function validate(ExecutionContextInterface $context)
|
||||
{
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue');
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function validateStatic($object, ExecutionContext $context)
|
||||
public static function validateStatic($object, ExecutionContextInterface $context)
|
||||
{
|
||||
$context->addViolation('Static message', array('{{ value }}' => 'baz'), 'otherInvalidValue');
|
||||
$context->addViolation('Static message', array('{{ value }}' => 'baz'));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class CallbackValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new CallbackValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new CallbackValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Callback(array('foo')));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testSingleMethod()
|
||||
@ -74,13 +68,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback('validate');
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testSingleMethodExplicitName()
|
||||
@ -88,13 +80,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback(array('callback' => 'validate'));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testSingleStaticMethod()
|
||||
@ -102,68 +92,60 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback('validateStatic');
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
));
|
||||
}
|
||||
|
||||
public function testClosure()
|
||||
{
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback(function ($object, ExecutionContext $context) {
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue');
|
||||
$constraint = new Callback(function ($object, ExecutionContextInterface $context) {
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'));
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testClosureNullObject()
|
||||
{
|
||||
$constraint = new Callback(function ($object, ExecutionContext $context) {
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue');
|
||||
$constraint = new Callback(function ($object, ExecutionContextInterface $context) {
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'));
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate(null, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testClosureExplicitName()
|
||||
{
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback(array(
|
||||
'callback' => function ($object, ExecutionContext $context) {
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue');
|
||||
'callback' => function ($object, ExecutionContextInterface $context) {
|
||||
$context->addViolation('My message', array('{{ value }}' => 'foobar'));
|
||||
|
||||
return false;
|
||||
},
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testArrayCallable()
|
||||
@ -171,26 +153,22 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback(array(__CLASS__.'_Class', 'validateCallback'));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testArrayCallableNullObject()
|
||||
{
|
||||
$constraint = new Callback(array(__CLASS__.'_Class', 'validateCallback'));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate(null, $constraint);
|
||||
|
||||
$this->assertViolation('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testArrayCallableExplicitName()
|
||||
@ -200,13 +178,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'callback' => array(__CLASS__.'_Class', 'validateCallback'),
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -215,13 +191,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback(array('validate'));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -230,13 +204,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback(array('methods' => array('validate')));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -245,18 +217,16 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$object = new CallbackValidatorTest_Object();
|
||||
$constraint = new Callback(array('validate', 'validateStatic'));
|
||||
|
||||
$this->context->expects($this->at(0))
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
$this->context->expects($this->at(1))
|
||||
->method('addViolation')
|
||||
->with('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolations(array(
|
||||
$this->createViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
)),
|
||||
$this->createViolation('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -267,18 +237,16 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'methods' => array('validate', 'validateStatic'),
|
||||
));
|
||||
|
||||
$this->context->expects($this->at(0))
|
||||
->method('addViolation')
|
||||
->with('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
$this->context->expects($this->at(1))
|
||||
->method('addViolation')
|
||||
->with('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolations(array(
|
||||
$this->createViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
)),
|
||||
$this->createViolation('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -289,13 +257,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array(__CLASS__.'_Class', 'validateCallback')
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -306,13 +272,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'methods' => array(array(__CLASS__.'_Class', 'validateCallback')),
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\CardScheme;
|
||||
use Symfony\Component\Validator\Constraints\CardSchemeValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class CardSchemeValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class CardSchemeValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new CardSchemeValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new CardSchemeValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new CardScheme(array('schemes' => array())));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new CardScheme(array('schemes' => array())));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,10 +46,9 @@ class CardSchemeValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidNumbers($scheme, $number)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($number, new CardScheme(array('schemes' => $scheme)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,10 +56,14 @@ class CardSchemeValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidNumbers($scheme, $number)
|
||||
{
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation');
|
||||
$constraint = new CardScheme(array(
|
||||
'schemes' => $scheme,
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($number, new CardScheme(array('schemes' => $scheme)));
|
||||
$this->validator->validate($number, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array());
|
||||
}
|
||||
|
||||
public function getValidNumbers()
|
||||
|
@ -13,39 +13,30 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\ChoiceValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
function choice_callback()
|
||||
{
|
||||
return array('foo', 'bar');
|
||||
}
|
||||
|
||||
class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new ChoiceValidator();
|
||||
}
|
||||
|
||||
public static function staticCallback()
|
||||
{
|
||||
return array('foo', 'bar');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new ChoiceValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue(__CLASS__));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
||||
*/
|
||||
@ -61,10 +52,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Choice(array('choices' => array('foo', 'bar'))));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,20 +77,18 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$constraint = new Choice(array('choices' => array('foo', 'bar')));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('bar', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidChoiceCallbackFunction()
|
||||
{
|
||||
$constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback'));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('bar', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidChoiceCallbackClosure()
|
||||
@ -109,30 +97,30 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
return array('foo', 'bar');
|
||||
}));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('bar', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidChoiceCallbackStaticMethod()
|
||||
{
|
||||
$constraint = new Choice(array('callback' => array(__CLASS__, 'staticCallback')));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('bar', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidChoiceCallbackContextMethod()
|
||||
{
|
||||
// search $this for "staticCallback"
|
||||
$this->setObject($this);
|
||||
|
||||
$constraint = new Choice(array('callback' => 'staticCallback'));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('bar', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testMultipleChoices()
|
||||
@ -142,10 +130,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'multiple' => true,
|
||||
));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(array('baz', 'bar'), $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testInvalidChoice()
|
||||
@ -155,13 +142,11 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => 'baz',
|
||||
), null, null);
|
||||
|
||||
$this->validator->validate('baz', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 'baz',
|
||||
));
|
||||
}
|
||||
|
||||
public function testInvalidChoiceMultiple()
|
||||
@ -172,13 +157,11 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'multiple' => true,
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => 'baz',
|
||||
));
|
||||
|
||||
$this->validator->validate(array('foo', 'baz'), $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 'baz',
|
||||
));
|
||||
}
|
||||
|
||||
public function testTooFewChoices()
|
||||
@ -190,13 +173,15 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'minMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ limit }}' => 2,
|
||||
), null, 2);
|
||||
$value = array('foo');
|
||||
|
||||
$this->validator->validate(array('foo'), $constraint);
|
||||
$this->setValue($value);
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ limit }}' => 2,
|
||||
), 'property.path', $value, 2);
|
||||
}
|
||||
|
||||
public function testTooManyChoices()
|
||||
@ -208,13 +193,15 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ limit }}' => 2,
|
||||
), null, 2);
|
||||
$value = array('foo', 'bar', 'moo');
|
||||
|
||||
$this->validator->validate(array('foo', 'bar', 'moo'), $constraint);
|
||||
$this->setValue($value);
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ limit }}' => 2,
|
||||
), 'property.path', $value, 2);
|
||||
}
|
||||
|
||||
public function testNonStrict()
|
||||
@ -224,11 +211,10 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'strict' => false,
|
||||
));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('2', $constraint);
|
||||
$this->validator->validate(2, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testStrictAllowsExactValue()
|
||||
@ -238,10 +224,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'strict' => true,
|
||||
));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(2, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testStrictDisallowsDifferentType()
|
||||
@ -252,13 +237,11 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => '2',
|
||||
));
|
||||
|
||||
$this->validator->validate('2', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '2',
|
||||
));
|
||||
}
|
||||
|
||||
public function testNonStrictWithMultipleChoices()
|
||||
@ -269,10 +252,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'strict' => false
|
||||
));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(array('2', 3), $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testStrictWithMultipleChoices()
|
||||
@ -284,12 +266,10 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'multipleMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => '3',
|
||||
));
|
||||
|
||||
$this->validator->validate(array(2, '3'), $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '3',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -11,63 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
/**
|
||||
* This class is a hand written simplified version of PHP native `ArrayObject`
|
||||
* class, to show that it behaves differently than the PHP native implementation.
|
||||
*/
|
||||
class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable
|
||||
{
|
||||
private $array;
|
||||
|
||||
public function __construct(array $array = null)
|
||||
{
|
||||
$this->array = $array ?: array();
|
||||
}
|
||||
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists($offset, $this->array);
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->array[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
if (null === $offset) {
|
||||
$this->array[] = $value;
|
||||
} else {
|
||||
$this->array[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->array[$offset]);
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->array);
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->array);
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return serialize($this->array);
|
||||
}
|
||||
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$this->array = (array) unserialize((string) $serialized);
|
||||
}
|
||||
}
|
||||
use Symfony\Component\Validator\Tests\Fixtures\CustomArrayObject;
|
||||
|
||||
class CollectionValidatorCustomArrayObjectTest extends CollectionValidatorTest
|
||||
{
|
||||
|
@ -17,51 +17,44 @@ use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use Symfony\Component\Validator\Constraints\Optional;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Constraints\Required;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new CollectionValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getGroup')
|
||||
->will($this->returnValue('MyGroup'));
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new CollectionValidator();
|
||||
}
|
||||
|
||||
abstract protected function prepareTestData(array $contents);
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate(null, new Collection(array('fields' => array(
|
||||
'foo' => new Range(array('min' => 4)),
|
||||
))));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testFieldsAsDefaultOption()
|
||||
{
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$data = $this->prepareTestData(array('foo' => 'foobar'));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
$this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Range(array('min' => 4)),
|
||||
'foo' => $constraint,
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,25 +75,23 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'foo' => 3,
|
||||
'bar' => 5,
|
||||
);
|
||||
$i = 1;
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$this->context->expects($this->at($i++))
|
||||
->method('validateValue')
|
||||
->with($value, $constraint, '['.$key.']', 'MyGroup');
|
||||
$this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint), 'MyGroup');
|
||||
}
|
||||
|
||||
$data = $this->prepareTestData($array);
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => $constraint,
|
||||
'bar' => $constraint,
|
||||
),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testWalkMultipleConstraints()
|
||||
@ -114,48 +105,46 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'foo' => 3,
|
||||
'bar' => 5,
|
||||
);
|
||||
$i = 1;
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->context->expects($this->at($i++))
|
||||
->method('validateValue')
|
||||
->with($value, $constraint, '['.$key.']', 'MyGroup');
|
||||
}
|
||||
$this->expectValidateValueAt($i++, '['.$key.']', $value, $constraints, 'MyGroup');
|
||||
}
|
||||
|
||||
$data = $this->prepareTestData($array);
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => $constraints,
|
||||
'bar' => $constraints,
|
||||
)
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testExtraFieldsDisallowed()
|
||||
{
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$data = $this->prepareTestData(array(
|
||||
'foo' => 5,
|
||||
'baz' => 6,
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolationAt')
|
||||
->with('[baz]', 'myMessage', array(
|
||||
'{{ field }}' => 'baz'
|
||||
));
|
||||
$this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => new Range(array('min' => 4)),
|
||||
'foo' => $constraint,
|
||||
),
|
||||
'extraFieldsMessage' => 'myMessage',
|
||||
)));
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ field }}' => 'baz'
|
||||
), 'property.path[baz]', 6);
|
||||
}
|
||||
|
||||
// bug fix
|
||||
@ -165,16 +154,17 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'foo' => null,
|
||||
));
|
||||
|
||||
$constraint = new Collection(array(
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => new Range(array('min' => 4)),
|
||||
'foo' => $constraint,
|
||||
),
|
||||
));
|
||||
)));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, $constraint);
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testExtraFieldsAllowed()
|
||||
@ -184,54 +174,52 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'bar' => 6,
|
||||
));
|
||||
|
||||
$constraint = new Collection(array(
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => new Range(array('min' => 4)),
|
||||
'foo' => $constraint,
|
||||
),
|
||||
'allowExtraFields' => true,
|
||||
));
|
||||
)));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, $constraint);
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testMissingFieldsDisallowed()
|
||||
{
|
||||
$data = $this->prepareTestData(array());
|
||||
|
||||
$constraint = new Collection(array(
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => new Range(array('min' => 4)),
|
||||
'foo' => $constraint,
|
||||
),
|
||||
'missingFieldsMessage' => 'myMessage',
|
||||
));
|
||||
)));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolationAt')
|
||||
->with('[foo]', 'myMessage', array(
|
||||
'{{ field }}' => 'foo',
|
||||
));
|
||||
|
||||
$this->validator->validate($data, $constraint);
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ field }}' => 'foo'
|
||||
), 'property.path[foo]', null);
|
||||
}
|
||||
|
||||
public function testMissingFieldsAllowed()
|
||||
{
|
||||
$data = $this->prepareTestData(array());
|
||||
|
||||
$constraint = new Collection(array(
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => new Range(array('min' => 4)),
|
||||
'foo' => $constraint,
|
||||
),
|
||||
'allowMissingFields' => true,
|
||||
));
|
||||
)));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, $constraint);
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testOptionalFieldPresent()
|
||||
@ -240,24 +228,22 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'foo' => null,
|
||||
));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Optional(),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testOptionalFieldNotPresent()
|
||||
{
|
||||
$data = $this->prepareTestData(array());
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Optional(),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testOptionalFieldSingleConstraint()
|
||||
@ -268,18 +254,15 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('validateValue')
|
||||
->with($array['foo'], $constraint, '[foo]', 'MyGroup');
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
$this->expectValidateValueAt(0, '[foo]', $array['foo'], array($constraint), 'MyGroup');
|
||||
|
||||
$data = $this->prepareTestData($array);
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Optional($constraint),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testOptionalFieldMultipleConstraints()
|
||||
@ -292,22 +275,16 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
new NotNull(),
|
||||
new Range(array('min' => 4)),
|
||||
);
|
||||
$i = 1;
|
||||
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->context->expects($this->at($i++))
|
||||
->method('validateValue')
|
||||
->with($array['foo'], $constraint, '[foo]', 'MyGroup');
|
||||
}
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
$this->expectValidateValueAt(0, '[foo]', $array['foo'], $constraints, 'MyGroup');
|
||||
|
||||
$data = $this->prepareTestData($array);
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Optional($constraints),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testRequiredFieldPresent()
|
||||
@ -316,30 +293,27 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'foo' => null,
|
||||
));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Required(),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testRequiredFieldNotPresent()
|
||||
{
|
||||
$data = $this->prepareTestData(array());
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolationAt')
|
||||
->with('[foo]', 'myMessage', array(
|
||||
'{{ field }}' => 'foo',
|
||||
));
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => new Required(),
|
||||
),
|
||||
'missingFieldsMessage' => 'myMessage',
|
||||
)));
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ field }}' => 'foo'
|
||||
), 'property.path[foo]', null);
|
||||
}
|
||||
|
||||
public function testRequiredFieldSingleConstraint()
|
||||
@ -350,18 +324,15 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$constraint = new Range(array('min' => 4));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('validateValue')
|
||||
->with($array['foo'], $constraint, '[foo]', 'MyGroup');
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
$this->expectValidateValueAt(0, '[foo]', $array['foo'], array($constraint), 'MyGroup');
|
||||
|
||||
$data = $this->prepareTestData($array);
|
||||
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Required($constraint),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testRequiredFieldMultipleConstraints()
|
||||
@ -374,22 +345,16 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
new NotNull(),
|
||||
new Range(array('min' => 4)),
|
||||
);
|
||||
$i = 1;
|
||||
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->context->expects($this->at($i++))
|
||||
->method('validateValue')
|
||||
->with($array['foo'], $constraint, '[foo]', 'MyGroup');
|
||||
}
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolationAt');
|
||||
$this->expectValidateValueAt(0, '[foo]', $array['foo'], $constraints, 'MyGroup');
|
||||
|
||||
$data = $this->prepareTestData($array);
|
||||
|
||||
$this->validator->validate($array, new Collection(array(
|
||||
$this->validator->validate($data, new Collection(array(
|
||||
'foo' => new Required($constraints),
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testObjectShouldBeLeftUnchanged()
|
||||
@ -398,9 +363,13 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'foo' => 3
|
||||
));
|
||||
|
||||
$constraint = new Range(array('min' => 2));
|
||||
|
||||
$this->expectValidateValueAt(0, '[foo]', $value['foo'], array($constraint), 'MyGroup');
|
||||
|
||||
$this->validator->validate($value, new Collection(array(
|
||||
'fields' => array(
|
||||
'foo' => new Range(array('min' => 2)),
|
||||
'foo' => $constraint,
|
||||
)
|
||||
)));
|
||||
|
||||
|
@ -11,20 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
class CountValidatorCountableTest_Countable implements \Countable
|
||||
{
|
||||
private $content;
|
||||
|
||||
public function __construct(array $content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->content);
|
||||
}
|
||||
}
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Countable;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
@ -33,6 +20,6 @@ class CountValidatorCountableTest extends CountValidatorTest
|
||||
{
|
||||
protected function createCollection(array $content)
|
||||
{
|
||||
return new CountValidatorCountableTest_Countable($content);
|
||||
return new Countable($content);
|
||||
}
|
||||
}
|
||||
|
@ -13,36 +13,30 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Count;
|
||||
use Symfony\Component\Validator\Constraints\CountValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
abstract class CountValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new CountValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new CountValidator();
|
||||
}
|
||||
|
||||
abstract protected function createCollection(array $content);
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Count(6));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,11 +87,10 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidValuesMax($value)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$constraint = new Count(array('max' => 3));
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,11 +98,10 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidValuesMin($value)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$constraint = new Count(array('min' => 5));
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,11 +109,10 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidValuesExact($value)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$constraint = new Count(4);
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,14 +125,12 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxMessage' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', $this->identicalTo(array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
)), $value, 4);
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,14 +143,12 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'minMessage' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', $this->identicalTo(array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
)), $value, 4);
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,14 +162,12 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'exactMessage' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', $this->identicalTo(array(
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
)), $value, 4);
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
), 'property.path', $value, 4);
|
||||
}
|
||||
|
||||
public function testDefaultOption()
|
||||
|
@ -14,41 +14,39 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
use Symfony\Component\Validator\Constraints\Country;
|
||||
use Symfony\Component\Validator\Constraints\CountryValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class CountryValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class CountryValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new CountryValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new CountryValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Country());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Country());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,10 +62,9 @@ class CountryValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidCountries($country)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($country, new Country());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidCountries()
|
||||
@ -88,13 +85,11 @@ class CountryValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $country,
|
||||
));
|
||||
|
||||
$this->validator->validate($country, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $country,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidCountries()
|
||||
@ -113,9 +108,9 @@ class CountryValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
\Locale::setDefault('en_GB');
|
||||
|
||||
$existingCountry = 'GB';
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($existingCountry, new Country());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
}
|
||||
|
@ -14,41 +14,39 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
use Symfony\Component\Validator\Constraints\Currency;
|
||||
use Symfony\Component\Validator\Constraints\CurrencyValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class CurrencyValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new CurrencyValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new CurrencyValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Currency());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Currency());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,10 +62,9 @@ class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidCurrencies($currency)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($currency, new Currency());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,10 +73,10 @@ class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testValidCurrenciesWithCountrySpecificLocale($currency)
|
||||
{
|
||||
\Locale::setDefault('en_GB');
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($currency, new Currency());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidCurrencies()
|
||||
@ -102,13 +99,11 @@ class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $currency,
|
||||
));
|
||||
|
||||
$this->validator->validate($currency, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $currency,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidCurrencies()
|
||||
|
@ -13,47 +13,39 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\DateTime;
|
||||
use Symfony\Component\Validator\Constraints\DateTimeValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class DateTimeValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new DateTimeValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new DateTimeValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new DateTime());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new DateTime());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testDateTimeClassIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(new \DateTime(), new DateTime());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,10 +61,9 @@ class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidDateTimes($dateTime)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($dateTime, new DateTime());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidDateTimes()
|
||||
@ -93,13 +84,11 @@ class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $dateTime,
|
||||
));
|
||||
|
||||
$this->validator->validate($dateTime, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $dateTime,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidDateTimes()
|
||||
|
@ -13,47 +13,39 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Date;
|
||||
use Symfony\Component\Validator\Constraints\DateValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class DateValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class DateValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new DateValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new DateValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Date());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Date());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testDateTimeClassIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(new \DateTime(), new Date());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,10 +61,9 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidDates($date)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($date, new Date());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidDates()
|
||||
@ -93,13 +84,11 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $date,
|
||||
));
|
||||
|
||||
$this->validator->validate($date, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $date,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidDates()
|
||||
|
@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\EmailValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class EmailValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new EmailValidator(false);
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new EmailValidator(false);
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Email());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Email());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,10 +54,9 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidEmails($email)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($email, new Email());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidEmails()
|
||||
@ -85,13 +77,11 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $email,
|
||||
));
|
||||
|
||||
$this->validator->validate($email, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $email,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidEmails()
|
||||
@ -105,9 +95,10 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testStrict()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
$constraint = new Email(array('strict' => true));
|
||||
|
||||
$this->validator->validate('example@localhost', new Email(array('strict' => true)));
|
||||
$this->validator->validate('example@localhost', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\EqualTo;
|
||||
use Symfony\Component\Validator\Constraints\EqualToValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @author Daniel Holmes <daniel@danielholmes.org>
|
||||
*/
|
||||
class EqualToValidatorTest extends AbstractComparisonValidatorTestCase
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new EqualToValidator();
|
||||
|
@ -14,185 +14,140 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\Validator\Constraints\Expression;
|
||||
use Symfony\Component\Validator\Constraints\ExpressionValidator;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class ExpressionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class ExpressionValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new ExpressionValidator(PropertyAccess::createPropertyAccessor());
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue(__CLASS__));
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new ExpressionValidator(PropertyAccess::createPropertyAccessor());
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Expression('value == 1'));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Expression('value == 1'));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testSucceedingExpressionAtObjectLevel()
|
||||
{
|
||||
$constraint = new Expression('this.property == 1');
|
||||
$constraint = new Expression('this.data == 1');
|
||||
|
||||
$object = (object) array('property' => '1');
|
||||
$object = new Entity();
|
||||
$object->data = '1';
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyName')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
$this->setObject($object);
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testFailingExpressionAtObjectLevel()
|
||||
{
|
||||
$constraint = new Expression(array(
|
||||
'expression' => 'this.property == 1',
|
||||
'expression' => 'this.data == 1',
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$object = (object) array('property' => '2');
|
||||
$object = new Entity();
|
||||
$object->data = '2';
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyName')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage');
|
||||
$this->setObject($object);
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
|
||||
public function testSucceedingExpressionAtPropertyLevel()
|
||||
{
|
||||
$constraint = new Expression('value == this.expected');
|
||||
$constraint = new Expression('value == this.data');
|
||||
|
||||
$object = (object) array('expected' => '1');
|
||||
$object = new Entity();
|
||||
$object->data = '1';
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyName')
|
||||
->will($this->returnValue('property'));
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyPath')
|
||||
->will($this->returnValue('property'));
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getRoot')
|
||||
->will($this->returnValue($object));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
$this->setRoot($object);
|
||||
$this->setPropertyPath('data');
|
||||
$this->setProperty($object, 'data');
|
||||
|
||||
$this->validator->validate('1', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testFailingExpressionAtPropertyLevel()
|
||||
{
|
||||
$constraint = new Expression(array(
|
||||
'expression' => 'value == this.expected',
|
||||
'expression' => 'value == this.data',
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$object = (object) array('expected' => '1');
|
||||
$object = new Entity();
|
||||
$object->data = '1';
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyName')
|
||||
->will($this->returnValue('property'));
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyPath')
|
||||
->will($this->returnValue('property'));
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getRoot')
|
||||
->will($this->returnValue($object));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage');
|
||||
$this->setRoot($object);
|
||||
$this->setPropertyPath('data');
|
||||
$this->setProperty($object, 'data');
|
||||
|
||||
$this->validator->validate('2', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(), 'data');
|
||||
}
|
||||
|
||||
public function testSucceedingExpressionAtNestedPropertyLevel()
|
||||
{
|
||||
$constraint = new Expression('value == this.expected');
|
||||
$constraint = new Expression('value == this.data');
|
||||
|
||||
$object = (object) array('expected' => '1');
|
||||
$root = (object) array('nested' => $object);
|
||||
$object = new Entity();
|
||||
$object->data = '1';
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyName')
|
||||
->will($this->returnValue('property'));
|
||||
$root = new Entity();
|
||||
$root->reference = $object;
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyPath')
|
||||
->will($this->returnValue('nested.property'));
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getRoot')
|
||||
->will($this->returnValue($root));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
$this->setRoot($root);
|
||||
$this->setPropertyPath('reference.data');
|
||||
$this->setProperty($object, 'data');
|
||||
|
||||
$this->validator->validate('1', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testFailingExpressionAtNestedPropertyLevel()
|
||||
{
|
||||
$constraint = new Expression(array(
|
||||
'expression' => 'value == this.expected',
|
||||
'expression' => 'value == this.data',
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$object = (object) array('expected' => '1');
|
||||
$root = (object) array('nested' => $object);
|
||||
$object = new Entity();
|
||||
$object->data = '1';
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyName')
|
||||
->will($this->returnValue('property'));
|
||||
$root = new Entity();
|
||||
$root->reference = $object;
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getPropertyPath')
|
||||
->will($this->returnValue('nested.property'));
|
||||
|
||||
$this->context->expects($this->any())
|
||||
->method('getRoot')
|
||||
->will($this->returnValue($root));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage');
|
||||
$this->setRoot($root);
|
||||
$this->setPropertyPath('reference.data');
|
||||
$this->setProperty($object, 'data');
|
||||
|
||||
$this->validator->validate('2', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(), 'reference.data');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\False;
|
||||
use Symfony\Component\Validator\Constraints\FalseValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class FalseValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class FalseValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new FalseValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new FalseValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new False());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testFalseIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(false, new False());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testTrueIsInvalid()
|
||||
@ -54,10 +47,8 @@ class FalseValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array());
|
||||
|
||||
$this->validator->validate(true, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,10 @@ class FileValidatorPathTest extends FileValidatorTest
|
||||
'notFoundMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ file }}' => 'foobar',
|
||||
));
|
||||
|
||||
$this->validator->validate('foobar', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ file }}' => 'foobar',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -14,25 +14,36 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\Validator\Constraints\File;
|
||||
use Symfony\Component\Validator\Constraints\FileValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
protected $path;
|
||||
|
||||
protected $file;
|
||||
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new FileValidator();
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new FileValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
parent::setUp();
|
||||
|
||||
$this->path = sys_get_temp_dir().DIRECTORY_SEPARATOR.'FileValidatorTest';
|
||||
$this->file = fopen($this->path, 'w');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
if (is_resource($this->file)) {
|
||||
fclose($this->file);
|
||||
}
|
||||
@ -41,26 +52,22 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
unlink($this->path);
|
||||
}
|
||||
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
$this->path = null;
|
||||
$this->file = null;
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new File());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new File());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,19 +80,17 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testValidFile()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($this->path, new File());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidUploadedfile()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$file = new UploadedFile($this->path, 'originalName', null, null, null, true);
|
||||
$this->validator->validate($file, new File());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function provideMaxSizeExceededTests()
|
||||
@ -137,16 +142,14 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxSizeMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ limit }}' => $limitAsString,
|
||||
'{{ size }}' => $sizeAsString,
|
||||
'{{ suffix }}' => $suffix,
|
||||
'{{ file }}' => $this->path,
|
||||
));
|
||||
|
||||
$this->validator->validate($this->getFile($this->path), $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ limit }}' => $limitAsString,
|
||||
'{{ size }}' => $sizeAsString,
|
||||
'{{ suffix }}' => $suffix,
|
||||
'{{ file }}' => $this->path,
|
||||
));
|
||||
}
|
||||
|
||||
public function provideMaxSizeNotExceededTests()
|
||||
@ -177,10 +180,9 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxSizeMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($this->getFile($this->path), $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,14 +215,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue('image/jpg'))
|
||||
;
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$constraint = new File(array(
|
||||
'mimeTypes' => array('image/png', 'image/jpg'),
|
||||
));
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidWildcardMimeType()
|
||||
@ -241,14 +242,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue('image/jpg'))
|
||||
;
|
||||
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$constraint = new File(array(
|
||||
'mimeTypes' => array('image/*'),
|
||||
));
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testInvalidMimeType()
|
||||
@ -274,15 +274,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'mimeTypesMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ type }}' => '"application/pdf"',
|
||||
'{{ types }}' => '"image/png", "image/jpg"',
|
||||
'{{ file }}' => $this->path,
|
||||
));
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ type }}' => '"application/pdf"',
|
||||
'{{ types }}' => '"image/png", "image/jpg"',
|
||||
'{{ file }}' => $this->path,
|
||||
));
|
||||
}
|
||||
|
||||
public function testInvalidWildcardMimeType()
|
||||
@ -308,15 +306,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'mimeTypesMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ type }}' => '"application/pdf"',
|
||||
'{{ types }}' => '"image/*", "image/jpg"',
|
||||
'{{ file }}' => $this->path,
|
||||
));
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ type }}' => '"application/pdf"',
|
||||
'{{ types }}' => '"image/*", "image/jpg"',
|
||||
'{{ file }}' => $this->path,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -331,12 +327,10 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxSize' => $maxSize
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', $params);
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', $params);
|
||||
|
||||
}
|
||||
|
||||
public function uploadedFileErrorProvider()
|
||||
|
@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqualValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @author Daniel Holmes <daniel@danielholmes.org>
|
||||
*/
|
||||
class GreaterThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCase
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new GreaterThanOrEqualValidator();
|
||||
|
@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @author Daniel Holmes <daniel@danielholmes.org>
|
||||
*/
|
||||
class GreaterThanValidatorTest extends AbstractComparisonValidatorTestCase
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new GreaterThanValidator();
|
||||
|
@ -13,31 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Iban;
|
||||
use Symfony\Component\Validator\Constraints\IbanValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class IbanValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class IbanValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new IbanValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new IbanValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Iban());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Iban());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,9 +46,9 @@ class IbanValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidIbans($iban)
|
||||
{
|
||||
$this->context->expects($this->never())->method('addViolation');
|
||||
|
||||
$this->validator->validate($iban, new Iban());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidIbans()
|
||||
@ -160,13 +161,11 @@ class IbanValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $iban,
|
||||
));
|
||||
|
||||
$this->validator->validate($iban, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $iban,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidIbans()
|
||||
|
@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\IdenticalTo;
|
||||
use Symfony\Component\Validator\Constraints\IdenticalToValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @author Daniel Holmes <daniel@danielholmes.org>
|
||||
*/
|
||||
class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new IdenticalToValidator();
|
||||
|
@ -13,8 +13,9 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Image;
|
||||
use Symfony\Component\Validator\Constraints\ImageValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class ImageValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
@ -23,11 +24,20 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
protected $imageLandscape;
|
||||
protected $imagePortrait;
|
||||
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new ImageValidator();
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new ImageValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
parent::setUp();
|
||||
|
||||
$this->image = __DIR__.'/Fixtures/test.gif';
|
||||
$this->imageLandscape = __DIR__.'/Fixtures/test_landscape.gif';
|
||||
$this->imagePortrait = __DIR__.'/Fixtures/test_portrait.gif';
|
||||
@ -35,33 +45,27 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Image());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Image());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidImage()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($this->image, new Image());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidSize()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$constraint = new Image(array(
|
||||
'minWidth' => 1,
|
||||
'maxWidth' => 2,
|
||||
@ -70,6 +74,8 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testWidthTooSmall()
|
||||
@ -79,14 +85,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'minWidthMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ width }}' => '2',
|
||||
'{{ min_width }}' => '3',
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ width }}' => '2',
|
||||
'{{ min_width }}' => '3',
|
||||
));
|
||||
}
|
||||
|
||||
public function testWidthTooBig()
|
||||
@ -96,14 +100,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxWidthMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ width }}' => '2',
|
||||
'{{ max_width }}' => '1',
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ width }}' => '2',
|
||||
'{{ max_width }}' => '1',
|
||||
));
|
||||
}
|
||||
|
||||
public function testHeightTooSmall()
|
||||
@ -113,14 +115,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'minHeightMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ height }}' => '2',
|
||||
'{{ min_height }}' => '3',
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ height }}' => '2',
|
||||
'{{ min_height }}' => '3',
|
||||
));
|
||||
}
|
||||
|
||||
public function testHeightTooBig()
|
||||
@ -130,14 +130,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxHeightMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ height }}' => '2',
|
||||
'{{ max_height }}' => '1',
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ height }}' => '2',
|
||||
'{{ max_height }}' => '1',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,14 +193,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'minRatioMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ ratio }}' => 1,
|
||||
'{{ min_ratio }}' => 2,
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ ratio }}' => 1,
|
||||
'{{ min_ratio }}' => 2,
|
||||
));
|
||||
}
|
||||
|
||||
public function testRatioTooBig()
|
||||
@ -212,14 +208,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'maxRatioMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ ratio }}' => 1,
|
||||
'{{ max_ratio }}' => 0.5,
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ ratio }}' => 1,
|
||||
'{{ max_ratio }}' => 0.5,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,14 +247,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'allowSquareMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ width }}' => 2,
|
||||
'{{ height }}' => 2,
|
||||
));
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ width }}' => 2,
|
||||
'{{ height }}' => 2,
|
||||
));
|
||||
}
|
||||
|
||||
public function testLandscapeNotAllowed()
|
||||
@ -270,14 +262,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'allowLandscapeMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ width }}' => 2,
|
||||
'{{ height }}' => 1,
|
||||
));
|
||||
|
||||
$this->validator->validate($this->imageLandscape, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ width }}' => 2,
|
||||
'{{ height }}' => 1,
|
||||
));
|
||||
}
|
||||
|
||||
public function testPortraitNotAllowed()
|
||||
@ -287,13 +277,11 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'allowPortraitMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ width }}' => 1,
|
||||
'{{ height }}' => 2,
|
||||
));
|
||||
|
||||
$this->validator->validate($this->imagePortrait, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ width }}' => 1,
|
||||
'{{ height }}' => 2,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Ip;
|
||||
use Symfony\Component\Validator\Constraints\IpValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new IpValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
protected function createValidator()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
return new IpValidator();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Ip());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Ip());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +54,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidValidatorVersion()
|
||||
{
|
||||
$ip = new Ip(array(
|
||||
new Ip(array(
|
||||
'version' => 666,
|
||||
));
|
||||
}
|
||||
@ -71,12 +64,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidIpsV4($ip)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($ip, new Ip(array(
|
||||
'version' => Ip::V4,
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidIpsV4()
|
||||
@ -98,12 +90,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidIpsV6($ip)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($ip, new Ip(array(
|
||||
'version' => Ip::V6,
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidIpsV6()
|
||||
@ -136,12 +127,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidIpsAll($ip)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($ip, new Ip(array(
|
||||
'version' => Ip::ALL,
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidIpsAll()
|
||||
@ -159,13 +149,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidIpsV4()
|
||||
@ -193,13 +181,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidPrivateIpsV4()
|
||||
@ -221,13 +207,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidReservedIpsV4()
|
||||
@ -249,13 +233,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidPublicIpsV4()
|
||||
@ -273,13 +255,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidIpsV6()
|
||||
@ -311,13 +291,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidPrivateIpsV6()
|
||||
@ -339,13 +317,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidReservedIpsV6()
|
||||
@ -366,13 +342,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidPublicIpsV6()
|
||||
@ -390,13 +364,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidIpsAll()
|
||||
@ -414,13 +386,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidPrivateIpsAll()
|
||||
@ -438,13 +408,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidReservedIpsAll()
|
||||
@ -462,13 +430,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $ip,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidPublicIpsAll()
|
||||
|
@ -13,20 +13,21 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Isbn;
|
||||
use Symfony\Component\Validator\Constraints\IsbnValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/Isbn
|
||||
*/
|
||||
class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
public function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new IsbnValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new IsbnValidator();
|
||||
}
|
||||
|
||||
public function getValidIsbn10()
|
||||
@ -116,21 +117,19 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$constraint = new Isbn(true);
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$constraint = new Isbn(true);
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,6 +138,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testExpectsStringCompatibleType()
|
||||
{
|
||||
$constraint = new Isbn(true);
|
||||
|
||||
$this->validator->validate(new \stdClass(), $constraint);
|
||||
}
|
||||
|
||||
@ -147,12 +147,13 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidIsbn10($isbn)
|
||||
{
|
||||
$constraint = new Isbn(array('type' => 'isbn10'));
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
$constraint = new Isbn(array(
|
||||
'type' => 'isbn10'
|
||||
));
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,13 +161,14 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidIsbn10($isbn)
|
||||
{
|
||||
$constraint = new Isbn(array('type' => 'isbn10'));
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->isbn10Message);
|
||||
$constraint = new Isbn(array(
|
||||
'type' => 'isbn10',
|
||||
'isbn10Message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,11 +177,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testValidIsbn13($isbn)
|
||||
{
|
||||
$constraint = new Isbn(array('type' => 'isbn13'));
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,13 +188,14 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidIsbn13($isbn)
|
||||
{
|
||||
$constraint = new Isbn(array('type' => 'isbn13'));
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->isbn13Message);
|
||||
$constraint = new Isbn(array(
|
||||
'type' => 'isbn13',
|
||||
'isbn13Message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,11 +204,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testValidIsbn($isbn)
|
||||
{
|
||||
$constraint = new Isbn();
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,12 +215,12 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidIsbn($isbn)
|
||||
{
|
||||
$constraint = new Isbn();
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->bothIsbnMessage);
|
||||
$constraint = new Isbn(array(
|
||||
'bothIsbnMessage' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
}
|
||||
|
@ -13,20 +13,21 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Issn;
|
||||
use Symfony\Component\Validator\Constraints\IssnValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/Issn
|
||||
*/
|
||||
class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class IssnValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
public function setUp()
|
||||
protected function getApiVersion()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new IssnValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new IssnValidator();
|
||||
}
|
||||
|
||||
public function getValidLowerCasedIssn()
|
||||
@ -110,21 +111,19 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$constraint = new Issn();
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$constraint = new Issn();
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,13 +140,14 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testCaseSensitiveIssns($issn)
|
||||
{
|
||||
$constraint = new Issn(array('caseSensitive' => true));
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->message);
|
||||
$constraint = new Issn(array(
|
||||
'caseSensitive' => true,
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,13 +155,14 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testRequireHyphenIssns($issn)
|
||||
{
|
||||
$constraint = new Issn(array('requireHyphen' => true));
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->message);
|
||||
$constraint = new Issn(array(
|
||||
'requireHyphen' => true,
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,11 +171,10 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testValidIssn($issn)
|
||||
{
|
||||
$constraint = new Issn();
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,13 +182,13 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidFormatIssn($issn)
|
||||
{
|
||||
$constraint = new Issn();
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->message);
|
||||
$constraint = new Issn(array(
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,13 +196,13 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidValueIssn($issn)
|
||||
{
|
||||
$constraint = new Issn();
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->message);
|
||||
$constraint = new Issn(array(
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,11 +210,12 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidIssn($issn)
|
||||
{
|
||||
$constraint = new Issn();
|
||||
$this->context
|
||||
->expects($this->once())
|
||||
->method('addViolation');
|
||||
$constraint = new Issn(array(
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
}
|
||||
}
|
||||
|
@ -14,41 +14,39 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
use Symfony\Component\Validator\Constraints\Language;
|
||||
use Symfony\Component\Validator\Constraints\LanguageValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class LanguageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
class LanguageValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LanguageValidator();
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireFullIntl($this);
|
||||
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new LanguageValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new Language());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Language());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,10 +62,9 @@ class LanguageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidLanguages($language)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($language, new Language());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getValidLanguages()
|
||||
@ -88,13 +85,11 @@ class LanguageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'myMessage'
|
||||
));
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $language,
|
||||
));
|
||||
|
||||
$this->validator->validate($language, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $language,
|
||||
));
|
||||
}
|
||||
|
||||
public function getInvalidLanguages()
|
||||
@ -109,11 +104,11 @@ class LanguageValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
\Locale::setDefault('fr_FR');
|
||||
$existingLanguage = 'en';
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($existingLanguage, new Language(array(
|
||||
'message' => 'aMessage'
|
||||
)));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\LegacyAllValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyAllValidator2Dot4ApiTest extends AllValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LegacyAllValidator();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyAllValidatorLegacyApiTest extends AllValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyBlankValidator2Dot4ApiTest extends BlankValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyBlankValidatorLegacyApiTest extends BlankValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCallbackValidator2Dot4ApiTest extends CallbackValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCallbackValidatorLegacyApiTest extends CallbackValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCardSchemeValidator2Dot4ApiTest extends CardSchemeValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCardSchemeValidatorLegacyApiTest extends CardSchemeValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\LegacyChoiceValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyChoiceValidator2Dot4ApiTest extends ChoiceValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LegacyChoiceValidator();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyChoiceValidatorLegacyApiTest extends ChoiceValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\LegacyCollectionValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class LegacyCollectionValidatorArray2Dot4ApiTest extends CollectionValidatorArrayTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LegacyCollectionValidator();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class LegacyCollectionValidatorArrayLegacyApiTest extends CollectionValidatorArrayTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\LegacyCollectionValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class LegacyCollectionValidatorArrayObject2Dot4ApiTest extends CollectionValidatorArrayObjectTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LegacyCollectionValidator();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class LegacyCollectionValidatorArrayObjectLegacyApiTest extends CollectionValidatorArrayObjectTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\LegacyCollectionValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class LegacyCollectionValidatorCustomArrayObject2Dot4ApiTest extends CollectionValidatorCustomArrayObjectTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LegacyCollectionValidator();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class LegacyCollectionValidatorCustomArrayObjectLegacyApiTest extends CollectionValidatorCustomArrayObjectTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\LegacyCountValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCountValidatorArray2Dot4ApiTest extends CountValidatorArrayTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LegacyCountValidator();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCountValidatorArrayLegacyApiTest extends CountValidatorArrayTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\LegacyCountValidator;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCountValidatorCountable2Dot4ApiTest extends CountValidatorCountableTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new LegacyCountValidator();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCountValidatorCountableLegacyApiTest extends CountValidatorCountableTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCurrencyValidator2Dot4ApiTest extends CurrencyValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyCurrencyValidatorLegacyApiTest extends CurrencyValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyDateTimeValidator2Dot4ApiTest extends DateTimeValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyDateTimeValidatorLegacyApiTest extends DateTimeValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyDateValidator2Dot4ApiTest extends DateValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyDateValidatorLegacyApiTest extends DateValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyEmailValidator2Dot4ApiTest extends EmailValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyEmailValidatorLegacyApiTest extends EmailValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyEqualToValidator2Dot4ApiTest extends EqualToValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyEqualToValidatorLegacyApiTest extends EqualToValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyExpressionValidator2Dot4ApiTest extends ExpressionValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyExpressionValidatorLegacyApiTest extends ExpressionValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyFalseValidator2Dot4ApiTest extends FalseValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyFalseValidatorLegacyApiTest extends FalseValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyFileValidatorObject2Dot4ApiTest extends FileValidatorObjectTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyFileValidatorObjectLegacyApiTest extends FileValidatorObjectTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyFileValidatorPath2Dot4ApiTest extends FileValidatorPathTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyFileValidatorPathLegacyApiTest extends FileValidatorPathTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyGreaterThanOrEqualValidator2Dot4ApiTest extends GreaterThanOrEqualValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyGreaterThanOrEqualValidatorLegacyApiTest extends GreaterThanOrEqualValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyGreaterThanValidator2Dot4ApiTest extends GreaterThanValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyGreaterThanValidatorLegacyApiTest extends GreaterThanValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIbanValidator2Dot4ApiTest extends IbanValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIbanValidatorLegacyApiTest extends IbanValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIdenticalToValidator2Dot4ApiTest extends IdenticalToValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIdenticalToValidatorLegacyApiTest extends IdenticalToValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyImageValidator2Dot4ApiTest extends ImageValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyImageValidatorLegacyApiTest extends ImageValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIpValidator2Dot4ApiTest extends IpValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIpValidatorLegacyApiTest extends IpValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIsbnValidator2Dot4ApiTest extends IsbnValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIsbnValidatorLegacyApiTest extends IsbnValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIssnValidator2Dot4ApiTest extends IssnValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyIssnValidatorLegacyApiTest extends IssnValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyLanguageValidator2Dot4ApiTest extends LanguageValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_4;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @since 2.5.3
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LegacyLanguageValidatorLegacyApiTest extends LanguageValidatorTest
|
||||
{
|
||||
protected function getApiVersion()
|
||||
{
|
||||
return Validation::API_VERSION_2_5_BC;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user