diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php index 7dc3389939..efdff8197b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php @@ -43,7 +43,7 @@ class ConstraintValidatorFactoryTest extends \PHPUnit_Framework_TestCase { $service = 'validator_constraint_service'; $alias = 'validator_constraint_alias'; - $validator = new \stdClass(); + $validator = $this->getMockForAbstractClass('Symfony\\Component\\Validator\\ConstraintValidator'); // mock ContainerBuilder b/c it implements TaggedContainerInterface $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php b/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php index 86e2f99454..66f0d012d3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php +++ b/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php @@ -14,7 +14,8 @@ namespace Symfony\Bundle\FrameworkBundle\Validator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; -use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\ConstraintValidatorInterface; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * Uses a service container to create constraint validators. @@ -58,7 +59,9 @@ class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface * * @param Constraint $constraint A constraint * - * @return ConstraintValidator A validator for the supplied 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) { @@ -70,6 +73,10 @@ class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface $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]; } }