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\Test\ConstraintValidatorTestCase;
20 class AllValidatorTest extends ConstraintValidatorTestCase
22 protected function createValidator()
24 return new AllValidator();
27 public function testNullIsValid()
29 $this->validator->validate(null, new All(new Range(array('min' => 4))));
31 $this->assertNoViolation();
35 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
37 public function testThrowsExceptionIfNotTraversable()
39 $this->validator->validate('foo.barbar', new All(new Range(array('min' => 4))));
43 * @dataProvider getValidArguments
45 public function testWalkSingleConstraint($array)
47 $constraint = new Range(array('min' => 4));
51 foreach ($array as $key => $value) {
52 $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint));
55 $this->validator->validate($array, new All($constraint));
57 $this->assertNoViolation();
61 * @dataProvider getValidArguments
63 public function testWalkMultipleConstraints($array)
65 $constraint1 = new Range(array('min' => 4));
66 $constraint2 = new NotNull();
68 $constraints = array($constraint1, $constraint2);
72 foreach ($array as $key => $value) {
73 $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint1, $constraint2));
76 $this->validator->validate($array, new All($constraints));
78 $this->assertNoViolation();
81 public function getValidArguments()
84 array(array(5, 6, 7)),
85 array(new \ArrayObject(array(5, 6, 7))),