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

StaticProxyConstructorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 54
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\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor;
10
use ProxyManagerTestAsset\ClassWithProtectedProperties;
11
use ProxyManagerTestAsset\ClassWithPublicProperties;
12
use ReflectionClass;
13
use Zend\Code\Generator\PropertyGenerator;
14
15
/**
16
 * Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor}
17
 *
18
 * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor
19
 * @group Coverage
20
 */
21
final class StaticProxyConstructorTest extends TestCase
22
{
23
    /** @var PropertyGenerator&MockObject */
24
    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...
25
26
    /** @var PropertyGenerator&MockObject */
27
    private PropertyGenerator $suffixInterceptors;
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    protected function setUp() : void
33
    {
34
        $this->prefixInterceptors = $this->createMock(PropertyGenerator::class);
35
        $this->suffixInterceptors = $this->createMock(PropertyGenerator::class);
36
37
        $this->prefixInterceptors->method('getName')->willReturn('pre');
38
        $this->suffixInterceptors->method('getName')->willReturn('post');
39
    }
40
41
    public function testSignature() : void
42
    {
43
        $method = new StaticProxyConstructor(new ReflectionClass(ClassWithProtectedProperties::class));
44
45
        self::assertSame('staticProxyConstructor', $method->getName());
46
        self::assertTrue($method->isStatic());
47
        self::assertSame('public', $method->getVisibility());
48
49
        $parameters = $method->getParameters();
50
51
        self::assertCount(3, $parameters);
52
53
        self::assertSame(ClassWithProtectedProperties::class, $parameters['localizedObject']->getType());
54
        self::assertSame('array', $parameters['prefixInterceptors']->getType());
55
        self::assertSame('array', $parameters['suffixInterceptors']->getType());
56
    }
57
58
    public function testBodyStructure() : void
59
    {
60
        $method = new StaticProxyConstructor(new ReflectionClass(ClassWithPublicProperties::class));
61
62
        self::assertSame(
63
            'static $reflection;
64
65
$reflection = $reflection ?? new \ReflectionClass(__CLASS__);
66
$instance   = $reflection->newInstanceWithoutConstructor();
67
68
$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors);
69
70
return $instance;',
71
            $method->getBody()
72
        );
73
    }
74
}
75