4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Tests\Mapping;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Mapping\PropertyMetadata;
16 use Symfony\Component\Validator\Tests\Fixtures\Entity;
18 class PropertyMetadataTest extends TestCase
20 const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
21 const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
23 public function testInvalidPropertyName()
25 $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
27 new PropertyMetadata(self::CLASSNAME, 'foobar');
30 public function testGetPropertyValueFromPrivateProperty()
32 $entity = new Entity('foobar');
33 $metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
35 $this->assertEquals('foobar', $metadata->getPropertyValue($entity));
38 public function testGetPropertyValueFromOverriddenPrivateProperty()
40 $entity = new Entity('foobar');
41 $metadata = new PropertyMetadata(self::PARENTCLASS, 'data');
43 $this->assertTrue($metadata->isPublic($entity));
44 $this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
47 public function testGetPropertyValueFromRemovedProperty()
49 $entity = new Entity('foobar');
50 $metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
51 $metadata->name = 'test';
53 $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
54 $metadata->getPropertyValue($entity);