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 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;
22 * @author Bernhard Schussek <bschussek@gmail.com>
24 class CollectionTest extends TestCase
27 * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
29 public function testRejectInvalidFieldsOption()
37 * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
39 public function testRejectNonConstraints()
47 * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
49 public function testRejectValidConstraint()
57 * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
59 public function testRejectValidConstraintWithinOptional()
62 'foo' => new Optional(new Valid()),
67 * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
69 public function testRejectValidConstraintWithinRequired()
72 'foo' => new Required(new Valid()),
76 public function testAcceptOptionalConstraintAsOneElementArray()
78 $collection1 = new Collection(array(
80 'alternate_email' => array(
81 new Optional(new Email()),
86 $collection2 = new Collection(array(
88 'alternate_email' => new Optional(new Email()),
92 $this->assertEquals($collection1, $collection2);
95 public function testAcceptRequiredConstraintAsOneElementArray()
97 $collection1 = new Collection(array(
99 'alternate_email' => array(
100 new Required(new Email()),
105 $collection2 = new Collection(array(
107 'alternate_email' => new Required(new Email()),
111 $this->assertEquals($collection1, $collection2);