ElementMetadataTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Symfony\Tests\Components\Validator\Mapping;
  3. require_once __DIR__.'/../Fixtures/ConstraintA.php';
  4. require_once __DIR__.'/../Fixtures/ConstraintB.php';
  5. use Symfony\Tests\Components\Validator\Fixtures\ConstraintA;
  6. use Symfony\Tests\Components\Validator\Fixtures\ConstraintB;
  7. use Symfony\Components\Validator\Mapping\ElementMetadata;
  8. class ElementMetadataTest extends \PHPUnit_Framework_TestCase
  9. {
  10. protected $metadata;
  11. public function setUp()
  12. {
  13. $this->metadata = new ElementMetadata('Symfony\Tests\Components\Validator\Fixtures\Entity');
  14. }
  15. public function testAddConstraints()
  16. {
  17. $this->metadata->addConstraint($constraint1 = new ConstraintA());
  18. $this->metadata->addConstraint($constraint2 = new ConstraintA());
  19. $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
  20. }
  21. public function testMultipleConstraintsOfTheSameType()
  22. {
  23. $constraint1 = new ConstraintA(array('property1' => 'A'));
  24. $constraint2 = new ConstraintA(array('property1' => 'B'));
  25. $this->metadata->addConstraint($constraint1);
  26. $this->metadata->addConstraint($constraint2);
  27. $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
  28. }
  29. public function testFindConstraintsByGroup()
  30. {
  31. $constraint1 = new ConstraintA(array('groups' => 'TestGroup'));
  32. $constraint2 = new ConstraintB();
  33. $this->metadata->addConstraint($constraint1);
  34. $this->metadata->addConstraint($constraint2);
  35. $this->assertEquals(array($constraint1), $this->metadata->findConstraints('TestGroup'));
  36. }
  37. }