StaticReflectionServiceTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 13
dl 0
loc 43
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testShortname() 0 3 1
A testGetAccessibleProperty() 0 4 1
A testGetMethods() 0 4 1
A testGetParentClasses() 0 4 1
A setUp() 0 3 1
A testGetReflectionClass() 0 4 1
A testClassNamespaceName() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Persistence\Mapping;
6
7
use Doctrine\Persistence\Mapping\StaticReflectionService;
8
use PHPUnit\Framework\TestCase;
9
use stdClass;
10
use function count;
11
12
/**
13
 * @group DCOM-93
14
 */
15
class StaticReflectionServiceTest extends TestCase
16
{
17
    /** @var StaticReflectionService */
18
    private $reflectionService;
19
20
    protected function setUp() : void
21
    {
22
        $this->reflectionService = new StaticReflectionService();
23
    }
24
25
    public function testShortname() : void
26
    {
27
        self::assertSame('StaticReflectionServiceTest', $this->reflectionService->getClassShortName(self::class));
28
    }
29
30
    public function testClassNamespaceName() : void
31
    {
32
        self::assertSame('', $this->reflectionService->getClassNamespace(stdClass::class));
33
        self::assertSame(__NAMESPACE__, $this->reflectionService->getClassNamespace(self::class));
34
    }
35
36
    public function testGetParentClasses() : void
37
    {
38
        $classes = $this->reflectionService->getParentClasses(self::class);
39
        self::assertTrue(count($classes) === 0, 'The test class ' . self::class . ' should have no parents according to static reflection.');
40
    }
41
42
    public function testGetReflectionClass() : void
43
    {
44
        $class = $this->reflectionService->getClass(self::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $class is correct as $this->reflectionService->getClass(self::class) targeting Doctrine\Persistence\Map...tionService::getClass() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
45
        self::assertNull($class);
46
    }
47
48
    public function testGetMethods() : void
49
    {
50
        self::assertTrue($this->reflectionService->hasPublicMethod(self::class, 'testGetMethods'));
51
        self::assertTrue($this->reflectionService->hasPublicMethod(self::class, 'testGetMethods2'));
52
    }
53
54
    public function testGetAccessibleProperty() : void
55
    {
56
        $reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'reflectionService');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $reflProp is correct as $this->reflectionService...s, 'reflectionService') targeting Doctrine\Persistence\Map...getAccessibleProperty() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
57
        self::assertNull($reflProp);
58
    }
59
}
60