PropertyMetadataTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\PropertyMetadata;
  13. use Symfony\Component\Validator\Tests\Fixtures\Entity;
  14. class PropertyMetadataTest extends TestCase
  15. {
  16. const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
  17. const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
  18. public function testInvalidPropertyName()
  19. {
  20. $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
  21. new PropertyMetadata(self::CLASSNAME, 'foobar');
  22. }
  23. public function testGetPropertyValueFromPrivateProperty()
  24. {
  25. $entity = new Entity('foobar');
  26. $metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
  27. $this->assertEquals('foobar', $metadata->getPropertyValue($entity));
  28. }
  29. public function testGetPropertyValueFromOverriddenPrivateProperty()
  30. {
  31. $entity = new Entity('foobar');
  32. $metadata = new PropertyMetadata(self::PARENTCLASS, 'data');
  33. $this->assertTrue($metadata->isPublic($entity));
  34. $this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
  35. }
  36. public function testGetPropertyValueFromRemovedProperty()
  37. {
  38. $entity = new Entity('foobar');
  39. $metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
  40. $metadata->name = 'test';
  41. $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
  42. $metadata->getPropertyValue($entity);
  43. }
  44. }