Completed
Pull Request — 1.3.x (#103)
by
unknown
04:23
created

RuntimeReflectionServiceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests_PHP74\Persistence\Mapping;
6
7
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty;
8
use Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty;
9
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
10
use PHPUnit\Framework\TestCase;
11
use ReflectionProperty;
12
13
/**
14
 * @group DCOM-93
15
 */
16
class RuntimeReflectionServiceTest extends TestCase
17
{
18
    /** @var RuntimeReflectionService */
19
    private $reflectionService;
20
21
    /** @var string */
22
    private string $typedNoDefaultProperty;
0 ignored issues
show
introduced by
The private property $typedNoDefaultProperty is not used, and could be removed.
Loading history...
23
    /** @var string */
24
    private string $typedDefaultProperty = '';
0 ignored issues
show
introduced by
The private property $typedDefaultProperty is not used, and could be removed.
Loading history...
25
    /** @var string */
26
    private $nonTypedNoDefaultProperty;
0 ignored issues
show
introduced by
The private property $nonTypedNoDefaultProperty is not used, and could be removed.
Loading history...
introduced by
Class RuntimeReflectionServiceTest contains unused property $nonTypedNoDefaultProperty.
Loading history...
27
    /** @var string */
28
    private $nonTypedDefaultProperty = '';
0 ignored issues
show
introduced by
The private property $nonTypedDefaultProperty is not used, and could be removed.
Loading history...
introduced by
Class RuntimeReflectionServiceTest contains unused property $nonTypedDefaultProperty.
Loading history...
29
30
    /** @var string */
31
    public string $typedNoDefaultPublicProperty;
32
    /** @var string */
33
    public string $typedDefaultPublicProperty = '';
34
    /** @var string */
35
    public $nonTypedNoDefaultPublicProperty;
36
    /** @var string */
37
    public $nonTypedDefaultPublicProperty = '';
38
39
    protected function setUp() : void
40
    {
41
        $this->reflectionService = new RuntimeReflectionService();
42
    }
43
44
    public function testGetTypedNoDefaultReflectionProperty() : void
45
    {
46
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedNoDefaultProperty');
47
        self::assertInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp);
48
    }
49
50
    public function testGetTypedDefaultReflectionProperty() : void
51
    {
52
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedDefaultProperty');
53
        self::assertInstanceOf(ReflectionProperty::class, $reflProp);
54
        self::assertNotInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp);
55
    }
56
57
    public function testGetNonTypedNoDefaultReflectionProperty() : void
58
    {
59
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'nonTypedNoDefaultProperty');
60
        self::assertInstanceOf(ReflectionProperty::class, $reflProp);
61
    }
62
63
    public function testGetNonTypedDefaultReflectionProperty() : void
64
    {
65
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'nonTypedDefaultProperty');
66
        self::assertInstanceOf(ReflectionProperty::class, $reflProp);
67
        self::assertNotInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp);
68
    }
69
70
    public function testGetTypedPublicNoDefaultPropertyWorksWithGetValue() : void
71
    {
72
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedNoDefaultPublicProperty');
73
        self::assertInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp);
74
        self::assertNull($reflProp->getValue($this));
75
    }
76
77
    public function testGetTypedPublicDefaultPropertyWorksWithGetValue() : void
78
    {
79
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedDefaultPublicProperty');
80
        self::assertInstanceOf(ReflectionProperty::class, $reflProp);
81
        self::assertNotInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp);
82
    }
83
84
    public function testGetNonTypedPublicNoDefaultPropertyWorksWithGetValue() : void
85
    {
86
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'nonTypedNoDefaultPublicProperty');
87
        self::assertInstanceOf(RuntimePublicReflectionProperty::class, $reflProp);
88
        self::assertNull($reflProp->getValue($this));
89
    }
90
91
    public function testGetNonTypedPublicDefaultPropertyWorksWithGetValue() : void
92
    {
93
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'nonTypedDefaultPublicProperty');
94
        self::assertInstanceOf(RuntimePublicReflectionProperty::class, $reflProp);
95
    }
96
}
97