Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / AllValidatorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Constraints;
13
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;
19
20 class AllValidatorTest extends ConstraintValidatorTestCase
21 {
22     protected function createValidator()
23     {
24         return new AllValidator();
25     }
26
27     public function testNullIsValid()
28     {
29         $this->validator->validate(null, new All(new Range(array('min' => 4))));
30
31         $this->assertNoViolation();
32     }
33
34     /**
35      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
36      */
37     public function testThrowsExceptionIfNotTraversable()
38     {
39         $this->validator->validate('foo.barbar', new All(new Range(array('min' => 4))));
40     }
41
42     /**
43      * @dataProvider getValidArguments
44      */
45     public function testWalkSingleConstraint($array)
46     {
47         $constraint = new Range(array('min' => 4));
48
49         $i = 0;
50
51         foreach ($array as $key => $value) {
52             $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint));
53         }
54
55         $this->validator->validate($array, new All($constraint));
56
57         $this->assertNoViolation();
58     }
59
60     /**
61      * @dataProvider getValidArguments
62      */
63     public function testWalkMultipleConstraints($array)
64     {
65         $constraint1 = new Range(array('min' => 4));
66         $constraint2 = new NotNull();
67
68         $constraints = array($constraint1, $constraint2);
69
70         $i = 0;
71
72         foreach ($array as $key => $value) {
73             $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint1, $constraint2));
74         }
75
76         $this->validator->validate($array, new All($constraints));
77
78         $this->assertNoViolation();
79     }
80
81     public function getValidArguments()
82     {
83         return array(
84             array(array(5, 6, 7)),
85             array(new \ArrayObject(array(5, 6, 7))),
86         );
87     }
88 }