1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\Generator\Util; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use ProxyManager\Generator\Util\ProxiedMethodReturnExpression; |
9
|
|
|
use ProxyManagerTestAsset\VoidMethodTypeHintedClass; |
10
|
|
|
use ReflectionMethod; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Test to {@see ProxyManager\Generator\Util\ProxiedMethodReturnExpression} |
14
|
|
|
* |
15
|
|
|
* @covers \ProxyManager\Generator\Util\ProxiedMethodReturnExpression |
16
|
|
|
* @group Coverage |
17
|
|
|
*/ |
18
|
|
|
final class ProxiedMethodReturnExpressionTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @dataProvider returnExpressionsProvider |
22
|
|
|
*/ |
23
|
|
|
public function testGeneratedReturnExpression( |
24
|
|
|
string $expression, |
25
|
|
|
?ReflectionMethod $originalMethod, |
26
|
|
|
string $expectedGeneratedCode |
27
|
|
|
) : void { |
28
|
|
|
self::assertSame($expectedGeneratedCode, ProxiedMethodReturnExpression::generate($expression, $originalMethod)); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @psalm-return array<string, array{0: string, 1: ReflectionMethod|null, 2: string}> |
33
|
|
|
*/ |
34
|
|
|
public function returnExpressionsProvider() : array |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
'variable, no original method' => [ |
38
|
|
|
'$foo', |
39
|
|
|
null, |
40
|
|
|
'return $foo;', |
41
|
|
|
], |
42
|
|
|
'variable, given non-void original method' => [ |
43
|
|
|
'$foo', |
44
|
|
|
new ReflectionMethod(self::class, 'returnExpressionsProvider'), |
45
|
|
|
'return $foo;', |
46
|
|
|
], |
47
|
|
|
'variable, given void original method' => [ |
48
|
|
|
'$foo', |
49
|
|
|
new ReflectionMethod(VoidMethodTypeHintedClass::class, 'returnVoid'), |
50
|
|
|
"\$foo;\nreturn;", |
51
|
|
|
], |
52
|
|
|
'expression, no original method' => [ |
53
|
|
|
'(1 + 1)', |
54
|
|
|
null, |
55
|
|
|
'return (1 + 1);', |
56
|
|
|
], |
57
|
|
|
'expression, given non-void original method' => [ |
58
|
|
|
'(1 + 1)', |
59
|
|
|
new ReflectionMethod(self::class, 'returnExpressionsProvider'), |
60
|
|
|
'return (1 + 1);', |
61
|
|
|
], |
62
|
|
|
'expression, given void original method' => [ |
63
|
|
|
'(1 + 1)', |
64
|
|
|
new ReflectionMethod(VoidMethodTypeHintedClass::class, 'returnVoid'), |
65
|
|
|
"(1 + 1);\nreturn;", |
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.