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\Test; |
15
|
|
|
|
16
|
|
|
use Mockery as m; |
17
|
|
|
use phpDocumentor\GraphViz\AttributeNotFound; |
18
|
|
|
use phpDocumentor\GraphViz\Edge; |
19
|
|
|
use phpDocumentor\GraphViz\Node; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Test for the the class representing a GraphViz edge (vertex). |
24
|
|
|
*/ |
25
|
|
|
class EdgeTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Tears down the fixture, for example, closes a network connection. |
29
|
|
|
* This method is called after a test is executed. |
30
|
|
|
*/ |
31
|
|
|
protected function tearDown() : void |
32
|
|
|
{ |
33
|
|
|
m::close(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Tests the construct method |
38
|
|
|
* |
39
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::__construct |
40
|
|
|
*/ |
41
|
|
|
public function testConstruct() : void |
42
|
|
|
{ |
43
|
|
|
$fromNode = m::mock(Node::class); |
44
|
|
|
$toNode = m::mock(Node::class); |
45
|
|
|
$fixture = new Edge($fromNode, $toNode); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$this->assertInstanceOf( |
48
|
|
|
Edge::class, |
49
|
|
|
$fixture |
50
|
|
|
); |
51
|
|
|
$this->assertSame( |
52
|
|
|
$fromNode, |
53
|
|
|
$fixture->getFrom() |
54
|
|
|
); |
55
|
|
|
$this->assertSame( |
56
|
|
|
$toNode, |
57
|
|
|
$fixture->getTo() |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Tests the create method |
63
|
|
|
* |
64
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::create |
65
|
|
|
*/ |
66
|
|
|
public function testCreate() : void |
67
|
|
|
{ |
68
|
|
|
$this->assertInstanceOf( |
69
|
|
|
Edge::class, |
70
|
|
|
Edge::create(new Node('from'), new Node('to')) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Tests whether the getFrom method returns the same node as passed |
76
|
|
|
* in the create method |
77
|
|
|
* |
78
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::getFrom |
79
|
|
|
*/ |
80
|
|
|
public function testGetFrom() : void |
81
|
|
|
{ |
82
|
|
|
$from = new Node('from'); |
83
|
|
|
$edge = Edge::create($from, new Node('to')); |
84
|
|
|
$this->assertSame($from, $edge->getFrom()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Tests the getTo method returns the same node as passed |
89
|
|
|
* in the create method |
90
|
|
|
* |
91
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::getTo |
92
|
|
|
*/ |
93
|
|
|
public function testGetTo() : void |
94
|
|
|
{ |
95
|
|
|
$to = new Node('to'); |
96
|
|
|
$edge = Edge::create(new Node('from'), $to); |
97
|
|
|
$this->assertSame($to, $edge->getTo()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Tests the magic __call method, to work as described, return the object |
102
|
|
|
* instance for a setX method, return the value for an getX method, and null |
103
|
|
|
* for the remaining method calls |
104
|
|
|
* |
105
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::__call |
106
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::setAttribute |
107
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::getAttribute |
108
|
|
|
*/ |
109
|
|
|
public function testCall() : void |
110
|
|
|
{ |
111
|
|
|
$label = 'my label'; |
112
|
|
|
$fixture = new Edge(new Node('from'), new Node('to')); |
113
|
|
|
$this->assertInstanceOf(Edge::class, $fixture->setLabel($label)); |
|
|
|
|
114
|
|
|
$this->assertSame($label, $fixture->getLabel()->getValue()); |
|
|
|
|
115
|
|
|
$this->assertNull($fixture->someNonExcistingMethod()); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::getAttribute |
120
|
|
|
* @covers \phpDocumentor\GraphViz\AttributeNotFound::__construct |
121
|
|
|
*/ |
122
|
|
|
public function testGetNonExistingAttributeThrowsAttributeNotFound() : void |
123
|
|
|
{ |
124
|
|
|
$fixture = new Edge(new Node('from'), new Node('to')); |
125
|
|
|
|
126
|
|
|
$this->expectException(AttributeNotFound::class); |
127
|
|
|
$this->expectExceptionMessage('Attribute with name "label" was not found'); |
128
|
|
|
|
129
|
|
|
$fixture->getLabel(); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Tests whether the magic __toString method returns a well formatted string |
134
|
|
|
* as specified in the DOT standard |
135
|
|
|
* |
136
|
|
|
* @covers \phpDocumentor\GraphViz\Edge::__toString |
137
|
|
|
*/ |
138
|
|
|
public function testToString() : void |
139
|
|
|
{ |
140
|
|
|
$fixture = new Edge(new Node('from'), new Node('to')); |
141
|
|
|
$fixture->setLabel('MyLabel'); |
|
|
|
|
142
|
|
|
$fixture->setWeight(45); |
|
|
|
|
143
|
|
|
|
144
|
|
|
$dot = <<<DOT |
145
|
|
|
"from" -> "to" [ |
146
|
|
|
label="MyLabel" |
147
|
|
|
weight="45" |
148
|
|
|
] |
149
|
|
|
DOT; |
150
|
|
|
|
151
|
|
|
$this->assertSame($dot, (string) $fixture); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: