|
1
|
|
|
<?php |
|
2
|
|
|
namespace Doctrine\Tests\Common\Persistence\Mapping; |
|
3
|
|
|
|
|
4
|
|
|
use Doctrine\Common\Persistence\Mapping\MappingException; |
|
5
|
|
|
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; |
|
6
|
|
|
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @group DCOM-93 |
|
10
|
|
|
*/ |
|
11
|
|
|
class RuntimeReflectionServiceTest extends \PHPUnit\Framework\TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var RuntimeReflectionService |
|
15
|
|
|
*/ |
|
16
|
|
|
private $reflectionService; |
|
17
|
|
|
|
|
18
|
|
|
public $unusedPublicProperty; |
|
19
|
|
|
|
|
20
|
|
|
public function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->reflectionService = new RuntimeReflectionService(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testShortname() |
|
26
|
|
|
{ |
|
27
|
|
|
self::assertEquals("RuntimeReflectionServiceTest", $this->reflectionService->getClassShortName(__CLASS__)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testClassNamespaceName() |
|
31
|
|
|
{ |
|
32
|
|
|
self::assertEquals('Doctrine\Tests\Common\Persistence\Mapping', $this->reflectionService->getClassNamespace(__CLASS__)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testGetParentClasses() |
|
36
|
|
|
{ |
|
37
|
|
|
$classes = $this->reflectionService->getParentClasses(__CLASS__); |
|
38
|
|
|
self::assertTrue(count($classes) >= 1, "The test class " . __CLASS__ . " should have at least one parent."); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testGetParentClassesForAbsentClass() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->expectException(MappingException::class); |
|
44
|
|
|
$this->reflectionService->getParentClasses(__NAMESPACE__ . '\AbsentClass'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetReflectionClass() |
|
48
|
|
|
{ |
|
49
|
|
|
$class = $this->reflectionService->getClass(__CLASS__); |
|
50
|
|
|
self::assertInstanceOf("ReflectionClass", $class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testGetMethods() |
|
54
|
|
|
{ |
|
55
|
|
|
self::assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods")); |
|
56
|
|
|
self::assertFalse($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods2")); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGetAccessibleProperty() |
|
60
|
|
|
{ |
|
61
|
|
|
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "reflectionService"); |
|
62
|
|
|
self::assertInstanceOf(\ReflectionProperty::class, $reflProp); |
|
63
|
|
|
self::assertInstanceOf(RuntimeReflectionService::class, $reflProp->getValue($this)); |
|
64
|
|
|
|
|
65
|
|
|
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "unusedPublicProperty"); |
|
66
|
|
|
self::assertInstanceOf(RuntimePublicReflectionProperty::class, $reflProp); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|