1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\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\Generator\MethodGenerator; |
12
|
|
|
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod; |
13
|
|
|
use ProxyManagerTestAsset\BaseClass; |
14
|
|
|
use ProxyManagerTestAsset\ClassWithMethodWithVariadicFunction; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod} |
18
|
|
|
* |
19
|
|
|
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod |
20
|
|
|
* @group Coverage |
21
|
|
|
*/ |
22
|
|
|
final class InterceptedMethodTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** @var PropertyGenerator&MockObject */ |
25
|
|
|
private PropertyGenerator $prefixInterceptors; |
|
|
|
|
26
|
|
|
|
27
|
|
|
/** @var PropertyGenerator&MockObject */ |
28
|
|
|
private PropertyGenerator $suffixInterceptors; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
|
|
protected function setUp() : void |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
|
37
|
|
|
$this->prefixInterceptors = $this->createMock(PropertyGenerator::class); |
38
|
|
|
$this->suffixInterceptors = $this->createMock(PropertyGenerator::class); |
39
|
|
|
|
40
|
|
|
$this->prefixInterceptors->method('getName')->willReturn('pre'); |
41
|
|
|
$this->suffixInterceptors->method('getName')->willReturn('post'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testBodyStructure() : void |
45
|
|
|
{ |
46
|
|
|
$method = InterceptedMethod::generateMethod( |
47
|
|
|
new MethodReflection(BaseClass::class, 'publicByReferenceParameterMethod'), |
48
|
|
|
$this->prefixInterceptors, |
49
|
|
|
$this->suffixInterceptors |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
self::assertSame('publicByReferenceParameterMethod', $method->getName()); |
53
|
|
|
self::assertCount(2, $method->getParameters()); |
54
|
|
|
self::assertStringMatchesFormat( |
55
|
|
|
'%a$returnValue = parent::publicByReferenceParameterMethod($param, $byRefParam);%A', |
56
|
|
|
$method->getBody() |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testForwardsVariadicParameters() : void |
61
|
|
|
{ |
62
|
|
|
$method = InterceptedMethod::generateMethod( |
63
|
|
|
new MethodReflection(ClassWithMethodWithVariadicFunction::class, 'foo'), |
64
|
|
|
$this->prefixInterceptors, |
65
|
|
|
$this->suffixInterceptors |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
self::assertSame('foo', $method->getName()); |
69
|
|
|
self::assertCount(2, $method->getParameters()); |
70
|
|
|
self::assertStringMatchesFormat( |
71
|
|
|
'%a$returnValue = parent::foo($bar, ...$baz);%A', |
72
|
|
|
$method->getBody() |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|