b5fbf6c0b09718e98d3f8c80b2928a07902dffa9
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / CollectionTest.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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Constraints\Collection;
16 use Symfony\Component\Validator\Constraints\Email;
17 use Symfony\Component\Validator\Constraints\Optional;
18 use Symfony\Component\Validator\Constraints\Required;
19 use Symfony\Component\Validator\Constraints\Valid;
20
21 /**
22  * @author Bernhard Schussek <bschussek@gmail.com>
23  */
24 class CollectionTest extends TestCase
25 {
26     /**
27      * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
28      */
29     public function testRejectInvalidFieldsOption()
30     {
31         new Collection(array(
32             'fields' => 'foo',
33         ));
34     }
35
36     /**
37      * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
38      */
39     public function testRejectNonConstraints()
40     {
41         new Collection(array(
42             'foo' => 'bar',
43         ));
44     }
45
46     /**
47      * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
48      */
49     public function testRejectValidConstraint()
50     {
51         new Collection(array(
52             'foo' => new Valid(),
53         ));
54     }
55
56     /**
57      * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
58      */
59     public function testRejectValidConstraintWithinOptional()
60     {
61         new Collection(array(
62             'foo' => new Optional(new Valid()),
63         ));
64     }
65
66     /**
67      * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
68      */
69     public function testRejectValidConstraintWithinRequired()
70     {
71         new Collection(array(
72             'foo' => new Required(new Valid()),
73         ));
74     }
75
76     public function testAcceptOptionalConstraintAsOneElementArray()
77     {
78         $collection1 = new Collection(array(
79             'fields' => array(
80                 'alternate_email' => array(
81                     new Optional(new Email()),
82                 ),
83             ),
84         ));
85
86         $collection2 = new Collection(array(
87             'fields' => array(
88                 'alternate_email' => new Optional(new Email()),
89             ),
90         ));
91
92         $this->assertEquals($collection1, $collection2);
93     }
94
95     public function testAcceptRequiredConstraintAsOneElementArray()
96     {
97         $collection1 = new Collection(array(
98             'fields' => array(
99                 'alternate_email' => array(
100                     new Required(new Email()),
101                 ),
102             ),
103         ));
104
105         $collection2 = new Collection(array(
106             'fields' => array(
107                 'alternate_email' => new Required(new Email()),
108             ),
109         ));
110
111         $this->assertEquals($collection1, $collection2);
112     }
113 }