|
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;
|
@@ -1023,4 +1024,62 @@ private function createUninitializedObjectPropertyGhost(): UninitializedObjectPr
|
1023 | 1024 | return $class::createLazyGhost(initializer: function ($instance) {
|
1024 | 1025 | });
|
1025 | 1026 | }
|
| 1027 | + |
| 1028 | + /** |
| 1029 | + * @requires PHP 8.4 |
| 1030 | + */ |
| 1031 | + public function testIsWritableWithAsymmetricVisibility() |
| 1032 | + { |
| 1033 | + $object = new AsymmetricVisibility(); |
| 1034 | + |
| 1035 | + $this->assertTrue($this->propertyAccessor->isWritable($object, 'publicPublic')); |
| 1036 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'publicProtected')); |
| 1037 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'publicPrivate')); |
| 1038 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'privatePrivate')); |
| 1039 | + $this->assertFalse($this->propertyAccessor->isWritable($object, 'virtualNoSetHook')); |
| 1040 | + } |
| 1041 | + |
| 1042 | + /** |
| 1043 | + * @requires PHP 8.4 |
| 1044 | + */ |
| 1045 | + public function testIsReadableWithAsymmetricVisibility() |
| 1046 | + { |
| 1047 | + $object = new AsymmetricVisibility(); |
| 1048 | + |
| 1049 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'publicPublic')); |
| 1050 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'publicProtected')); |
| 1051 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'publicPrivate')); |
| 1052 | + $this->assertFalse($this->propertyAccessor->isReadable($object, 'privatePrivate')); |
| 1053 | + $this->assertTrue($this->propertyAccessor->isReadable($object, 'virtualNoSetHook')); |
| 1054 | + } |
| 1055 | + |
| 1056 | + /** |
| 1057 | + * @requires PHP 8.4 |
| 1058 | + * |
| 1059 | + * @dataProvider setValueWithAsymmetricVisibilityDataProvider |
| 1060 | + */ |
| 1061 | + public function testSetValueWithAsymmetricVisibility(string $propertyPath, ?string $expectedException) |
| 1062 | + { |
| 1063 | + $object = new AsymmetricVisibility(); |
| 1064 | + |
| 1065 | + if ($expectedException) { |
| 1066 | + $this->expectException($expectedException); |
| 1067 | + } else { |
| 1068 | + $this->expectNotToPerformAssertions(); |
| 1069 | + } |
| 1070 | + |
| 1071 | + $this->propertyAccessor->setValue($object, $propertyPath, true); |
| 1072 | + } |
| 1073 | + |
| 1074 | + /** |
| 1075 | + * @return iterable<array{0: string, 1: null|class-string}> |
| 1076 | + */ |
| 1077 | + public static function setValueWithAsymmetricVisibilityDataProvider(): iterable |
| 1078 | + { |
| 1079 | + yield ['publicPublic', null]; |
| 1080 | + yield ['publicProtected', \Error::class]; |
| 1081 | + yield ['publicPrivate', \Error::class]; |
| 1082 | + yield ['privatePrivate', NoSuchPropertyException::class]; |
| 1083 | + yield ['virtualNoSetHook', \Error::class]; |
| 1084 | + } |
1026 | 1085 | }
|
0 commit comments