1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
declare(strict_types=1); |
20
|
|
|
|
21
|
|
|
namespace ProxyManagerTest\Generator\Util; |
22
|
|
|
|
23
|
|
|
use PHPUnit_Framework_TestCase; |
24
|
|
|
use ProxyManager\Generator\Util\ProxiedMethodReturnExpression; |
25
|
|
|
use ProxyManagerTestAsset\VoidMethodTypeHintedClass; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Test to {@see ProxyManager\Generator\Util\ProxiedMethodReturnExpression} |
29
|
|
|
* |
30
|
|
|
* @author Marco Pivetta <[email protected]> |
31
|
|
|
* @license MIT |
32
|
|
|
* |
33
|
|
|
* @covers \ProxyManager\Generator\Util\ProxiedMethodReturnExpression |
34
|
|
|
* |
35
|
|
|
* @group Coverage |
36
|
|
|
*/ |
37
|
|
|
class ProxiedMethodReturnExpressionTest extends PHPUnit_Framework_TestCase |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* @dataProvider returnExpressionsProvider |
41
|
|
|
* |
42
|
|
|
* @param string $expression |
43
|
|
|
* @param null|\ReflectionMethod $originalMethod |
44
|
|
|
* @param string $expectedGeneratedCode |
45
|
|
|
*/ |
46
|
|
|
public function testGeneratedReturnExpression( |
47
|
|
|
string $expression, |
48
|
|
|
?\ReflectionMethod $originalMethod, |
49
|
|
|
string $expectedGeneratedCode |
50
|
|
|
) : void { |
51
|
|
|
self::assertSame($expectedGeneratedCode, ProxiedMethodReturnExpression::generate($expression, $originalMethod)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function returnExpressionsProvider() : array |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
'variable, no original method' => [ |
58
|
|
|
'$foo', |
59
|
|
|
null, |
60
|
|
|
'return $foo;' |
61
|
|
|
], |
62
|
|
|
'variable, given non-void original method' => [ |
63
|
|
|
'$foo', |
64
|
|
|
new \ReflectionMethod(self::class, 'returnExpressionsProvider'), |
65
|
|
|
'return $foo;' |
66
|
|
|
], |
67
|
|
|
'variable, given void original method' => [ |
68
|
|
|
'$foo', |
69
|
|
|
new \ReflectionMethod(VoidMethodTypeHintedClass::class, 'returnVoid'), |
70
|
|
|
"\$foo;\nreturn;" |
71
|
|
|
], |
72
|
|
|
'expression, no original method' => [ |
73
|
|
|
'(1 + 1)', |
74
|
|
|
null, |
75
|
|
|
'return (1 + 1);' |
76
|
|
|
], |
77
|
|
|
'expression, given non-void original method' => [ |
78
|
|
|
'(1 + 1)', |
79
|
|
|
new \ReflectionMethod(self::class, 'returnExpressionsProvider'), |
80
|
|
|
'return (1 + 1);' |
81
|
|
|
], |
82
|
|
|
'expression, given void original method' => [ |
83
|
|
|
'(1 + 1)', |
84
|
|
|
new \ReflectionMethod(VoidMethodTypeHintedClass::class, 'returnVoid'), |
85
|
|
|
"(1 + 1);\nreturn;" |
86
|
|
|
], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|