GetterMetadataTest.php 1.0 KB

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