Completed
Push — master ( 2f25cf...59cc7f )
by Marco
43:54 queued 18:55
created

testBodyStructureWithTypedProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 9.344
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator\NullObject\MethodGenerator;
6
7
use PHPUnit\Framework\TestCase;
8
use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor;
9
use ProxyManagerTestAsset\ClassWithMixedProperties;
10
use ProxyManagerTestAsset\ClassWithMixedTypedProperties;
11
use ProxyManagerTestAsset\ClassWithPrivateProperties;
12
use ReflectionClass;
13
14
/**
15
 * Tests for {@see \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor}
16
 *
17
 * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor
18
 * @group Coverage
19
 */
20
class StaticProxyConstructorTest extends TestCase
21
{
22
    public function testBodyStructure() : void
23
    {
24
        $constructor = new StaticProxyConstructor(
25
            new ReflectionClass(ClassWithMixedProperties::class)
26
        );
27
28
        self::assertSame('staticProxyConstructor', $constructor->getName());
29
        self::assertSame(ClassWithMixedProperties::class, (string) $constructor->getReturnType());
30
        self::assertTrue($constructor->isStatic());
31
        self::assertSame('public', $constructor->getVisibility());
32
        self::assertCount(0, $constructor->getParameters());
33
        self::assertSame(
34
            'static $reflection;
35
36
$reflection = $reflection ?? new \ReflectionClass(__CLASS__);
37
$instance   = $reflection->newInstanceWithoutConstructor();
38
39
$instance->publicProperty0 = null;
40
$instance->publicProperty1 = null;
41
$instance->publicProperty2 = null;
42
43
return $instance;',
44
            $constructor->getBody()
45
        );
46
    }
47
48
    public function testBodyStructureWithoutPublicProperties() : void
49
    {
50
        $constructor = new StaticProxyConstructor(
51
            new ReflectionClass(ClassWithPrivateProperties::class)
52
        );
53
54
        self::assertSame('staticProxyConstructor', $constructor->getName());
55
        self::assertCount(0, $constructor->getParameters());
56
        self::assertSame(ClassWithPrivateProperties::class, (string) $constructor->getReturnType());
57
        $body = $constructor->getBody();
58
        self::assertSame(
59
            'static $reflection;
60
61
$reflection = $reflection ?? new \ReflectionClass(__CLASS__);
62
$instance   = $reflection->newInstanceWithoutConstructor();
63
64
return $instance;',
65
            $body
66
        );
67
    }
68
    public function testBodyStructureWithTypedProperties() : void
69
    {
70
        $constructor = new StaticProxyConstructor(new ReflectionClass(ClassWithMixedTypedProperties::class));
71
72
        self::assertSame('staticProxyConstructor', $constructor->getName());
73
        self::assertSame(ClassWithMixedTypedProperties::class, (string) $constructor->getReturnType());
74
        self::assertTrue($constructor->isStatic());
75
        self::assertSame('public', $constructor->getVisibility());
76
        self::assertCount(0, $constructor->getParameters());
77
        self::assertSame(
78
            'static $reflection;
79
80
$reflection = $reflection ?? new \ReflectionClass(__CLASS__);
81
$instance   = $reflection->newInstanceWithoutConstructor();
82
83
$instance->publicUnTypedProperty = null;
84
$instance->publicUnTypedPropertyWithoutDefaultValue = null;
85
$instance->publicNullableBoolProperty = null;
86
$instance->publicNullableBoolPropertyWithoutDefaultValue = null;
87
$instance->publicNullableIntProperty = null;
88
$instance->publicNullableIntPropertyWithoutDefaultValue = null;
89
$instance->publicNullableFloatProperty = null;
90
$instance->publicNullableFloatPropertyWithoutDefaultValue = null;
91
$instance->publicNullableStringProperty = null;
92
$instance->publicNullableStringPropertyWithoutDefaultValue = null;
93
$instance->publicNullableArrayProperty = null;
94
$instance->publicNullableArrayPropertyWithoutDefaultValue = null;
95
$instance->publicNullableIterableProperty = null;
96
$instance->publicNullableIterablePropertyWithoutDefaultValue = null;
97
$instance->publicNullableObjectProperty = null;
98
$instance->publicNullableClassProperty = null;
99
100
return $instance;',
101
            $constructor->getBody()
102
        );
103
    }
104
}
105