|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\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\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor; |
|
12
|
|
|
use ProxyManagerTestAsset\BaseClass; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor} |
|
16
|
|
|
* |
|
17
|
|
|
* @group Coverage |
|
18
|
|
|
*/ |
|
19
|
|
|
final class LazyLoadingMethodInterceptorTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testBodyStructure() : void |
|
25
|
|
|
{ |
|
26
|
|
|
$initializer = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
27
|
|
|
$valueHolder = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$initializer->method('getName')->willReturn('foo'); |
|
|
|
|
|
|
30
|
|
|
$valueHolder->method('getName')->willReturn('bar'); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
$reflection = new MethodReflection(BaseClass::class, 'publicByReferenceParameterMethod'); |
|
33
|
|
|
$method = LazyLoadingMethodInterceptor::generateMethod($reflection, $initializer, $valueHolder); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
self::assertSame('publicByReferenceParameterMethod', $method->getName()); |
|
|
|
|
|
|
36
|
|
|
self::assertCount(2, $method->getParameters()); |
|
|
|
|
|
|
37
|
|
|
self::assertSame( |
|
|
|
|
|
|
38
|
|
|
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, 'publicByReferenceParameterMethod', " |
|
39
|
|
|
. "array('param' => \$param, 'byRefParam' => \$byRefParam), \$this->foo);\n\n" |
|
40
|
|
|
. 'return $this->bar->publicByReferenceParameterMethod($param, $byRefParam);', |
|
41
|
|
|
$method->getBody() |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testBodyStructureWithoutParameters() : void |
|
49
|
|
|
{ |
|
50
|
|
|
$reflectionMethod = new MethodReflection(BaseClass::class, 'publicMethod'); |
|
51
|
|
|
$initializer = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
52
|
|
|
$valueHolder = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$initializer->method('getName')->willReturn('foo'); |
|
|
|
|
|
|
55
|
|
|
$valueHolder->method('getName')->willReturn('bar'); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$initializer->method('getName')->willReturn('foo'); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$method = LazyLoadingMethodInterceptor::generateMethod($reflectionMethod, $initializer, $valueHolder); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
self::assertSame('publicMethod', $method->getName()); |
|
|
|
|
|
|
62
|
|
|
self::assertCount(0, $method->getParameters()); |
|
|
|
|
|
|
63
|
|
|
self::assertSame( |
|
|
|
|
|
|
64
|
|
|
'$this->foo && $this->foo->__invoke($this->bar, $this, ' |
|
65
|
|
|
. "'publicMethod', array(), \$this->foo);\n\n" |
|
66
|
|
|
. 'return $this->bar->publicMethod();', |
|
67
|
|
|
$method->getBody() |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
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.