Minor dependency updates
[yaffs-website] / vendor / symfony / validator / Tests / Mapping / GetterMetadataTest.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\GetterMetadata;
16 use Symfony\Component\Validator\Tests\Fixtures\Entity;
17
18 class GetterMetadataTest extends TestCase
19 {
20     const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
21
22     public function testInvalidPropertyName()
23     {
24         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
25
26         new GetterMetadata(self::CLASSNAME, 'foobar');
27     }
28
29     public function testGetPropertyValueFromPublicGetter()
30     {
31         // private getters don't work yet because ReflectionMethod::setAccessible()
32         // does not exist yet in a stable PHP release
33
34         $entity = new Entity('foobar');
35         $metadata = new GetterMetadata(self::CLASSNAME, 'internal');
36
37         $this->assertEquals('foobar from getter', $metadata->getPropertyValue($entity));
38     }
39
40     public function testGetPropertyValueFromOverriddenPublicGetter()
41     {
42         $entity = new Entity();
43         $metadata = new GetterMetadata(self::CLASSNAME, 'data');
44
45         $this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
46     }
47
48     public function testGetPropertyValueFromIsser()
49     {
50         $entity = new Entity();
51         $metadata = new GetterMetadata(self::CLASSNAME, 'valid', 'isValid');
52
53         $this->assertEquals('valid', $metadata->getPropertyValue($entity));
54     }
55
56     public function testGetPropertyValueFromHasser()
57     {
58         $entity = new Entity();
59         $metadata = new GetterMetadata(self::CLASSNAME, 'permissions');
60
61         $this->assertEquals('permissions', $metadata->getPropertyValue($entity));
62     }
63
64     /**
65      * @expectedException \Symfony\Component\Validator\Exception\ValidatorException
66      * @expectedExceptionMessage The hasLastName() method does not exist in class Symfony\Component\Validator\Tests\Fixtures\Entity.
67      */
68     public function testUndefinedMethodNameThrowsException()
69     {
70         new GetterMetadata(self::CLASSNAME, 'lastName', 'hasLastName');
71     }
72 }