CollectionTest.php in Plug 7
File
lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php
View source
<?php
namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Constraints\Required;
use Symfony\Component\Validator\Constraints\Valid;
class CollectionTest extends \PHPUnit_Framework_TestCase {
public function testRejectInvalidFieldsOption() {
new Collection(array(
'fields' => 'foo',
));
}
public function testRejectNonConstraints() {
new Collection(array(
'foo' => 'bar',
));
}
public function testRejectValidConstraint() {
new Collection(array(
'foo' => new Valid(),
));
}
public function testRejectValidConstraintWithinOptional() {
new Collection(array(
'foo' => new Optional(new Valid()),
));
}
public function testRejectValidConstraintWithinRequired() {
new Collection(array(
'foo' => new Required(new Valid()),
));
}
public function testAcceptOptionalConstraintAsOneElementArray() {
$collection1 = new Collection(array(
'fields' => array(
'alternate_email' => array(
new Optional(new Email()),
),
),
));
$collection2 = new Collection(array(
'fields' => array(
'alternate_email' => new Optional(new Email()),
),
));
$this
->assertEquals($collection1, $collection2);
}
public function testAcceptRequiredConstraintAsOneElementArray() {
$collection1 = new Collection(array(
'fields' => array(
'alternate_email' => array(
new Required(new Email()),
),
),
));
$collection2 = new Collection(array(
'fields' => array(
'alternate_email' => new Required(new Email()),
),
));
$this
->assertEquals($collection1, $collection2);
}
}