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/Component/Validator/Mapping/MemberMetadataTest.php
Bernhard Schussek 6a148465da [Validator][Form] Removed support for match-all group "*"
The constraint "Valid" does not accept any options or groups anymore. As per
JSR303 1.0 final, section 3.5.1 "Object graph validation" (page 39),
properties  annotated with valid should be cascaded independent of the current
group (i.e. always). Thus the group "*" is not necessary anymore and was
removed from the "Valid" constraint in the Form validation.xml.
2010-11-17 08:02:06 +01:00

65 lines
1.8 KiB
PHP

<?php
namespace Symfony\Tests\Component\Validator\Mapping;
require_once __DIR__.'/../Fixtures/ConstraintA.php';
require_once __DIR__.'/../Fixtures/ConstraintB.php';
use Symfony\Tests\Component\Validator\Fixtures\ConstraintA;
use Symfony\Tests\Component\Validator\Fixtures\ConstraintB;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Mapping\MemberMetadata;
class MemberMetadataTest extends \PHPUnit_Framework_TestCase
{
protected $metadata;
public function setUp()
{
$this->metadata = new TestMemberMetadata(
'Symfony\Tests\Component\Validator\Fixtures\Entity',
'getLastName',
'lastName'
);
}
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());
}
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()
{
}
}