2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\Validator\Mapping;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
require_once __DIR__.'/../Fixtures/ConstraintA.php';
|
|
|
|
require_once __DIR__.'/../Fixtures/ConstraintB.php';
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Tests\Component\Validator\Fixtures\ConstraintA;
|
|
|
|
use Symfony\Tests\Component\Validator\Fixtures\ConstraintB;
|
|
|
|
use Symfony\Component\Validator\Mapping\ElementMetadata;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
class ElementMetadataTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
protected $metadata;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-12-06 14:45:37 +00:00
|
|
|
protected function setUp()
|
2010-06-24 10:24:08 +01:00
|
|
|
{
|
2010-08-20 22:09:55 +01:00
|
|
|
$this->metadata = new TestElementMetadata('Symfony\Tests\Component\Validator\Fixtures\Entity');
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testAddConstraints()
|
|
|
|
{
|
|
|
|
$this->metadata->addConstraint($constraint1 = new ConstraintA());
|
|
|
|
$this->metadata->addConstraint($constraint2 = new ConstraintA());
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testMultipleConstraintsOfTheSameType()
|
|
|
|
{
|
|
|
|
$constraint1 = new ConstraintA(array('property1' => 'A'));
|
|
|
|
$constraint2 = new ConstraintA(array('property1' => 'B'));
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->metadata->addConstraint($constraint1);
|
|
|
|
$this->metadata->addConstraint($constraint2);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testFindConstraintsByGroup()
|
|
|
|
{
|
|
|
|
$constraint1 = new ConstraintA(array('groups' => 'TestGroup'));
|
|
|
|
$constraint2 = new ConstraintB();
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->metadata->addConstraint($constraint1);
|
|
|
|
$this->metadata->addConstraint($constraint2);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals(array($constraint1), $this->metadata->findConstraints('TestGroup'));
|
|
|
|
}
|
2010-06-29 16:20:29 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|
2010-06-29 16:20:29 +01:00
|
|
|
|
|
|
|
class TestElementMetadata extends ElementMetadata {}
|