RemoteObjectGeneratorTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeneratesValidCode() 0 27 3
A getProxyGenerator() 0 4 1
A getExpectedImplementedInterfaces() 0 6 1
A getTestedImplementations() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator;
6
7
use ProxyManager\Generator\ClassGenerator;
8
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
9
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
10
use ProxyManager\Proxy\RemoteObjectInterface;
11
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
12
use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
13
use ProxyManagerTestAsset\BaseClass;
14
use ProxyManagerTestAsset\BaseInterface;
15
use ProxyManagerTestAsset\ClassWithByRefMagicMethods;
16
use ProxyManagerTestAsset\ClassWithMagicMethods;
17
use ProxyManagerTestAsset\ClassWithMixedProperties;
18
use ProxyManagerTestAsset\ClassWithMixedReferenceableTypedProperties;
19
use ProxyManagerTestAsset\ClassWithMixedTypedProperties;
20
use ReflectionClass;
21
use function array_diff;
22
23
/**
24
 * Tests for {@see \ProxyManager\ProxyGenerator\RemoteObjectGenerator}
25
 *
26
 * @covers \ProxyManager\ProxyGenerator\RemoteObjectGenerator
27
 * @group Coverage
28
 */
29
final class RemoteObjectGeneratorTest extends AbstractProxyGeneratorTest
30
{
31
    /**
32
     * @dataProvider getTestedImplementations
33
     *
34
     * Verifies that generated code is valid and implements expected interfaces
35
     */
36
    public function testGeneratesValidCode(string $className) : void
37
    {
38
        $generator          = $this->getProxyGenerator();
39
        $generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest');
40
        $generatedClass     = new ClassGenerator($generatedClassName);
41
        $originalClass      = new ReflectionClass($className);
42
        $generatorStrategy  = new EvaluatingGeneratorStrategy();
43
44
        $generator->generate($originalClass, $generatedClass);
45
        $generatorStrategy->generate($generatedClass);
46
47
        $generatedReflection = new ReflectionClass($generatedClassName);
48
49
        if ($originalClass->isInterface()) {
50
            self::assertTrue($generatedReflection->implementsInterface($className));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProxyManagerTest\...oteObjectGeneratorTest>.

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...
51
        } else {
52
            self::assertEmpty(
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<ProxyManagerTest\...oteObjectGeneratorTest>.

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...
53
                array_diff($originalClass->getInterfaceNames(), $generatedReflection->getInterfaceNames())
54
            );
55
        }
56
57
        self::assertSame($generatedClassName, $generatedReflection->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...oteObjectGeneratorTest>.

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...
58
59
        foreach ($this->getExpectedImplementedInterfaces() as $interface) {
60
            self::assertTrue($generatedReflection->implementsInterface($interface));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProxyManagerTest\...oteObjectGeneratorTest>.

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...
61
        }
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67
    protected function getProxyGenerator() : ProxyGeneratorInterface
68
    {
69
        return new RemoteObjectGenerator();
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75
    protected function getExpectedImplementedInterfaces() : array
76
    {
77
        return [
78
            RemoteObjectInterface::class,
79
        ];
80
    }
81
82
    /** @return string[][] */
83
    public function getTestedImplementations() : array
84
    {
85
        return [
86
            [BaseClass::class],
87
            [ClassWithMagicMethods::class],
88
            [ClassWithByRefMagicMethods::class],
89
            [ClassWithMixedProperties::class],
90
            [ClassWithMixedTypedProperties::class],
91
            [ClassWithMixedReferenceableTypedProperties::class],
92
            [BaseInterface::class],
93
        ];
94
    }
95
}
96