|
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; |
|
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private string $typedDefaultProperty = ''; |
|
|
|
|
|
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
private $nonTypedNoDefaultProperty; |
|
|
|
|
|
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
private $nonTypedDefaultProperty = ''; |
|
|
|
|
|
|
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
|
|
|
|