|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\BindProxyProperties; |
|
10
|
|
|
use ProxyManagerTestAsset\ClassWithMixedProperties; |
|
11
|
|
|
use ProxyManagerTestAsset\ClassWithMixedReferenceableTypedProperties; |
|
12
|
|
|
use ProxyManagerTestAsset\ClassWithPrivateProperties; |
|
13
|
|
|
use ProxyManagerTestAsset\ClassWithProtectedProperties; |
|
14
|
|
|
use ReflectionClass; |
|
15
|
|
|
use Zend\Code\Generator\PropertyGenerator; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\BindProxyProperties} |
|
19
|
|
|
* |
|
20
|
|
|
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\BindProxyProperties |
|
21
|
|
|
* @group Coverage |
|
22
|
|
|
*/ |
|
23
|
|
|
final class BindProxyPropertiesTest extends TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var PropertyGenerator&MockObject */ |
|
26
|
|
|
private PropertyGenerator $prefixInterceptors; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** @var PropertyGenerator&MockObject */ |
|
29
|
|
|
private PropertyGenerator $suffixInterceptors; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritDoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function setUp() : void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->prefixInterceptors = $this->createMock(PropertyGenerator::class); |
|
37
|
|
|
$this->suffixInterceptors = $this->createMock(PropertyGenerator::class); |
|
38
|
|
|
|
|
39
|
|
|
$this->prefixInterceptors->method('getName')->willReturn('pre'); |
|
40
|
|
|
$this->suffixInterceptors->method('getName')->willReturn('post'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testSignature() : void |
|
44
|
|
|
{ |
|
45
|
|
|
$method = new BindProxyProperties( |
|
46
|
|
|
new ReflectionClass(ClassWithProtectedProperties::class), |
|
47
|
|
|
$this->prefixInterceptors, |
|
48
|
|
|
$this->suffixInterceptors |
|
49
|
|
|
); |
|
50
|
|
|
self::assertSame('bindProxyProperties', $method->getName()); |
|
51
|
|
|
self::assertSame('private', $method->getVisibility()); |
|
52
|
|
|
self::assertFalse($method->isStatic()); |
|
53
|
|
|
|
|
54
|
|
|
$parameters = $method->getParameters(); |
|
55
|
|
|
|
|
56
|
|
|
self::assertCount(3, $parameters); |
|
57
|
|
|
|
|
58
|
|
|
self::assertSame( |
|
59
|
|
|
ClassWithProtectedProperties::class, |
|
60
|
|
|
$parameters['localizedObject']->getType() |
|
61
|
|
|
); |
|
62
|
|
|
self::assertSame('array', $parameters['prefixInterceptors']->getType()); |
|
63
|
|
|
self::assertSame('array', $parameters['suffixInterceptors']->getType()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testBodyStructure() : void |
|
67
|
|
|
{ |
|
68
|
|
|
$method = new BindProxyProperties( |
|
69
|
|
|
new ReflectionClass(ClassWithMixedProperties::class), |
|
70
|
|
|
$this->prefixInterceptors, |
|
71
|
|
|
$this->suffixInterceptors |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$expectedCode = <<<'PHP' |
|
75
|
|
|
$this->publicProperty0 = & $localizedObject->publicProperty0; |
|
76
|
|
|
|
|
77
|
|
|
$this->publicProperty1 = & $localizedObject->publicProperty1; |
|
78
|
|
|
|
|
79
|
|
|
$this->publicProperty2 = & $localizedObject->publicProperty2; |
|
80
|
|
|
|
|
81
|
|
|
$this->protectedProperty0 = & $localizedObject->protectedProperty0; |
|
82
|
|
|
|
|
83
|
|
|
$this->protectedProperty1 = & $localizedObject->protectedProperty1; |
|
84
|
|
|
|
|
85
|
|
|
$this->protectedProperty2 = & $localizedObject->protectedProperty2; |
|
86
|
|
|
|
|
87
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
88
|
|
|
$this->privateProperty0 = & $localizedObject->privateProperty0; |
|
89
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedProperties')->__invoke(); |
|
90
|
|
|
|
|
91
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
92
|
|
|
$this->privateProperty1 = & $localizedObject->privateProperty1; |
|
93
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedProperties')->__invoke(); |
|
94
|
|
|
|
|
95
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
96
|
|
|
$this->privateProperty2 = & $localizedObject->privateProperty2; |
|
97
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedProperties')->__invoke(); |
|
98
|
|
|
|
|
99
|
|
|
$this->pre = $prefixInterceptors; |
|
100
|
|
|
$this->post = $suffixInterceptors; |
|
101
|
|
|
PHP; |
|
102
|
|
|
|
|
103
|
|
|
self::assertSame($expectedCode, $method->getBody()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testBodyStructureWithProtectedProperties() : void |
|
107
|
|
|
{ |
|
108
|
|
|
$method = new BindProxyProperties( |
|
109
|
|
|
new ReflectionClass(ClassWithProtectedProperties::class), |
|
110
|
|
|
$this->prefixInterceptors, |
|
111
|
|
|
$this->suffixInterceptors |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
self::assertSame( |
|
115
|
|
|
'$this->property0 = & $localizedObject->property0; |
|
116
|
|
|
|
|
117
|
|
|
$this->property1 = & $localizedObject->property1; |
|
118
|
|
|
|
|
119
|
|
|
$this->property2 = & $localizedObject->property2; |
|
120
|
|
|
|
|
121
|
|
|
$this->property3 = & $localizedObject->property3; |
|
122
|
|
|
|
|
123
|
|
|
$this->property4 = & $localizedObject->property4; |
|
124
|
|
|
|
|
125
|
|
|
$this->property5 = & $localizedObject->property5; |
|
126
|
|
|
|
|
127
|
|
|
$this->property6 = & $localizedObject->property6; |
|
128
|
|
|
|
|
129
|
|
|
$this->property7 = & $localizedObject->property7; |
|
130
|
|
|
|
|
131
|
|
|
$this->property8 = & $localizedObject->property8; |
|
132
|
|
|
|
|
133
|
|
|
$this->property9 = & $localizedObject->property9; |
|
134
|
|
|
|
|
135
|
|
|
$this->pre = $prefixInterceptors; |
|
136
|
|
|
$this->post = $suffixInterceptors;', |
|
137
|
|
|
$method->getBody() |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testBodyStructureWithPrivateProperties() : void |
|
142
|
|
|
{ |
|
143
|
|
|
$method = new BindProxyProperties( |
|
144
|
|
|
new ReflectionClass(ClassWithPrivateProperties::class), |
|
145
|
|
|
$this->prefixInterceptors, |
|
146
|
|
|
$this->suffixInterceptors |
|
147
|
|
|
); |
|
148
|
|
|
|
|
149
|
|
|
self::assertSame( |
|
150
|
|
|
'\Closure::bind(function () use ($localizedObject) { |
|
151
|
|
|
$this->property0 = & $localizedObject->property0; |
|
152
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
153
|
|
|
|
|
154
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
155
|
|
|
$this->property1 = & $localizedObject->property1; |
|
156
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
157
|
|
|
|
|
158
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
159
|
|
|
$this->property2 = & $localizedObject->property2; |
|
160
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
161
|
|
|
|
|
162
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
163
|
|
|
$this->property3 = & $localizedObject->property3; |
|
164
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
165
|
|
|
|
|
166
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
167
|
|
|
$this->property4 = & $localizedObject->property4; |
|
168
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
169
|
|
|
|
|
170
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
171
|
|
|
$this->property5 = & $localizedObject->property5; |
|
172
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
173
|
|
|
|
|
174
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
175
|
|
|
$this->property6 = & $localizedObject->property6; |
|
176
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
177
|
|
|
|
|
178
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
179
|
|
|
$this->property7 = & $localizedObject->property7; |
|
180
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
181
|
|
|
|
|
182
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
183
|
|
|
$this->property8 = & $localizedObject->property8; |
|
184
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
185
|
|
|
|
|
186
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
187
|
|
|
$this->property9 = & $localizedObject->property9; |
|
188
|
|
|
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke(); |
|
189
|
|
|
|
|
190
|
|
|
$this->pre = $prefixInterceptors; |
|
191
|
|
|
$this->post = $suffixInterceptors;', |
|
192
|
|
|
$method->getBody() |
|
193
|
|
|
); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
public function testBodyStructureWithTypedProperties() : void |
|
197
|
|
|
{ |
|
198
|
|
|
$method = new BindProxyProperties( |
|
199
|
|
|
new ReflectionClass(ClassWithMixedReferenceableTypedProperties::class), |
|
200
|
|
|
$this->prefixInterceptors, |
|
201
|
|
|
$this->suffixInterceptors |
|
202
|
|
|
); |
|
203
|
|
|
|
|
204
|
|
|
self::assertSame( |
|
205
|
|
|
<<<'PHP' |
|
206
|
|
|
$this->publicUnTypedProperty = & $localizedObject->publicUnTypedProperty; |
|
207
|
|
|
|
|
208
|
|
|
$this->publicBoolProperty = & $localizedObject->publicBoolProperty; |
|
209
|
|
|
|
|
210
|
|
|
$this->publicNullableBoolProperty = & $localizedObject->publicNullableBoolProperty; |
|
211
|
|
|
|
|
212
|
|
|
$this->publicIntProperty = & $localizedObject->publicIntProperty; |
|
213
|
|
|
|
|
214
|
|
|
$this->publicNullableIntProperty = & $localizedObject->publicNullableIntProperty; |
|
215
|
|
|
|
|
216
|
|
|
$this->publicFloatProperty = & $localizedObject->publicFloatProperty; |
|
217
|
|
|
|
|
218
|
|
|
$this->publicNullableFloatProperty = & $localizedObject->publicNullableFloatProperty; |
|
219
|
|
|
|
|
220
|
|
|
$this->publicStringProperty = & $localizedObject->publicStringProperty; |
|
221
|
|
|
|
|
222
|
|
|
$this->publicNullableStringProperty = & $localizedObject->publicNullableStringProperty; |
|
223
|
|
|
|
|
224
|
|
|
$this->publicArrayProperty = & $localizedObject->publicArrayProperty; |
|
225
|
|
|
|
|
226
|
|
|
$this->publicNullableArrayProperty = & $localizedObject->publicNullableArrayProperty; |
|
227
|
|
|
|
|
228
|
|
|
$this->publicIterableProperty = & $localizedObject->publicIterableProperty; |
|
229
|
|
|
|
|
230
|
|
|
$this->publicNullableIterableProperty = & $localizedObject->publicNullableIterableProperty; |
|
231
|
|
|
|
|
232
|
|
|
$this->protectedUnTypedProperty = & $localizedObject->protectedUnTypedProperty; |
|
233
|
|
|
|
|
234
|
|
|
$this->protectedBoolProperty = & $localizedObject->protectedBoolProperty; |
|
235
|
|
|
|
|
236
|
|
|
$this->protectedNullableBoolProperty = & $localizedObject->protectedNullableBoolProperty; |
|
237
|
|
|
|
|
238
|
|
|
$this->protectedIntProperty = & $localizedObject->protectedIntProperty; |
|
239
|
|
|
|
|
240
|
|
|
$this->protectedNullableIntProperty = & $localizedObject->protectedNullableIntProperty; |
|
241
|
|
|
|
|
242
|
|
|
$this->protectedFloatProperty = & $localizedObject->protectedFloatProperty; |
|
243
|
|
|
|
|
244
|
|
|
$this->protectedNullableFloatProperty = & $localizedObject->protectedNullableFloatProperty; |
|
245
|
|
|
|
|
246
|
|
|
$this->protectedStringProperty = & $localizedObject->protectedStringProperty; |
|
247
|
|
|
|
|
248
|
|
|
$this->protectedNullableStringProperty = & $localizedObject->protectedNullableStringProperty; |
|
249
|
|
|
|
|
250
|
|
|
$this->protectedArrayProperty = & $localizedObject->protectedArrayProperty; |
|
251
|
|
|
|
|
252
|
|
|
$this->protectedNullableArrayProperty = & $localizedObject->protectedNullableArrayProperty; |
|
253
|
|
|
|
|
254
|
|
|
$this->protectedIterableProperty = & $localizedObject->protectedIterableProperty; |
|
255
|
|
|
|
|
256
|
|
|
$this->protectedNullableIterableProperty = & $localizedObject->protectedNullableIterableProperty; |
|
257
|
|
|
|
|
258
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
259
|
|
|
$this->privateUnTypedProperty = & $localizedObject->privateUnTypedProperty; |
|
260
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
261
|
|
|
|
|
262
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
263
|
|
|
$this->privateBoolProperty = & $localizedObject->privateBoolProperty; |
|
264
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
265
|
|
|
|
|
266
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
267
|
|
|
$this->privateNullableBoolProperty = & $localizedObject->privateNullableBoolProperty; |
|
268
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
269
|
|
|
|
|
270
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
271
|
|
|
$this->privateIntProperty = & $localizedObject->privateIntProperty; |
|
272
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
273
|
|
|
|
|
274
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
275
|
|
|
$this->privateNullableIntProperty = & $localizedObject->privateNullableIntProperty; |
|
276
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
277
|
|
|
|
|
278
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
279
|
|
|
$this->privateFloatProperty = & $localizedObject->privateFloatProperty; |
|
280
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
281
|
|
|
|
|
282
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
283
|
|
|
$this->privateNullableFloatProperty = & $localizedObject->privateNullableFloatProperty; |
|
284
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
285
|
|
|
|
|
286
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
287
|
|
|
$this->privateStringProperty = & $localizedObject->privateStringProperty; |
|
288
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
289
|
|
|
|
|
290
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
291
|
|
|
$this->privateNullableStringProperty = & $localizedObject->privateNullableStringProperty; |
|
292
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
293
|
|
|
|
|
294
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
295
|
|
|
$this->privateArrayProperty = & $localizedObject->privateArrayProperty; |
|
296
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
297
|
|
|
|
|
298
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
299
|
|
|
$this->privateNullableArrayProperty = & $localizedObject->privateNullableArrayProperty; |
|
300
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
301
|
|
|
|
|
302
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
303
|
|
|
$this->privateIterableProperty = & $localizedObject->privateIterableProperty; |
|
304
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
305
|
|
|
|
|
306
|
|
|
\Closure::bind(function () use ($localizedObject) { |
|
307
|
|
|
$this->privateNullableIterableProperty = & $localizedObject->privateNullableIterableProperty; |
|
308
|
|
|
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedReferenceableTypedProperties')->__invoke(); |
|
309
|
|
|
|
|
310
|
|
|
$this->pre = $prefixInterceptors; |
|
311
|
|
|
$this->post = $suffixInterceptors; |
|
312
|
|
|
PHP |
|
313
|
|
|
, |
|
|
|
|
|
|
314
|
|
|
$method->getBody() |
|
315
|
|
|
); |
|
316
|
|
|
} |
|
317
|
|
|
} |
|
318
|
|
|
|