1 | <?php |
||
21 | * @group Coverage |
||
22 | */ |
||
23 | class UnsetPropertiesGeneratorTest extends TestCase |
||
|
|||
24 | { |
||
25 | /** |
||
26 | * @dataProvider classNamesProvider |
||
27 | */ |
||
28 | public function testGeneratedCode(string $className, string $expectedCode, string $instanceName) : void |
||
29 | { |
||
30 | self::assertSame( |
||
31 | $expectedCode, |
||
32 | UnsetPropertiesGenerator::generateSnippet( |
||
33 | Properties::fromReflectionClass(new ReflectionClass($className)), |
||
34 | $instanceName |
||
35 | ) |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @return string[][] |
||
41 | */ |
||
42 | public function classNamesProvider() : array |
||
43 | { |
||
44 | return [ |
||
45 | EmptyClass::class => [ |
||
46 | EmptyClass::class, |
||
47 | '', |
||
48 | 'foo', |
||
49 | ], |
||
50 | BaseClass::class => [ |
||
51 | BaseClass::class, |
||
52 | 'unset($foo->publicProperty, $foo->protectedProperty); |
||
53 | |||
54 | \Closure::bind(function (\ProxyManagerTestAsset\BaseClass $instance) { |
||
55 | unset($instance->privateProperty); |
||
56 | }, $foo, \'ProxyManagerTestAsset\\\\BaseClass\')->__invoke($foo); |
||
57 | |||
58 | ', |
||
59 | 'foo', |
||
60 | ], |
||
61 | ClassWithMixedProperties::class => [ |
||
62 | ClassWithMixedProperties::class, |
||
63 | 'unset($foo->publicProperty0, $foo->publicProperty1, $foo->publicProperty2, $foo->protectedProperty0, ' |
||
64 | . '$foo->protectedProperty1, $foo->protectedProperty2); |
||
65 | |||
66 | \Closure::bind(function (\ProxyManagerTestAsset\ClassWithMixedProperties $instance) { |
||
67 | unset($instance->privateProperty0, $instance->privateProperty1, $instance->privateProperty2); |
||
68 | }, $foo, \'ProxyManagerTestAsset\\\\ClassWithMixedProperties\')->__invoke($foo); |
||
69 | |||
70 | ', |
||
71 | 'foo', |
||
72 | ], |
||
73 | ClassWithCollidingPrivateInheritedProperties::class => [ |
||
74 | ClassWithCollidingPrivateInheritedProperties::class, |
||
75 | '\Closure::bind(function (\ProxyManagerTestAsset\ClassWithCollidingPrivateInheritedProperties ' |
||
76 | . '$instance) { |
||
77 | unset($instance->property0); |
||
78 | }, $bar, \'ProxyManagerTestAsset\\\\ClassWithCollidingPrivateInheritedProperties\')->__invoke($bar); |
||
79 | |||
80 | \Closure::bind(function (\ProxyManagerTestAsset\ClassWithPrivateProperties $instance) { |
||
81 | unset($instance->property0, $instance->property1, $instance->property2, $instance->property3, ' |
||
82 | . '$instance->property4, $instance->property5, $instance->property6, $instance->property7, ' |
||
83 | . '$instance->property8, $instance->property9); |
||
84 | }, $bar, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke($bar); |
||
85 | |||
86 | ', |
||
87 | 'bar', |
||
88 | ], |
||
89 | ClassWithMixedTypedProperties::class => [ |
||
90 | ClassWithMixedTypedProperties::class, |
||
91 | <<<'PHP' |
||
105 |