|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace ProxyManagerTest\ProxyGenerator\Util; |
|
20
|
|
|
|
|
21
|
|
|
use PHPUnit_Framework_TestCase; |
|
22
|
|
|
use ProxyManager\ProxyGenerator\Util\Properties; |
|
23
|
|
|
use ProxyManager\ProxyGenerator\Util\UnsetPropertiesGenerator; |
|
24
|
|
|
use ProxyManagerTestAsset\BaseClass; |
|
25
|
|
|
use ProxyManagerTestAsset\ClassWithCollidingPrivateInheritedProperties; |
|
26
|
|
|
use ProxyManagerTestAsset\ClassWithMixedProperties; |
|
27
|
|
|
use ProxyManagerTestAsset\EmptyClass; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\Util\UnsetPropertiesGenerator} |
|
31
|
|
|
* |
|
32
|
|
|
* @author Marco Pivetta <[email protected]> |
|
33
|
|
|
* @license MIT |
|
34
|
|
|
* |
|
35
|
|
|
* @covers \ProxyManager\ProxyGenerator\Util\UnsetPropertiesGenerator |
|
36
|
|
|
* @group Coverage |
|
37
|
|
|
*/ |
|
38
|
|
|
class UnsetPropertiesGeneratorTest extends PHPUnit_Framework_TestCase |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @dataProvider classNamesProvider |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $className |
|
44
|
|
|
* @param string $expectedCode |
|
45
|
|
|
* @param string $instanceName |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testGeneratedCode(string $className, string $expectedCode, string $instanceName) |
|
48
|
|
|
{ |
|
49
|
|
|
self::assertSame( |
|
50
|
|
|
$expectedCode, |
|
51
|
|
|
UnsetPropertiesGenerator::generateSnippet( |
|
52
|
|
|
Properties::fromReflectionClass(new \ReflectionClass($className)), |
|
53
|
|
|
$instanceName |
|
54
|
|
|
) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return string[][] |
|
60
|
|
|
*/ |
|
61
|
|
|
public function classNamesProvider() : array |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
|
|
EmptyClass::class => [ |
|
65
|
|
|
EmptyClass::class, |
|
66
|
|
|
'', |
|
67
|
|
|
'foo', |
|
68
|
|
|
], |
|
69
|
|
|
BaseClass::class => [ |
|
70
|
|
|
BaseClass::class, |
|
71
|
|
|
'unset($foo->publicProperty, $foo->protectedProperty); |
|
72
|
|
|
|
|
73
|
|
|
\Closure::bind(function (\ProxyManagerTestAsset\BaseClass $foo) { |
|
74
|
|
|
unset($foo->privateProperty); |
|
75
|
|
|
}, $foo, \'ProxyManagerTestAsset\\\\BaseClass\')->__invoke($foo); |
|
76
|
|
|
|
|
77
|
|
|
', |
|
78
|
|
|
'foo', |
|
79
|
|
|
], |
|
80
|
|
|
ClassWithMixedProperties::class => [ |
|
81
|
|
|
ClassWithMixedProperties::class, |
|
82
|
|
|
'unset($foo->publicProperty0, $foo->publicProperty1, $foo->publicProperty2, $foo->protectedProperty0, ' |
|
83
|
|
|
. '$foo->protectedProperty1, $foo->protectedProperty2); |
|
84
|
|
|
|
|
85
|
|
|
\Closure::bind(function (\ProxyManagerTestAsset\ClassWithMixedProperties $foo) { |
|
86
|
|
|
unset($foo->privateProperty0, $foo->privateProperty1, $foo->privateProperty2); |
|
87
|
|
|
}, $foo, \'ProxyManagerTestAsset\\\\ClassWithMixedProperties\')->__invoke($foo); |
|
88
|
|
|
|
|
89
|
|
|
', |
|
90
|
|
|
'foo', |
|
91
|
|
|
], |
|
92
|
|
|
ClassWithCollidingPrivateInheritedProperties::class => [ |
|
93
|
|
|
ClassWithCollidingPrivateInheritedProperties::class, |
|
94
|
|
|
'\Closure::bind(function (\ProxyManagerTestAsset\ClassWithCollidingPrivateInheritedProperties $bar) { |
|
95
|
|
|
unset($bar->property0); |
|
96
|
|
|
}, $bar, \'ProxyManagerTestAsset\\\\ClassWithCollidingPrivateInheritedProperties\')->__invoke($bar); |
|
97
|
|
|
|
|
98
|
|
|
\Closure::bind(function (\ProxyManagerTestAsset\ClassWithPrivateProperties $bar) { |
|
99
|
|
|
unset($bar->property0, $bar->property1, $bar->property2, $bar->property3, $bar->property4, ' |
|
100
|
|
|
. '$bar->property5, $bar->property6, $bar->property7, $bar->property8, $bar->property9); |
|
|
|
|
|
|
101
|
|
|
}, $bar, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke($bar); |
|
102
|
|
|
|
|
103
|
|
|
', |
|
104
|
|
|
'bar', |
|
105
|
|
|
], |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|