|
20 | 20 | use Symfony\Component\PropertyAccess\PropertyAccess;
|
21 | 21 | use Symfony\Component\PropertyAccess\PropertyAccessor;
|
22 | 22 | use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
| 23 | +use Symfony\Component\PropertyAccess\Tests\Fixtures\AsymmetricVisibility; |
23 | 24 | use Symfony\Component\PropertyAccess\Tests\Fixtures\ExtendedUninitializedProperty;
|
24 | 25 | use Symfony\Component\PropertyAccess\Tests\Fixtures\ReturnTyped;
|
25 | 26 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidArgumentLength;
|
@@ -1046,4 +1047,62 @@ private function createUninitializedObjectPropertyGhost(): UninitializedObjectPr
|
1046 | 1047 | return $class::createLazyGhost(initializer: function ($instance) {
|
1047 | 1048 | });
|
1048 | 1049 | }
|
| 1050 | + |
| 1051 | + /** |
| 1052 | + * @requires PHP 8.4 |
| 1053 | + */ |
| 1054 | + public function testIsWritableWithAsymmetricVisibility() |
| 1055 | + { |
| 1056 | + $object = new AsymmetricVisibility(); |
| 1057 | + |
| 1058 | + $this->assertTrue($this->propertyAccessor->isWritable($object, 'publicPublic')); |
| 1059 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'publicProtected')); |
| 1060 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'publicPrivate')); |
| 1061 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'privatePrivate')); |
| 1062 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'virtualNoSetHook')); |
| 1063 | + } |
| 1064 | + |
| 1065 | + /** |
| 1066 | + * @requires PHP 8.4 |
| 1067 | + */ |
| 1068 | + public function testIsReadableWithAsymmetricVisibility() |
| 1069 | + { |
| 1070 | + $object = new AsymmetricVisibility(); |
| 1071 | + |
| 1072 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'publicPublic')); |
| 1073 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'publicProtected')); |
| 1074 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'publicPrivate')); |
| 1075 | + $this->assertFalse($this->propertyAccessor->isReadable($object, 'privatePrivate')); |
| 1076 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'virtualNoSetHook')); |
| 1077 | + } |
| 1078 | + |
| 1079 | + /** |
| 1080 | + * @requires PHP 8.4 |
| 1081 | + * |
| 1082 | + * @dataProvider setValueWithAsymmetricVisibilityDataProvider |
| 1083 | + */ |
| 1084 | + public function testSetValueWithAsymmetricVisibility(string $propertyPath, ?string $expectedException) |
| 1085 | + { |
| 1086 | + $object = new AsymmetricVisibility(); |
| 1087 | + |
| 1088 | + if ($expectedException) { |
| 1089 | + $this->expectException($expectedException); |
| 1090 | + } else { |
| 1091 | + $this->expectNotToPerformAssertions(); |
| 1092 | + } |
| 1093 | + |
| 1094 | + $this->propertyAccessor->setValue($object, $propertyPath, true); |
| 1095 | + } |
| 1096 | + |
| 1097 | + /** |
| 1098 | + * @return iterable<array{0: string, 1: null|class-string}> |
| 1099 | + */ |
| 1100 | + public static function setValueWithAsymmetricVisibilityDataProvider(): iterable |
| 1101 | + { |
| 1102 | + yield ['publicPublic', null]; |
| 1103 | + yield ['publicProtected', \Error::class]; |
| 1104 | + yield ['publicPrivate', \Error::class]; |
| 1105 | + yield ['privatePrivate', NoSuchPropertyException::class]; |
| 1106 | + yield ['virtualNoSetHook', \Error::class]; |
| 1107 | + } |
1049 | 1108 | }
|
0 commit comments