|
19 | 19 | use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
|
20 | 20 | use Symfony\Component\PropertyAccess\PropertyAccess;
|
21 | 21 | use Symfony\Component\PropertyAccess\PropertyAccessor;
|
| 22 | +use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
22 | 23 | use Symfony\Component\PropertyAccess\Tests\Fixtures\ExtendedUninitializedProperty;
|
23 | 24 | use Symfony\Component\PropertyAccess\Tests\Fixtures\ReturnTyped;
|
24 | 25 | use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidArgumentLength;
|
|
41 | 42 |
|
42 | 43 | class PropertyAccessorTest extends TestCase
|
43 | 44 | {
|
44 |
| - /** |
45 |
| - * @var PropertyAccessor |
46 |
| - */ |
47 |
| - private $propertyAccessor; |
| 45 | + private PropertyAccessorInterface $propertyAccessor; |
48 | 46 |
|
49 | 47 | protected function setUp(): void
|
50 | 48 | {
|
@@ -83,7 +81,7 @@ public function getPathsWithMissingIndex()
|
83 | 81 | }
|
84 | 82 |
|
85 | 83 | /**
|
86 |
| - * @dataProvider getValidPropertyPaths |
| 84 | + * @dataProvider getValidReadPropertyPaths |
87 | 85 | */
|
88 | 86 | public function testGetValue($objectOrArray, $path, $value)
|
89 | 87 | {
|
@@ -312,7 +310,7 @@ public function testGetValueReadsMagicCallThatReturnsConstant()
|
312 | 310 | }
|
313 | 311 |
|
314 | 312 | /**
|
315 |
| - * @dataProvider getValidPropertyPaths |
| 313 | + * @dataProvider getValidWritePropertyPaths |
316 | 314 | */
|
317 | 315 | public function testSetValue($objectOrArray, $path)
|
318 | 316 | {
|
@@ -412,7 +410,7 @@ public function testGetValueWhenArrayValueIsNull()
|
412 | 410 | }
|
413 | 411 |
|
414 | 412 | /**
|
415 |
| - * @dataProvider getValidPropertyPaths |
| 413 | + * @dataProvider getValidReadPropertyPaths |
416 | 414 | */
|
417 | 415 | public function testIsReadable($objectOrArray, $path)
|
418 | 416 | {
|
@@ -465,7 +463,7 @@ public function testIsReadableRecognizesMagicCallIfEnabled()
|
465 | 463 | }
|
466 | 464 |
|
467 | 465 | /**
|
468 |
| - * @dataProvider getValidPropertyPaths |
| 466 | + * @dataProvider getValidWritePropertyPaths |
469 | 467 | */
|
470 | 468 | public function testIsWritable($objectOrArray, $path)
|
471 | 469 | {
|
@@ -517,7 +515,7 @@ public function testIsWritableRecognizesMagicCallIfEnabled()
|
517 | 515 | $this->assertTrue($this->propertyAccessor->isWritable(new TestClassMagicCall('Bernhard'), 'magicCallProperty'));
|
518 | 516 | }
|
519 | 517 |
|
520 |
| - public function getValidPropertyPaths() |
| 518 | + public function getValidWritePropertyPaths() |
521 | 519 | {
|
522 | 520 | return [
|
523 | 521 | [['Bernhard', 'Schussek'], '[0]', 'Bernhard'],
|
@@ -563,6 +561,19 @@ public function getValidPropertyPaths()
|
563 | 561 | ];
|
564 | 562 | }
|
565 | 563 |
|
| 564 | + public function getValidReadPropertyPaths() |
| 565 | + { |
| 566 | + $testCases = $this->getValidWritePropertyPaths(); |
| 567 | + |
| 568 | + // Optional paths can only be read and can't be written to. |
| 569 | + $testCases[] = [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?', null]; |
| 570 | + $testCases[] = [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?.baz?', null]; |
| 571 | + $testCases[] = [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?]', null]; |
| 572 | + $testCases[] = [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?][baz?]', null]; |
| 573 | + |
| 574 | + return $testCases; |
| 575 | + } |
| 576 | + |
566 | 577 | public function testTicket5755()
|
567 | 578 | {
|
568 | 579 | $object = new Ticket5775Object();
|
@@ -738,17 +749,11 @@ public function __construct($foo)
|
738 | 749 | $this->foo = $foo;
|
739 | 750 | }
|
740 | 751 |
|
741 |
| - /** |
742 |
| - * @return mixed |
743 |
| - */ |
744 | 752 | public function getFoo()
|
745 | 753 | {
|
746 | 754 | return $this->foo;
|
747 | 755 | }
|
748 | 756 |
|
749 |
| - /** |
750 |
| - * @param mixed $foo |
751 |
| - */ |
752 | 757 | public function setFoo($foo)
|
753 | 758 | {
|
754 | 759 | $this->foo = $foo;
|
|
0 commit comments