GetterMetadataTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Tests\Component\Validator\Mapping;
  11. require_once __DIR__.'/../Fixtures/Entity.php';
  12. use Symfony\Component\Validator\Mapping\GetterMetadata;
  13. use Symfony\Tests\Component\Validator\Fixtures\Entity;
  14. class GetterMetadataTest extends \PHPUnit_Framework_TestCase
  15. {
  16. const CLASSNAME = 'Symfony\Tests\Component\Validator\Fixtures\Entity';
  17. public function testInvalidPropertyName()
  18. {
  19. $this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
  20. new GetterMetadata(self::CLASSNAME, 'foobar');
  21. }
  22. public function testGetValueFromPublicGetter()
  23. {
  24. // private getters don't work yet because ReflectionMethod::setAccessible()
  25. // does not exists yet in a stable PHP release
  26. $entity = new Entity('foobar');
  27. $metadata = new GetterMetadata(self::CLASSNAME, 'internal');
  28. $this->assertEquals('foobar from getter', $metadata->getValue($entity));
  29. }
  30. }