Completed
Pull Request — 1.4.x (#106)
by Grégoire
02:25
created

testGetReflectionClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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