|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* phpDocumentor |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @link http://phpdoc.org |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace phpDocumentor\GraphViz\PHPStan; |
|
15
|
|
|
|
|
16
|
|
|
use Mockery as m; |
|
17
|
|
|
use phpDocumentor\GraphViz\Graph; |
|
18
|
|
|
use phpDocumentor\GraphViz\Node; |
|
19
|
|
|
use PHPStan\Reflection\ClassReflection; |
|
20
|
|
|
use PHPStan\Type\FloatType; |
|
21
|
|
|
use PHPStan\Type\StringType; |
|
22
|
|
|
use PHPUnit\Framework\TestCase; |
|
23
|
|
|
|
|
24
|
|
|
final class MethodReflectionExtensionTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var MethodReflectionExtension */ |
|
27
|
|
|
private $fixture; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() : void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->fixture = new MethodReflectionExtension(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @dataProvider existingMethodProvider |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testNodeHasMethodReturnsTrue(string $className, string $methodName) : void |
|
38
|
|
|
{ |
|
39
|
|
|
$classReflection = m::mock(ClassReflection::class); |
|
40
|
|
|
$classReflection->shouldReceive('getName')->andReturn($className); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertTrue($this->fixture->hasMethod($classReflection, $methodName)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return array<string, array<string, string>> |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
public function existingMethodProvider() : array |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
'node::getLabel' => [ |
|
52
|
|
|
'className' => Node::class, |
|
53
|
|
|
'methodName' => 'getLabel', |
|
54
|
|
|
], |
|
55
|
|
|
'node::setLabel' => [ |
|
56
|
|
|
'className' => Node::class, |
|
57
|
|
|
'methodName' => 'setLabel', |
|
58
|
|
|
], |
|
59
|
|
|
'graph::setFontSize' => [ |
|
60
|
|
|
'className' => Graph::class, |
|
61
|
|
|
'methodName' => 'setFontSize', |
|
62
|
|
|
], |
|
63
|
|
|
'graph::getFontSize' => [ |
|
64
|
|
|
'className' => Graph::class, |
|
65
|
|
|
'methodName' => 'getFontSize', |
|
66
|
|
|
], |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testAttributeType() : void |
|
71
|
|
|
{ |
|
72
|
|
|
$classReflection = m::mock(ClassReflection::class); |
|
73
|
|
|
$classReflection->shouldReceive('getName')->andReturn(Node::class); |
|
74
|
|
|
|
|
75
|
|
|
$method = $this->fixture->getMethod($classReflection, 'setFontSize'); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertInstanceOf(FloatType::class, $method->getVariants()[0]->getParameters()[0]->getType()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testAttributeTypeOfNoneExisting() : void |
|
81
|
|
|
{ |
|
82
|
|
|
$classReflection = m::mock(ClassReflection::class); |
|
83
|
|
|
$classReflection->shouldReceive('getName')->andReturn(Node::class); |
|
84
|
|
|
|
|
85
|
|
|
$method = $this->fixture->getMethod($classReflection, 'setColor'); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertInstanceOf(StringType::class, $method->getVariants()[0]->getParameters()[0]->getType()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.