LegacyElementMetadataTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Tests\Mapping;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Validator\Mapping\ElementMetadata;
  13. use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
  14. use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
  15. /**
  16. * @group legacy
  17. */
  18. class LegacyElementMetadataTest extends TestCase
  19. {
  20. protected $metadata;
  21. protected function setUp()
  22. {
  23. $this->metadata = new TestElementMetadata();
  24. }
  25. protected function tearDown()
  26. {
  27. $this->metadata = null;
  28. }
  29. public function testAddConstraints()
  30. {
  31. $this->metadata->addConstraint($constraint1 = new ConstraintA());
  32. $this->metadata->addConstraint($constraint2 = new ConstraintA());
  33. $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
  34. }
  35. public function testMultipleConstraintsOfTheSameType()
  36. {
  37. $constraint1 = new ConstraintA(array('property1' => 'A'));
  38. $constraint2 = new ConstraintA(array('property1' => 'B'));
  39. $this->metadata->addConstraint($constraint1);
  40. $this->metadata->addConstraint($constraint2);
  41. $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
  42. }
  43. public function testFindConstraintsByGroup()
  44. {
  45. $constraint1 = new ConstraintA(array('groups' => 'TestGroup'));
  46. $constraint2 = new ConstraintB();
  47. $this->metadata->addConstraint($constraint1);
  48. $this->metadata->addConstraint($constraint2);
  49. $this->assertEquals(array($constraint1), $this->metadata->findConstraints('TestGroup'));
  50. }
  51. public function testSerialize()
  52. {
  53. $this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
  54. $this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
  55. $metadata = unserialize(serialize($this->metadata));
  56. $this->assertEquals($this->metadata, $metadata);
  57. }
  58. }
  59. class TestElementMetadata extends ElementMetadata
  60. {
  61. }