This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Components/Validator/Mapping/ElementMetadataTest.php
2010-07-02 08:36:02 +02:00

63 lines
2.0 KiB
PHP

<?php
namespace Symfony\Tests\Components\Validator\Mapping;
require_once __DIR__.'/../Fixtures/ConstraintA.php';
require_once __DIR__.'/../Fixtures/ConstraintB.php';
use Symfony\Tests\Components\Validator\Fixtures\ConstraintA;
use Symfony\Tests\Components\Validator\Fixtures\ConstraintB;
use Symfony\Components\Validator\Mapping\ElementMetadata;
class ElementMetadataTest extends \PHPUnit_Framework_TestCase
{
protected $metadata;
public function setUp()
{
$this->metadata = new TestElementMetadata('Symfony\Tests\Components\Validator\Fixtures\Entity');
}
public function testAddConstraints()
{
$this->metadata->addConstraint($constraint1 = new ConstraintA());
$this->metadata->addConstraint($constraint2 = new ConstraintA());
$this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
}
public function testMultipleConstraintsOfTheSameType()
{
$constraint1 = new ConstraintA(array('property1' => 'A'));
$constraint2 = new ConstraintA(array('property1' => 'B'));
$this->metadata->addConstraint($constraint1);
$this->metadata->addConstraint($constraint2);
$this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
}
public function testFindConstraintsByGroup()
{
$constraint1 = new ConstraintA(array('groups' => 'TestGroup'));
$constraint2 = new ConstraintB();
$this->metadata->addConstraint($constraint1);
$this->metadata->addConstraint($constraint2);
$this->assertEquals(array($constraint1), $this->metadata->findConstraints('TestGroup'));
}
public function testSerialize()
{
$this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
$this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
$metadata = unserialize(serialize($this->metadata));
$this->assertEquals($this->metadata, $metadata);
}
}
class TestElementMetadata extends ElementMetadata {}