|
21 | 21 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidArgumentLength; |
22 | 22 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidMethods; |
23 | 23 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClass; |
| 24 | +use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassDynamicProperty; |
24 | 25 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassIsWritable; |
25 | 26 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicCall; |
26 | 27 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicGet; |
@@ -97,6 +98,29 @@ public function testGetValue($objectOrArray, $path, $value) |
97 | 98 | $this->assertSame($value, $this->propertyAccessor->getValue($objectOrArray, $path)); |
98 | 99 | } |
99 | 100 |
|
| 101 | + /** |
| 102 | + * Test get dynamic value from object is other than \stdClass instance. |
| 103 | + */ |
| 104 | + public function testGetDynamicValue() |
| 105 | + { |
| 106 | + $value = 'dynamicPropertyValue'; |
| 107 | + $path = 'dynamicProperty'; |
| 108 | + $object = new TestClassDynamicProperty($value); |
| 109 | + |
| 110 | + $this->assertSame($value, $this->propertyAccessor->getValue($object, $path)); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Ensure exact exception with message was thrown on access to non-public property. |
| 115 | + */ |
| 116 | + public function testGetInaccessibleProperty() |
| 117 | + { |
| 118 | + $this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException'); |
| 119 | + $this->expectExceptionMessage(sprintf('Can\'t read protected or private property "%s" in class "%s".', 'protectedProperty', TestClass::class)); |
| 120 | + |
| 121 | + $this->propertyAccessor->getValue(new TestClass('Bernhard'), 'protectedProperty'); |
| 122 | + } |
| 123 | + |
100 | 124 | /** |
101 | 125 | * @dataProvider getPathsWithMissingProperty |
102 | 126 | */ |
|
0 commit comments