AccessInterceptorScopeLocalizerTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeneratesValidCode() 0 15 3
A testWillRejectInterfaces() 0 8 1
A getProxyGenerator() 0 4 1
A getExpectedImplementedInterfaces() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator;
6
7
use Laminas\Code\Generator\ClassGenerator;
8
use ProxyManager\Exception\InvalidProxiedClassException;
9
use ProxyManager\Exception\UnsupportedProxiedClassException;
10
use ProxyManager\Proxy\AccessInterceptorInterface;
11
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator;
12
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
13
use ProxyManagerTestAsset\BaseInterface;
14
use ProxyManagerTestAsset\ClassWithMixedTypedProperties;
15
use ReflectionClass;
16
17
/**
18
 * Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator}
19
 *
20
 * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator
21
 * @group Coverage
22
 */
23
final class AccessInterceptorScopeLocalizerTest extends AbstractProxyGeneratorTest
24
{
25
    /**
26
     * @dataProvider getTestedImplementations
27
     *
28
     * {@inheritDoc}
29
     */
30
    public function testGeneratesValidCode(string $className) : void
31
    {
32
        $reflectionClass = new ReflectionClass($className);
33
34
        if ($reflectionClass->isInterface()) {
35
            // @todo interfaces *may* be proxied by deferring property localization to the constructor (no hardcoding)
36
            $this->expectException(InvalidProxiedClassException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<ProxyManagerTest\...ptorScopeLocalizerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
        }
38
39
        if ($reflectionClass->getName() === ClassWithMixedTypedProperties::class) {
40
            $this->expectException(UnsupportedProxiedClassException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<ProxyManagerTest\...ptorScopeLocalizerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        }
42
43
        parent::testGeneratesValidCode($className);
44
    }
45
46
    public function testWillRejectInterfaces() : void
47
    {
48
        $this->expectException(InvalidProxiedClassException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<ProxyManagerTest\...ptorScopeLocalizerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
50
        $this
51
            ->getProxyGenerator()
52
            ->generate(new ReflectionClass(BaseInterface::class), new ClassGenerator());
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    protected function getProxyGenerator() : ProxyGeneratorInterface
59
    {
60
        return new AccessInterceptorScopeLocalizerGenerator();
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    protected function getExpectedImplementedInterfaces() : array
67
    {
68
        return [AccessInterceptorInterface::class];
69
    }
70
}
71