|
32 | 32 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy;
|
33 | 33 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy;
|
34 | 34 | use Symfony\Component\PropertyInfo\Tests\Fixtures\SnakeCaseDummy;
|
| 35 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\VirtualProperties; |
35 | 36 | use Symfony\Component\PropertyInfo\Type as LegacyType;
|
36 | 37 | use Symfony\Component\TypeInfo\Type;
|
37 | 38 | use Symfony\Component\TypeInfo\Type\NullableType;
|
@@ -702,6 +703,69 @@ public function testAsymmetricVisibility()
|
702 | 703 | $this->assertFalse($this->extractor->isWritable(AsymmetricVisibility::class, 'protectedPrivate'));
|
703 | 704 | }
|
704 | 705 |
|
| 706 | + /** |
| 707 | + * @requires PHP 8.4 |
| 708 | + */ |
| 709 | + public function testVirtualProperties() |
| 710 | + { |
| 711 | + $this->assertTrue($this->extractor->isReadable(VirtualProperties::class, 'virtualNoSetHook')); |
| 712 | + $this->assertTrue($this->extractor->isReadable(VirtualProperties::class, 'virtualSetHookOnly')); |
| 713 | + $this->assertTrue($this->extractor->isReadable(VirtualProperties::class, 'virtualHook')); |
| 714 | + $this->assertFalse($this->extractor->isWritable(VirtualProperties::class, 'virtualNoSetHook')); |
| 715 | + $this->assertTrue($this->extractor->isWritable(VirtualProperties::class, 'virtualSetHookOnly')); |
| 716 | + $this->assertTrue($this->extractor->isWritable(VirtualProperties::class, 'virtualHook')); |
| 717 | + } |
| 718 | + |
| 719 | + /** |
| 720 | + * @dataProvider provideAsymmetricVisibilityMutator |
| 721 | + * @requires PHP 8.4 |
| 722 | + */ |
| 723 | + public function testAsymmetricVisibilityMutator(string $property, string $readVisibility, string $writeVisibility) |
| 724 | + { |
| 725 | + $extractor = new ReflectionExtractor(null, null, null, true, ReflectionExtractor::ALLOW_PUBLIC | ReflectionExtractor::ALLOW_PROTECTED | ReflectionExtractor::ALLOW_PRIVATE); |
| 726 | + $readMutator = $extractor->getReadInfo(AsymmetricVisibility::class, $property); |
| 727 | + $writeMutator = $extractor->getWriteInfo(AsymmetricVisibility::class, $property, [ |
| 728 | + 'enable_getter_setter_extraction' => true, |
| 729 | + ]); |
| 730 | + |
| 731 | + $this->assertSame(PropertyReadInfo::TYPE_PROPERTY, $readMutator->getType()); |
| 732 | + $this->assertSame(PropertyWriteInfo::TYPE_PROPERTY, $writeMutator->getType()); |
| 733 | + $this->assertSame($readVisibility, $readMutator->getVisibility()); |
| 734 | + $this->assertSame($writeVisibility, $writeMutator->getVisibility()); |
| 735 | + } |
| 736 | + |
| 737 | + public static function provideAsymmetricVisibilityMutator(): iterable |
| 738 | + { |
| 739 | + yield ['publicPrivate', PropertyReadInfo::VISIBILITY_PUBLIC, PropertyWriteInfo::VISIBILITY_PRIVATE]; |
| 740 | + yield ['publicProtected', PropertyReadInfo::VISIBILITY_PUBLIC, PropertyWriteInfo::VISIBILITY_PROTECTED]; |
| 741 | + yield ['protectedPrivate', PropertyReadInfo::VISIBILITY_PROTECTED, PropertyWriteInfo::VISIBILITY_PRIVATE]; |
| 742 | + } |
| 743 | + |
| 744 | + /** |
| 745 | + * @dataProvider provideVirtualPropertiesMutator |
| 746 | + * @requires PHP 8.4 |
| 747 | + */ |
| 748 | + public function testVirtualPropertiesMutator(string $property, string $readVisibility, string $writeVisibility) |
| 749 | + { |
| 750 | + $extractor = new ReflectionExtractor(null, null, null, true, ReflectionExtractor::ALLOW_PUBLIC | ReflectionExtractor::ALLOW_PROTECTED | ReflectionExtractor::ALLOW_PRIVATE); |
| 751 | + $readMutator = $extractor->getReadInfo(VirtualProperties::class, $property); |
| 752 | + $writeMutator = $extractor->getWriteInfo(VirtualProperties::class, $property, [ |
| 753 | + 'enable_getter_setter_extraction' => true, |
| 754 | + ]); |
| 755 | + |
| 756 | + $this->assertSame(PropertyReadInfo::TYPE_PROPERTY, $readMutator->getType()); |
| 757 | + $this->assertSame(PropertyWriteInfo::TYPE_PROPERTY, $writeMutator->getType()); |
| 758 | + $this->assertSame($readVisibility, $readMutator->getVisibility()); |
| 759 | + $this->assertSame($writeVisibility, $writeMutator->getVisibility()); |
| 760 | + } |
| 761 | + |
| 762 | + public static function provideVirtualPropertiesMutator(): iterable |
| 763 | + { |
| 764 | + yield ['virtualNoSetHook', PropertyReadInfo::VISIBILITY_PUBLIC, PropertyWriteInfo::VISIBILITY_PRIVATE]; |
| 765 | + yield ['virtualSetHookOnly', PropertyReadInfo::VISIBILITY_PUBLIC, PropertyWriteInfo::VISIBILITY_PUBLIC]; |
| 766 | + yield ['virtualHook', PropertyReadInfo::VISIBILITY_PUBLIC, PropertyWriteInfo::VISIBILITY_PUBLIC]; |
| 767 | + } |
| 768 | + |
705 | 769 | /**
|
706 | 770 | * @dataProvider typesProvider
|
707 | 771 | */
|
|
0 commit comments