4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Tests\Constraints;
14 use Symfony\Component\Validator\Constraints\All;
15 use Symfony\Component\Validator\Constraints\AllValidator;
16 use Symfony\Component\Validator\Constraints\NotNull;
17 use Symfony\Component\Validator\Constraints\Range;
18 use Symfony\Component\Validator\Validation;
20 class AllValidatorTest extends AbstractConstraintValidatorTest
22 protected function getApiVersion()
24 return Validation::API_VERSION_2_5;
27 protected function createValidator()
29 return new AllValidator();
32 public function testNullIsValid()
34 $this->validator->validate(null, new All(new Range(array('min' => 4))));
36 $this->assertNoViolation();
40 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
42 public function testThrowsExceptionIfNotTraversable()
44 $this->validator->validate('foo.barbar', new All(new Range(array('min' => 4))));
48 * @dataProvider getValidArguments
50 public function testWalkSingleConstraint($array)
52 $constraint = new Range(array('min' => 4));
56 foreach ($array as $key => $value) {
57 $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint));
60 $this->validator->validate($array, new All($constraint));
62 $this->assertNoViolation();
66 * @dataProvider getValidArguments
68 public function testWalkMultipleConstraints($array)
70 $constraint1 = new Range(array('min' => 4));
71 $constraint2 = new NotNull();
73 $constraints = array($constraint1, $constraint2);
77 foreach ($array as $key => $value) {
78 $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint1, $constraint2));
81 $this->validator->validate($array, new All($constraints));
83 $this->assertNoViolation();
86 public function getValidArguments()
89 array(array(5, 6, 7)),
90 array(new \ArrayObject(array(5, 6, 7))),