|
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
|
|
|
|
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
public string $typedNoDefaultPublicProperty; |
|
28
|
|
|
|
|
29
|
|
|
protected function setUp() : void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->reflectionService = new RuntimeReflectionService(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testGetTypedNoDefaultReflectionProperty() : void |
|
35
|
|
|
{ |
|
36
|
|
|
$reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedNoDefaultProperty'); |
|
37
|
|
|
self::assertInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testGetTypedDefaultReflectionProperty() : void |
|
41
|
|
|
{ |
|
42
|
|
|
$reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedDefaultProperty'); |
|
43
|
|
|
self::assertInstanceOf(ReflectionProperty::class, $reflProp); |
|
44
|
|
|
self::assertNotInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetTypedPublicNoDefaultPropertyWorksWithGetValue() : void |
|
48
|
|
|
{ |
|
49
|
|
|
$reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedNoDefaultPublicProperty'); |
|
50
|
|
|
self::assertInstanceOf(RuntimePublicReflectionProperty::class, $reflProp); |
|
51
|
|
|
self::assertNull($reflProp->getValue($this)); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|