9fea435dff27997f5c4f48b157cddbc1de8bffa5
[yaffs-website] / vendor / symfony / validator / Tests / Mapping / PropertyMetadataTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Mapping;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Mapping\PropertyMetadata;
16 use Symfony\Component\Validator\Tests\Fixtures\Entity;
17
18 class PropertyMetadataTest extends TestCase
19 {
20     const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
21     const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
22
23     public function testInvalidPropertyName()
24     {
25         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
26
27         new PropertyMetadata(self::CLASSNAME, 'foobar');
28     }
29
30     public function testGetPropertyValueFromPrivateProperty()
31     {
32         $entity = new Entity('foobar');
33         $metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
34
35         $this->assertEquals('foobar', $metadata->getPropertyValue($entity));
36     }
37
38     public function testGetPropertyValueFromOverriddenPrivateProperty()
39     {
40         $entity = new Entity('foobar');
41         $metadata = new PropertyMetadata(self::PARENTCLASS, 'data');
42
43         $this->assertTrue($metadata->isPublic($entity));
44         $this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
45     }
46
47     public function testGetPropertyValueFromRemovedProperty()
48     {
49         $entity = new Entity('foobar');
50         $metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
51         $metadata->name = 'test';
52
53         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
54         $metadata->getPropertyValue($entity);
55     }
56 }