2010-06-29 16:20:29 +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-29 16:20:29 +01:00
|
|
|
|
|
|
|
require_once __DIR__.'/../Fixtures/ConstraintA.php';
|
|
|
|
require_once __DIR__.'/../Fixtures/ConstraintB.php';
|
2011-01-19 14:30:43 +00:00
|
|
|
require_once __DIR__.'/../Fixtures/ClassConstraint.php';
|
2010-06-29 16:20:29 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Tests\Component\Validator\Fixtures\ConstraintA;
|
|
|
|
use Symfony\Tests\Component\Validator\Fixtures\ConstraintB;
|
2011-01-19 14:30:43 +00:00
|
|
|
use Symfony\Tests\Component\Validator\Fixtures\ClassConstraint;
|
2010-11-16 22:41:46 +00:00
|
|
|
use Symfony\Component\Validator\Constraints\Valid;
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Validator\Mapping\MemberMetadata;
|
2010-06-29 16:20:29 +01:00
|
|
|
|
|
|
|
class MemberMetadataTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
protected $metadata;
|
|
|
|
|
2010-12-06 14:45:37 +00:00
|
|
|
protected function setUp()
|
2010-06-29 16:20:29 +01:00
|
|
|
{
|
|
|
|
$this->metadata = new TestMemberMetadata(
|
2010-12-13 10:09:41 +00:00
|
|
|
'Symfony\Tests\Component\Validator\Fixtures\Entity',
|
2010-06-29 16:20:29 +01:00
|
|
|
'getLastName',
|
|
|
|
'lastName'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-14 09:44:38 +01:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
$this->metadata = null;
|
|
|
|
}
|
|
|
|
|
2010-11-16 22:41:46 +00:00
|
|
|
public function testAddValidSetsMemberToCascaded()
|
|
|
|
{
|
|
|
|
$result = $this->metadata->addConstraint(new Valid());
|
|
|
|
|
|
|
|
$this->assertEquals(array(), $this->metadata->getConstraints());
|
|
|
|
$this->assertEquals($result, $this->metadata);
|
|
|
|
$this->assertTrue($this->metadata->isCascaded());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddOtherConstraintDoesNotSetMemberToCascaded()
|
|
|
|
{
|
|
|
|
$result = $this->metadata->addConstraint($constraint = new ConstraintA());
|
|
|
|
|
|
|
|
$this->assertEquals(array($constraint), $this->metadata->getConstraints());
|
|
|
|
$this->assertEquals($result, $this->metadata);
|
|
|
|
$this->assertFalse($this->metadata->isCascaded());
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:30:43 +00:00
|
|
|
public function testAddConstraintRequiresClassConstraints()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
|
|
|
|
|
|
|
$this->metadata->addConstraint(new ClassConstraint());
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestMemberMetadata extends MemberMetadata
|
|
|
|
{
|
|
|
|
public function getValue($object)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function newReflectionMember()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|