1 | <?php |
||
49 | class RemoteObjectFunctionalTest extends PHPUnit_Framework_TestCase |
||
50 | { |
||
51 | /** |
||
52 | * @param mixed $expectedValue |
||
53 | * @param string $method |
||
54 | * @param array $params |
||
55 | * |
||
56 | * @return XmlRpcAdapter |
||
57 | */ |
||
58 | protected function getXmlRpcAdapter($expectedValue, string $method, array $params) : XmlRpcAdapter |
||
79 | |||
80 | /** |
||
81 | * @param mixed $expectedValue |
||
82 | * @param string $method |
||
83 | * @param array $params |
||
84 | * |
||
85 | * @return JsonRpcAdapter |
||
86 | */ |
||
87 | protected function getJsonRpcAdapter($expectedValue, string $method, array $params) : JsonRpcAdapter |
||
108 | |||
109 | /** |
||
110 | * @dataProvider getProxyMethods |
||
111 | * |
||
112 | * @param string|object $instanceOrClassName |
||
113 | * @param string $method |
||
114 | * @param mixed[] $params |
||
115 | * @param mixed $expectedValue |
||
116 | */ |
||
117 | public function testXmlRpcMethodCalls($instanceOrClassName, string $method, array $params, $expectedValue) : void |
||
126 | |||
127 | /** |
||
128 | * @dataProvider getProxyMethods |
||
129 | * |
||
130 | * @param string|object $instanceOrClassName |
||
131 | * @param string $method |
||
132 | * @param mixed[] $params |
||
133 | * @param mixed $expectedValue |
||
134 | */ |
||
135 | public function testJsonRpcMethodCalls($instanceOrClassName, string $method, array $params, $expectedValue) : void |
||
144 | |||
145 | /** |
||
146 | * @dataProvider getPropertyAccessProxies |
||
147 | * |
||
148 | * @param string|object $instanceOrClassName |
||
149 | * @param string $publicProperty |
||
150 | * @param string $propertyValue |
||
151 | */ |
||
152 | public function testJsonRpcPropertyReadAccess($instanceOrClassName, string $publicProperty, $propertyValue) : void |
||
164 | |||
165 | /** |
||
166 | * Generates a proxy for the given class name, and retrieves its class name |
||
167 | * |
||
168 | * @param string|object $parentClassName |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | private function generateProxy($parentClassName) : string |
||
184 | |||
185 | /** |
||
186 | * Generates a list of object | invoked method | parameters | expected result |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | public function getProxyMethods() : array |
||
227 | |||
228 | /** |
||
229 | * Generates proxies and instances with a public property to feed to the property accessor methods |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | public function getPropertyAccessProxies() : array |
||
243 | |||
244 | /** |
||
245 | * @group 276 |
||
246 | * |
||
247 | * @dataProvider getMethodsThatAccessPropertiesOnOtherObjectsInTheSameScope |
||
248 | * |
||
249 | * @param object $callerObject |
||
250 | * @param object $realInstance |
||
251 | * @param string $method |
||
252 | * @param string $expectedValue |
||
253 | * @param string $propertyName |
||
254 | */ |
||
255 | public function testWillInterceptAccessToPropertiesViaFriendClassAccess( |
||
256 | $callerObject, |
||
257 | $realInstance, |
||
258 | string $method, |
||
259 | string $expectedValue, |
||
260 | string $propertyName |
||
261 | ) : void { |
||
262 | $proxyName = $this->generateProxy(get_class($realInstance)); |
||
263 | |||
264 | /* @var $adapter AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */ |
||
265 | $adapter = $this->createMock(AdapterInterface::class); |
||
266 | |||
267 | $adapter |
||
268 | ->expects(self::once()) |
||
269 | ->method('call') |
||
270 | ->with(get_class($realInstance), '__get', [$propertyName]) |
||
271 | ->willReturn($expectedValue); |
||
272 | |||
273 | /* @var $proxy OtherObjectAccessClass|RemoteObjectInterface */ |
||
274 | $proxy = $proxyName::staticProxyConstructor($adapter); |
||
275 | |||
276 | /* @var $accessor callable */ |
||
277 | $accessor = [$callerObject, $method]; |
||
278 | |||
279 | self::assertSame($expectedValue, $accessor($proxy)); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * @group 276 |
||
284 | * |
||
285 | * @dataProvider getMethodsThatAccessPropertiesOnOtherObjectsInTheSameScope |
||
286 | * |
||
287 | * @param object $callerObject |
||
288 | * @param object $realInstance |
||
289 | * @param string $method |
||
290 | * @param string $expectedValue |
||
291 | * @param string $propertyName |
||
292 | */ |
||
293 | public function testWillInterceptAccessToPropertiesViaFriendClassAccessEvenIfCloned( |
||
294 | $callerObject, |
||
295 | $realInstance, |
||
296 | string $method, |
||
297 | string $expectedValue, |
||
298 | string $propertyName |
||
299 | ) : void { |
||
300 | $proxyName = $this->generateProxy(get_class($realInstance)); |
||
301 | |||
302 | /* @var $adapter AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */ |
||
303 | $adapter = $this->createMock(AdapterInterface::class); |
||
304 | |||
305 | $adapter |
||
306 | ->expects(self::once()) |
||
307 | ->method('call') |
||
308 | ->with(get_class($realInstance), '__get', [$propertyName]) |
||
309 | ->willReturn($expectedValue); |
||
310 | |||
311 | /* @var $proxy OtherObjectAccessClass|RemoteObjectInterface */ |
||
312 | $proxy = clone $proxyName::staticProxyConstructor($adapter); |
||
313 | |||
314 | /* @var $accessor callable */ |
||
315 | $accessor = [$callerObject, $method]; |
||
316 | |||
317 | self::assertSame($expectedValue, $accessor($proxy)); |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @group 327 |
||
322 | */ |
||
323 | public function testWillExecuteLogicInAVoidMethod() : void |
||
343 | |||
344 | public function getMethodsThatAccessPropertiesOnOtherObjectsInTheSameScope() : \Generator |
||
364 | } |
||
365 |