Completed
Pull Request — 1.4.x (#106)
by Grégoire
05:25 queued 03:08
created

StaticReflectionServiceTest::testGetMethods()   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\Persistence\Mapping\StaticReflectionService;
6
use PHPUnit\Framework\TestCase;
7
use stdClass;
8
use function count;
9
10
/**
11
 * @group DCOM-93
12
 */
13
class StaticReflectionServiceTest extends TestCase
14
{
15
    /** @var StaticReflectionService */
16
    private $reflectionService;
17
18
    public function setUp()
19
    {
20
        $this->reflectionService = new StaticReflectionService();
21
    }
22
23
    public function testShortname()
24
    {
25
        self::assertSame('StaticReflectionServiceTest', $this->reflectionService->getClassShortName(self::class));
26
    }
27
28
    public function testClassNamespaceName()
29
    {
30
        self::assertSame('', $this->reflectionService->getClassNamespace(stdClass::class));
31
        self::assertSame(__NAMESPACE__, $this->reflectionService->getClassNamespace(self::class));
32
    }
33
34
    public function testGetParentClasses()
35
    {
36
        $classes = $this->reflectionService->getParentClasses(self::class);
37
        self::assertTrue(count($classes) === 0, 'The test class ' . self::class . ' should have no parents according to static reflection.');
38
    }
39
40
    public function testGetReflectionClass()
41
    {
42
        $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...
43
        self::assertNull($class);
44
    }
45
46
    public function testGetMethods()
47
    {
48
        self::assertTrue($this->reflectionService->hasPublicMethod(self::class, 'testGetMethods'));
49
        self::assertTrue($this->reflectionService->hasPublicMethod(self::class, 'testGetMethods2'));
50
    }
51
52
    public function testGetAccessibleProperty()
53
    {
54
        $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...
55
        self::assertNull($reflProp);
56
    }
57
}
58