[Validator] Add ClassMetadata plural methods for convinience
This commit is contained in:
parent
229355618b
commit
0fd6769d2a
@ -184,7 +184,7 @@ class ClassMetadata extends ElementMetadata implements LegacyMetadataInterface,
|
||||
'members',
|
||||
'name',
|
||||
'properties',
|
||||
'defaultGroup'
|
||||
'defaultGroup',
|
||||
));
|
||||
}
|
||||
|
||||
@ -278,6 +278,21 @@ class ClassMetadata extends ElementMetadata implements LegacyMetadataInterface,
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $property
|
||||
* @param Constraint[] $constraints
|
||||
*
|
||||
* @return ClassMetadata
|
||||
*/
|
||||
public function addPropertyConstraints($property, array $constraints)
|
||||
{
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->addPropertyConstraint($property, $constraint);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a constraint to the getter of the given property.
|
||||
*
|
||||
@ -304,6 +319,21 @@ class ClassMetadata extends ElementMetadata implements LegacyMetadataInterface,
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $property
|
||||
* @param Constraint[] $constraints
|
||||
*
|
||||
* @return ClassMetadata
|
||||
*/
|
||||
public function addGetterConstraints($property, array $constraints)
|
||||
{
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->addGetterConstraint($property, $constraint);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the constraints of the given metadata into this object.
|
||||
*
|
||||
|
@ -58,6 +58,55 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('firstName', 'lastName'), $this->metadata->getConstrainedProperties());
|
||||
}
|
||||
|
||||
public function testAddMultiplePropertyConstraints()
|
||||
{
|
||||
$this->metadata->addPropertyConstraints('lastName', array(new ConstraintA(), new ConstraintB()));
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'Entity'))),
|
||||
new ConstraintB(array('groups' => array('Default', 'Entity'))),
|
||||
);
|
||||
|
||||
$properties = $this->metadata->getPropertyMetadata('lastName');
|
||||
|
||||
$this->assertCount(1, $properties);
|
||||
$this->assertEquals('lastName', $properties[0]->getName());
|
||||
$this->assertEquals($constraints, $properties[0]->getConstraints());
|
||||
}
|
||||
|
||||
public function testAddGetterConstraints()
|
||||
{
|
||||
$this->metadata->addGetterConstraint('lastName', new ConstraintA());
|
||||
$this->metadata->addGetterConstraint('lastName', new ConstraintB());
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'Entity'))),
|
||||
new ConstraintB(array('groups' => array('Default', 'Entity'))),
|
||||
);
|
||||
|
||||
$properties = $this->metadata->getPropertyMetadata('lastName');
|
||||
|
||||
$this->assertCount(1, $properties);
|
||||
$this->assertEquals('getLastName', $properties[0]->getName());
|
||||
$this->assertEquals($constraints, $properties[0]->getConstraints());
|
||||
}
|
||||
|
||||
public function testAddMultipleGetterConstraints()
|
||||
{
|
||||
$this->metadata->addGetterConstraints('lastName', array(new ConstraintA(), new ConstraintB()));
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'Entity'))),
|
||||
new ConstraintB(array('groups' => array('Default', 'Entity'))),
|
||||
);
|
||||
|
||||
$properties = $this->metadata->getPropertyMetadata('lastName');
|
||||
|
||||
$this->assertCount(1, $properties);
|
||||
$this->assertEquals('getLastName', $properties[0]->getName());
|
||||
$this->assertEquals($constraints, $properties[0]->getConstraints());
|
||||
}
|
||||
|
||||
public function testMergeConstraintsMergesClassConstraints()
|
||||
{
|
||||
$parent = new ClassMetadata(self::PARENTCLASS);
|
||||
|
Reference in New Issue
Block a user