Failed Conditions
Pull Request — master (#1)
by Jonathan
03:02
created

StaticReflectionServiceTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 45
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetMethods() 0 4 1
A testGetReflectionClass() 0 4 1
A testGetAccessibleProperty() 0 4 1
A testShortname() 0 3 1
A setUp() 0 3 1
A testGetParentClasses() 0 4 1
A testClassNamespaceName() 0 4 1
1
<?php
2
namespace Doctrine\Tests\Common\Persistence\Mapping;
3
4
use Doctrine\Common\Persistence\Mapping\StaticReflectionService;
5
6
/**
7
 * @group DCOM-93
8
 */
9
class StaticReflectionServiceTest extends \PHPUnit\Framework\TestCase
10
{
11
    /**
12
     * @var StaticReflectionService
13
     */
14
    private $reflectionService;
15
16
    public function setUp()
17
    {
18
        $this->reflectionService = new StaticReflectionService();
19
    }
20
21
    public function testShortname()
22
    {
23
        self::assertEquals("StaticReflectionServiceTest", $this->reflectionService->getClassShortName(__CLASS__));
24
    }
25
26
    public function testClassNamespaceName()
27
    {
28
        self::assertEquals('', $this->reflectionService->getClassNamespace(\stdClass::class));
29
        self::assertEquals(__NAMESPACE__, $this->reflectionService->getClassNamespace(__CLASS__));
30
    }
31
32
    public function testGetParentClasses()
33
    {
34
        $classes = $this->reflectionService->getParentClasses(__CLASS__);
35
        self::assertTrue(count($classes) == 0, "The test class " . __CLASS__ . " should have no parents according to static reflection.");
36
    }
37
38
    public function testGetReflectionClass()
39
    {
40
        $class = $this->reflectionService->getClass(__CLASS__);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $class is correct as $this->reflectionService->getClass(__CLASS__) targeting Doctrine\Common\Persiste...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...
41
        self::assertNull($class);
42
    }
43
44
    public function testGetMethods()
45
    {
46
        self::assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods"));
47
        self::assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods2"));
48
    }
49
50
    public function testGetAccessibleProperty()
51
    {
52
        $reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "reflectionService");
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $reflProp is correct as $this->reflectionService..._, 'reflectionService') targeting Doctrine\Common\Persiste...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...
53
        self::assertNull($reflProp);
54
    }
55
}
56