57dd6006974b0191b696499b6aef19809bfe0a28
[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\Validation;
19
20 class AllValidatorTest extends AbstractConstraintValidatorTest
21 {
22     protected function getApiVersion()
23     {
24         return Validation::API_VERSION_2_5;
25     }
26
27     protected function createValidator()
28     {
29         return new AllValidator();
30     }
31
32     public function testNullIsValid()
33     {
34         $this->validator->validate(null, new All(new Range(array('min' => 4))));
35
36         $this->assertNoViolation();
37     }
38
39     /**
40      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
41      */
42     public function testThrowsExceptionIfNotTraversable()
43     {
44         $this->validator->validate('foo.barbar', new All(new Range(array('min' => 4))));
45     }
46
47     /**
48      * @dataProvider getValidArguments
49      */
50     public function testWalkSingleConstraint($array)
51     {
52         $constraint = new Range(array('min' => 4));
53
54         $i = 0;
55
56         foreach ($array as $key => $value) {
57             $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint));
58         }
59
60         $this->validator->validate($array, new All($constraint));
61
62         $this->assertNoViolation();
63     }
64
65     /**
66      * @dataProvider getValidArguments
67      */
68     public function testWalkMultipleConstraints($array)
69     {
70         $constraint1 = new Range(array('min' => 4));
71         $constraint2 = new NotNull();
72
73         $constraints = array($constraint1, $constraint2);
74
75         $i = 0;
76
77         foreach ($array as $key => $value) {
78             $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint1, $constraint2));
79         }
80
81         $this->validator->validate($array, new All($constraints));
82
83         $this->assertNoViolation();
84     }
85
86     public function getValidArguments()
87     {
88         return array(
89             array(array(5, 6, 7)),
90             array(new \ArrayObject(array(5, 6, 7))),
91         );
92     }
93 }