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

RuntimeReflectionServiceTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 55
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAccessibleProperty() 0 8 1
A testGetReflectionClass() 0 4 1
A testGetParentClasses() 0 4 1
A testClassNamespaceName() 0 3 1
A setUp() 0 3 1
A testGetParentClassesForAbsentClass() 0 4 1
A testGetMethods() 0 4 1
A testShortname() 0 3 1
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