|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use Laminas\Code\Generator\PropertyGenerator; |
|
8
|
|
|
use Laminas\Code\Reflection\MethodReflection; |
|
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod; |
|
12
|
|
|
use ProxyManagerTestAsset\BaseClass; |
|
13
|
|
|
use ReflectionClass; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod} |
|
17
|
|
|
* |
|
18
|
|
|
* @group Coverage |
|
19
|
|
|
*/ |
|
20
|
|
|
final class RemoteObjectMethodTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testBodyStructureWithParameters() : void |
|
26
|
|
|
{ |
|
27
|
|
|
$adapter = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
28
|
|
|
$adapter->method('getName')->willReturn('adapter'); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
$reflectionMethod = new MethodReflection( |
|
31
|
|
|
BaseClass::class, |
|
32
|
|
|
'publicByReferenceParameterMethod' |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$method = RemoteObjectMethod::generateMethod( |
|
36
|
|
|
$reflectionMethod, |
|
37
|
|
|
$adapter, |
|
|
|
|
|
|
38
|
|
|
new ReflectionClass(PropertyGenerator::class) |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
self::assertSame('publicByReferenceParameterMethod', $method->getName()); |
|
|
|
|
|
|
42
|
|
|
self::assertCount(2, $method->getParameters()); |
|
|
|
|
|
|
43
|
|
|
self::assertSame( |
|
|
|
|
|
|
44
|
|
|
'$defaultValues = array ( |
|
45
|
|
|
0 => NULL, |
|
46
|
|
|
1 => NULL, |
|
47
|
|
|
); |
|
48
|
|
|
$declaredParameterCount = 2; |
|
49
|
|
|
|
|
50
|
|
|
$args = \func_get_args() + $defaultValues; |
|
51
|
|
|
|
|
52
|
|
|
$return = $this->adapter->call(\'Laminas\\\\Code\\\\Generator\\\\PropertyGenerator\', \'publicByReferenceParameterMethod\', $args); |
|
53
|
|
|
|
|
54
|
|
|
return $return;', |
|
55
|
|
|
$method->getBody() |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testBodyStructureWithArrayParameter() : void |
|
63
|
|
|
{ |
|
64
|
|
|
$adapter = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
65
|
|
|
$adapter->method('getName')->willReturn('adapter'); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$reflectionMethod = new MethodReflection(BaseClass::class, 'publicArrayHintedMethod'); |
|
68
|
|
|
|
|
69
|
|
|
$method = RemoteObjectMethod::generateMethod( |
|
70
|
|
|
$reflectionMethod, |
|
71
|
|
|
$adapter, |
|
|
|
|
|
|
72
|
|
|
new ReflectionClass(PropertyGenerator::class) |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
self::assertSame('publicArrayHintedMethod', $method->getName()); |
|
|
|
|
|
|
76
|
|
|
self::assertCount(1, $method->getParameters()); |
|
|
|
|
|
|
77
|
|
|
self::assertSame( |
|
|
|
|
|
|
78
|
|
|
"\$defaultValues = array ( |
|
79
|
|
|
0 => NULL, |
|
80
|
|
|
); |
|
81
|
|
|
\$declaredParameterCount = 1; |
|
82
|
|
|
|
|
83
|
|
|
\$args = \\func_get_args() + \$defaultValues; |
|
84
|
|
|
|
|
85
|
|
|
\$return = \$this->adapter->call('Laminas\\\\Code\\\\Generator\\\\PropertyGenerator', 'publicArrayHintedMethod', \$args); |
|
86
|
|
|
|
|
87
|
|
|
return \$return;", |
|
88
|
|
|
$method->getBody() |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod |
|
94
|
|
|
*/ |
|
95
|
|
|
public function testBodyStructureWithoutParameters() : void |
|
96
|
|
|
{ |
|
97
|
|
|
$adapter = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
98
|
|
|
$adapter->method('getName')->willReturn('adapter'); |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
$reflectionMethod = new MethodReflection(BaseClass::class, 'publicMethod'); |
|
101
|
|
|
|
|
102
|
|
|
$method = RemoteObjectMethod::generateMethod( |
|
103
|
|
|
$reflectionMethod, |
|
104
|
|
|
$adapter, |
|
|
|
|
|
|
105
|
|
|
new ReflectionClass(PropertyGenerator::class) |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
self::assertSame('publicMethod', $method->getName()); |
|
|
|
|
|
|
109
|
|
|
self::assertCount(0, $method->getParameters()); |
|
|
|
|
|
|
110
|
|
|
self::assertSame( |
|
|
|
|
|
|
111
|
|
|
"\$defaultValues = array ( |
|
112
|
|
|
); |
|
113
|
|
|
\$declaredParameterCount = 0; |
|
114
|
|
|
|
|
115
|
|
|
\$args = \\func_get_args() + \$defaultValues; |
|
116
|
|
|
|
|
117
|
|
|
\$return = \$this->adapter->call('Laminas\\\\Code\\\\Generator\\\\PropertyGenerator', 'publicMethod', \$args); |
|
118
|
|
|
|
|
119
|
|
|
return \$return;", |
|
120
|
|
|
$method->getBody() |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.