Completed
Push — master ( 3be072...ba2d3a )
by Marco
231:32 queued 209:55
created

InterceptedMethodTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
6
7
use PHPUnit\Framework\MockObject\MockObject;
8
use PHPUnit\Framework\TestCase;
9
use ProxyManager\Generator\MethodGenerator;
10
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod;
11
use ProxyManagerTestAsset\BaseClass;
12
use ProxyManagerTestAsset\ClassWithMethodWithVariadicFunction;
13
use Zend\Code\Generator\PropertyGenerator;
14
use Zend\Code\Reflection\MethodReflection;
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;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
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::assertInstanceOf(MethodGenerator::class, $method);
53
54
        self::assertSame('publicByReferenceParameterMethod', $method->getName());
55
        self::assertCount(2, $method->getParameters());
56
        self::assertStringMatchesFormat(
57
            '%a$returnValue = parent::publicByReferenceParameterMethod($param, $byRefParam);%A',
58
            $method->getBody()
59
        );
60
    }
61
62
    public function testForwardsVariadicParameters() : void
63
    {
64
        $method = InterceptedMethod::generateMethod(
65
            new MethodReflection(ClassWithMethodWithVariadicFunction::class, 'foo'),
66
            $this->prefixInterceptors,
67
            $this->suffixInterceptors
68
        );
69
70
        self::assertInstanceOf(MethodGenerator::class, $method);
71
72
        self::assertSame('foo', $method->getName());
73
        self::assertCount(2, $method->getParameters());
74
        self::assertStringMatchesFormat(
75
            '%a$returnValue = parent::foo($bar, ...$baz);%A',
76
            $method->getBody()
77
        );
78
    }
79
}
80