GetterMetadataTest.php 970 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Symfony\Tests\Component\Validator\Mapping;
  3. require_once __DIR__.'/../Fixtures/Entity.php';
  4. use Symfony\Component\Validator\Mapping\GetterMetadata;
  5. use Symfony\Tests\Component\Validator\Fixtures\Entity;
  6. class GetterMetadataTest extends \PHPUnit_Framework_TestCase
  7. {
  8. const CLASSNAME = 'Symfony\Tests\Component\Validator\Fixtures\Entity';
  9. public function testInvalidPropertyName()
  10. {
  11. $this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
  12. new GetterMetadata(self::CLASSNAME, 'foobar');
  13. }
  14. public function testGetValueFromPublicGetter()
  15. {
  16. // private getters don't work yet because ReflectionMethod::setAccessible()
  17. // does not exists yet in a stable PHP release
  18. $entity = new Entity('foobar');
  19. $metadata = new GetterMetadata(self::CLASSNAME, 'internal');
  20. $this->assertEquals('foobar from getter', $metadata->getValue($entity));
  21. }
  22. }