1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\Functional; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory; |
9
|
|
|
use ProxyManager\Factory\AccessInterceptorValueHolderFactory; |
10
|
|
|
use ProxyManager\Factory\LazyLoadingGhostFactory; |
11
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory; |
12
|
|
|
use ProxyManagerTestAsset\BaseClass; |
13
|
|
|
use ProxyManagerTestAsset\ClassWithByRefMagicMethods; |
14
|
|
|
use ProxyManagerTestAsset\ClassWithCollidingPrivateInheritedProperties; |
15
|
|
|
use ProxyManagerTestAsset\ClassWithFinalMagicMethods; |
16
|
|
|
use ProxyManagerTestAsset\ClassWithFinalMethods; |
17
|
|
|
use ProxyManagerTestAsset\ClassWithMagicMethods; |
18
|
|
|
use ProxyManagerTestAsset\ClassWithMethodWithByRefVariadicFunction; |
19
|
|
|
use ProxyManagerTestAsset\ClassWithMethodWithVariadicFunction; |
20
|
|
|
use ProxyManagerTestAsset\ClassWithMixedProperties; |
21
|
|
|
use ProxyManagerTestAsset\ClassWithMixedReferenceableTypedProperties; |
22
|
|
|
use ProxyManagerTestAsset\ClassWithMixedTypedProperties; |
23
|
|
|
use ProxyManagerTestAsset\ClassWithParentHint; |
24
|
|
|
use ProxyManagerTestAsset\ClassWithPrivateProperties; |
25
|
|
|
use ProxyManagerTestAsset\ClassWithProtectedProperties; |
26
|
|
|
use ProxyManagerTestAsset\ClassWithPublicProperties; |
27
|
|
|
use ProxyManagerTestAsset\ClassWithSelfHint; |
28
|
|
|
use ProxyManagerTestAsset\EmptyClass; |
29
|
|
|
use ProxyManagerTestAsset\HydratedObject; |
30
|
|
|
use ProxyManagerTestAsset\IterableTypeHintClass; |
31
|
|
|
use ProxyManagerTestAsset\ObjectTypeHintClass; |
32
|
|
|
use ProxyManagerTestAsset\ReturnTypeHintedClass; |
33
|
|
|
use ProxyManagerTestAsset\ScalarTypeHintedClass; |
34
|
|
|
use ProxyManagerTestAsset\VoidMethodTypeHintedClass; |
35
|
|
|
use function get_class; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Verifies that proxy factories don't conflict with each other when generating proxies |
39
|
|
|
* |
40
|
|
|
* @link https://github.com/Ocramius/ProxyManager/issues/10 |
41
|
|
|
* |
42
|
|
|
* @group Functional |
43
|
|
|
* @group issue-10 |
44
|
|
|
* @coversNothing |
45
|
|
|
*/ |
46
|
|
|
final class MultipleProxyGenerationTest extends TestCase |
47
|
|
|
{ |
48
|
|
|
/** |
49
|
|
|
* Verifies that proxies generated from different factories will retain their specific implementation |
50
|
|
|
* and won't conflict |
51
|
|
|
* |
52
|
|
|
* @dataProvider getTestedClasses |
53
|
|
|
*/ |
54
|
|
|
public function testCanGenerateMultipleDifferentProxiesForSameClass(object $object) : void |
55
|
|
|
{ |
56
|
|
|
$ghostProxyFactory = new LazyLoadingGhostFactory(); |
57
|
|
|
$virtualProxyFactory = new LazyLoadingValueHolderFactory(); |
58
|
|
|
$accessInterceptorFactory = new AccessInterceptorValueHolderFactory(); |
59
|
|
|
$accessInterceptorScopeLocalizerFactory = new AccessInterceptorScopeLocalizerFactory(); |
60
|
|
|
$className = get_class($object); |
61
|
|
|
$initializer = static function () : bool { |
62
|
|
|
return true; |
63
|
|
|
}; |
64
|
|
|
|
65
|
|
|
$generated = [ |
66
|
|
|
$ghostProxyFactory->createProxy($className, $initializer), |
67
|
|
|
$virtualProxyFactory->createProxy($className, $initializer), |
68
|
|
|
$accessInterceptorFactory->createProxy($object), |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
if ($className !== ClassWithMixedTypedProperties::class) { |
72
|
|
|
$generated[] = $accessInterceptorScopeLocalizerFactory->createProxy($object); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
foreach ($generated as $key => $proxy) { |
76
|
|
|
self::assertInstanceOf($className, $proxy); |
|
|
|
|
77
|
|
|
|
78
|
|
|
foreach ($generated as $comparedKey => $comparedProxy) { |
79
|
|
|
if ($comparedKey === $key) { |
80
|
|
|
continue; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
self::assertNotSame(get_class($comparedProxy), get_class($proxy)); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$proxyClass = get_class($proxy); |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @psalm-suppress InvalidStringClass |
90
|
|
|
* @psalm-suppress MixedMethodCall |
91
|
|
|
*/ |
92
|
|
|
self::assertInstanceOf($proxyClass, new $proxyClass(), 'Proxy can be instantiated via normal constructor'); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return object[][] |
98
|
|
|
*/ |
99
|
|
|
public function getTestedClasses() : array |
100
|
|
|
{ |
101
|
|
|
return [ |
102
|
|
|
[new BaseClass()], |
103
|
|
|
[new ClassWithMagicMethods()], |
104
|
|
|
[new ClassWithFinalMethods()], |
105
|
|
|
[new ClassWithFinalMagicMethods()], |
106
|
|
|
[new ClassWithByRefMagicMethods()], |
107
|
|
|
[new ClassWithMixedProperties()], |
108
|
|
|
[new ClassWithMixedTypedProperties()], |
109
|
|
|
[new ClassWithMixedReferenceableTypedProperties()], |
110
|
|
|
[new ClassWithPrivateProperties()], |
111
|
|
|
[new ClassWithProtectedProperties()], |
112
|
|
|
[new ClassWithPublicProperties()], |
113
|
|
|
[new EmptyClass()], |
114
|
|
|
[new HydratedObject()], |
115
|
|
|
[new ClassWithSelfHint()], |
116
|
|
|
[new ClassWithParentHint()], |
117
|
|
|
[new ClassWithCollidingPrivateInheritedProperties()], |
118
|
|
|
[new ClassWithMethodWithVariadicFunction()], |
119
|
|
|
[new ClassWithMethodWithByRefVariadicFunction()], |
120
|
|
|
[new ScalarTypeHintedClass()], |
121
|
|
|
[new IterableTypeHintClass()], |
122
|
|
|
[new ObjectTypeHintClass()], |
123
|
|
|
[new ReturnTypeHintedClass()], |
124
|
|
|
[new VoidMethodTypeHintedClass()], |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.