MemberMetadataTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Tests\Component\Validator\Mapping;
  11. require_once __DIR__.'/../Fixtures/ConstraintA.php';
  12. require_once __DIR__.'/../Fixtures/ConstraintB.php';
  13. use Symfony\Tests\Component\Validator\Fixtures\ConstraintA;
  14. use Symfony\Tests\Component\Validator\Fixtures\ConstraintB;
  15. use Symfony\Component\Validator\Constraints\Valid;
  16. use Symfony\Component\Validator\Mapping\MemberMetadata;
  17. class MemberMetadataTest extends \PHPUnit_Framework_TestCase
  18. {
  19. protected $metadata;
  20. protected function setUp()
  21. {
  22. $this->metadata = new TestMemberMetadata(
  23. 'Symfony\Tests\Component\Validator\Fixtures\Entity',
  24. 'getLastName',
  25. 'lastName'
  26. );
  27. }
  28. public function testAddValidSetsMemberToCascaded()
  29. {
  30. $result = $this->metadata->addConstraint(new Valid());
  31. $this->assertEquals(array(), $this->metadata->getConstraints());
  32. $this->assertEquals($result, $this->metadata);
  33. $this->assertTrue($this->metadata->isCascaded());
  34. }
  35. public function testAddOtherConstraintDoesNotSetMemberToCascaded()
  36. {
  37. $result = $this->metadata->addConstraint($constraint = new ConstraintA());
  38. $this->assertEquals(array($constraint), $this->metadata->getConstraints());
  39. $this->assertEquals($result, $this->metadata);
  40. $this->assertFalse($this->metadata->isCascaded());
  41. }
  42. public function testSerialize()
  43. {
  44. $this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
  45. $this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
  46. $metadata = unserialize(serialize($this->metadata));
  47. $this->assertEquals($this->metadata, $metadata);
  48. }
  49. }
  50. class TestMemberMetadata extends MemberMetadata
  51. {
  52. public function getValue($object)
  53. {
  54. }
  55. protected function newReflectionMember()
  56. {
  57. }
  58. }