Completed
Push — master ( fb964a...b7229e )
by Jonathan
9s
created

StaticReflectionMethodTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Doctrine\Tests\Common\Reflection;
4
5
use Doctrine\Common\Reflection\StaticReflectionClass;
6
use Doctrine\Common\Reflection\StaticReflectionMethod;
7
use Doctrine\Common\Reflection\StaticReflectionParser;
8
use PHPStan\Testing\TestCase;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use ReflectionException;
11
12
class StaticReflectionMethodTest extends TestCase
13
{
14
    /** @var StaticReflectionParser|MockObject */
15
    private $staticReflectionParser;
16
17
    /** @var string */
18
    private $methodName;
19
20
    /** @var StaticReflectionMethod */
21
    private $staticReflectionMethod;
22
23
    public function testGetName() : void
24
    {
25
        self::assertEquals($this->methodName, $this->staticReflectionMethod->getName());
26
    }
27
28
    public function testGetDeclaringClass() : void
29
    {
30
        $staticReflectionClass = $this->createMock(StaticReflectionClass::class);
31
32
        $this->staticReflectionParser->expects($this->once())
33
            ->method('getReflectionClass')
34
            ->willReturn($staticReflectionClass);
35
36
        self::assertSame($staticReflectionClass, $this->staticReflectionMethod->getDeclaringClass());
37
    }
38
39
    public function testGetNamespaceName() : void
40
    {
41
        $this->staticReflectionParser->expects($this->once())
42
            ->method('getNamespaceName')
43
            ->willReturn('test');
44
45
        self::assertEquals('test', $this->staticReflectionMethod->getNamespaceName());
46
    }
47
48
    public function testGetDocComment() : void
49
    {
50
        $staticReflectionClass = $this->createMock(StaticReflectionClass::class);
0 ignored issues
show
Unused Code introduced by
The assignment to $staticReflectionClass is dead and can be removed.
Loading history...
51
52
        $this->staticReflectionParser->expects($this->once())
53
            ->method('getDocComment')
54
            ->with('method', $this->methodName)
55
            ->willReturn('test doc comment');
56
57
        self::assertSame('test doc comment', $this->staticReflectionMethod->getDocComment());
58
    }
59
60
    public function testGetUseStatements() : void
61
    {
62
        $staticReflectionClass = $this->createMock(StaticReflectionClass::class);
0 ignored issues
show
Unused Code introduced by
The assignment to $staticReflectionClass is dead and can be removed.
Loading history...
63
64
        $this->staticReflectionParser->expects($this->once())
65
            ->method('getUseStatements')
66
            ->willReturn(['Test']);
67
68
        self::assertSame(['Test'], $this->staticReflectionMethod->getUseStatements());
69
    }
70
71
    /**
72
     * @dataProvider getNotImplementedMethods
73
     *
74
     * @param mixed[] $args
75
     */
76
    public function testNotImplemented(string $method, array $args) : void
77
    {
78
        $this->expectException(ReflectionException::class);
79
        $this->expectExceptionMessage('Method not implemented');
80
81
        $this->staticReflectionMethod->$method(...$args);
82
    }
83
84
    /**
85
     * @return mixed[]
86
     */
87
    public function getNotImplementedMethods() : array
88
    {
89
        return [
90
            ['export', ['Test', 'Test', true]],
91
            ['getClosure', [$this]],
92
            ['getModifiers', []],
93
            ['getPrototype', []],
94
            ['invoke', [$this, null]],
95
            ['invokeArgs', [$this, [null, null]]],
96
            ['isAbstract', []],
97
            ['isConstructor', []],
98
            ['isDestructor', []],
99
            ['isFinal', []],
100
            ['isPrivate', []],
101
            ['isProtected', []],
102
            ['isPublic', []],
103
            ['isStatic', []],
104
            ['setAccessible', [true]],
105
            ['__toString', []],
106
            ['getClosureThis', []],
107
            ['getEndLine', []],
108
            ['getExtension', []],
109
            ['getExtensionName', []],
110
            ['getFileName', []],
111
            ['getNumberOfParameters', []],
112
            ['getNumberOfRequiredParameters', []],
113
            ['getParameters', []],
114
            ['getShortName', []],
115
            ['getStartLine', []],
116
            ['getStaticVariables', []],
117
            ['inNamespace', []],
118
            ['isClosure', []],
119
            ['isDeprecated', []],
120
            ['isInternal', []],
121
            ['isUserDefined', []],
122
            ['returnsReference', []],
123
        ];
124
    }
125
126
    protected function setUp() : void
127
    {
128
        $this->staticReflectionParser = $this->createMock(StaticReflectionParser::class);
129
        $this->methodName             = 'methodName';
130
131
        $this->staticReflectionParser->expects($this->any())
132
            ->method('getStaticReflectionParserForDeclaringClass')
133
            ->with('method', $this->methodName)
134
            ->willReturn($this->staticReflectionParser);
135
136
        $this->staticReflectionMethod = new StaticReflectionMethod(
137
            $this->staticReflectionParser,
138
            $this->methodName
139
        );
140
    }
141
}
142