1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @package phpDocumentor\GraphViz\Tests |
9
|
|
|
* @author Mike van Riel <[email protected]> |
10
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
12
|
|
|
* @link http://phpdoc.org |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace phpDocumentor\GraphViz\Test; |
16
|
|
|
|
17
|
|
|
use phpDocumentor\GraphViz\AttributeNotFound; |
18
|
|
|
use phpDocumentor\GraphViz\Node; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test for the the class representing a GraphViz node. |
23
|
|
|
* |
24
|
|
|
* @package phpDocumentor\GraphViz\Tests |
25
|
|
|
* @author Mike van Riel <[email protected]> |
26
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
27
|
|
|
* @link http://phpdoc.org |
28
|
|
|
*/ |
29
|
|
|
class NodeTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
/** @var Node */ |
32
|
|
|
protected $fixture = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initializes the fixture for this test. |
36
|
|
|
*/ |
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->fixture = new Node('name', 'label'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Tests the construct method |
44
|
|
|
* |
45
|
|
|
* @covers \phpDocumentor\GraphViz\Node::__construct |
46
|
|
|
* |
47
|
|
|
* @returnn void |
48
|
|
|
*/ |
49
|
|
|
public function testConstruct() |
50
|
|
|
{ |
51
|
|
|
$fixture = new Node('MyName', 'MyLabel'); |
52
|
|
|
$this->assertInstanceOf( |
53
|
|
|
Node::class, |
54
|
|
|
$fixture |
55
|
|
|
); |
56
|
|
|
$this->assertSame('MyName', $fixture->getName()); |
57
|
|
|
$this->assertSame('MyLabel', $fixture->getLabel()->getValue()); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Tests the create method |
62
|
|
|
* |
63
|
|
|
* @covers \phpDocumentor\GraphViz\Node::create |
64
|
|
|
* |
65
|
|
|
* @returnn void |
66
|
|
|
*/ |
67
|
|
|
public function testCreate() |
68
|
|
|
{ |
69
|
|
|
$this->assertInstanceOf( |
70
|
|
|
Node::class, |
71
|
|
|
Node::create('name', 'label') |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Tests the getting and setting of the name. |
77
|
|
|
* |
78
|
|
|
* @covers \phpDocumentor\GraphViz\Node::getName |
79
|
|
|
* @covers \phpDocumentor\GraphViz\Node::setName |
80
|
|
|
*/ |
81
|
|
|
public function testName() |
82
|
|
|
{ |
83
|
|
|
$this->assertSame( |
84
|
|
|
$this->fixture->getName(), |
85
|
|
|
'name', |
86
|
|
|
'Expecting the name to match the initial state' |
87
|
|
|
); |
88
|
|
|
$this->assertSame( |
89
|
|
|
$this->fixture, |
90
|
|
|
$this->fixture->setName('otherName'), |
91
|
|
|
'Expecting a fluent interface' |
92
|
|
|
); |
93
|
|
|
$this->assertSame( |
94
|
|
|
$this->fixture->getName(), |
95
|
|
|
'otherName', |
96
|
|
|
'Expecting the name to contain the new value' |
97
|
|
|
); |
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\Node::__call |
106
|
|
|
* @covers \phpDocumentor\GraphViz\Node::getAttribute |
107
|
|
|
* @covers \phpDocumentor\GraphViz\Node::setAttribute |
108
|
|
|
*/ |
109
|
|
|
public function testCall() |
110
|
|
|
{ |
111
|
|
|
$fontname = 'Bitstream Vera Sans'; |
112
|
|
|
$this->assertInstanceOf(Node::class, $this->fixture->setfontname($fontname)); |
|
|
|
|
113
|
|
|
$this->assertSame($fontname, $this->fixture->getfontname()->getValue()); |
|
|
|
|
114
|
|
|
$this->assertNull($this->fixture->someNonExistingMethod()); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @covers \phpDocumentor\GraphViz\Node::getAttribute |
119
|
|
|
*/ |
120
|
|
|
public function testGetNonExistingAttributeThrowsAttributeNotFound() |
121
|
|
|
{ |
122
|
|
|
$this->expectException(AttributeNotFound::class); |
123
|
|
|
$this->expectExceptionMessage('Attribute with name "fontname" was not found'); |
124
|
|
|
|
125
|
|
|
$this->fixture->getFontname(); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Tests whether the magic __toString method returns a well formatted string |
130
|
|
|
* as specified in the DOT standard |
131
|
|
|
* |
132
|
|
|
* @covers \phpDocumentor\GraphViz\Node::__toString |
133
|
|
|
*/ |
134
|
|
|
public function testToString() |
135
|
|
|
{ |
136
|
|
|
$this->fixture->setfontsize(12); |
|
|
|
|
137
|
|
|
$this->fixture->setfontname('Bitstream Vera Sans'); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$dot = <<<DOT |
140
|
|
|
"name" [ |
141
|
|
|
label="label" |
142
|
|
|
fontsize="12" |
143
|
|
|
fontname="Bitstream Vera Sans" |
144
|
|
|
] |
145
|
|
|
DOT; |
146
|
|
|
|
147
|
|
|
$this->assertSame($dot, (string) $this->fixture); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Tests whether the magic __toString method returns a well formatted string |
152
|
|
|
* as specified in the DOT standard when the label contains slashes. |
153
|
|
|
* |
154
|
|
|
* @covers \phpDocumentor\GraphViz\Node::__toString |
155
|
|
|
*/ |
156
|
|
|
public function testToStringWithLabelContainingSlashes() |
157
|
|
|
{ |
158
|
|
|
$this->fixture->setfontsize(12); |
|
|
|
|
159
|
|
|
$this->fixture->setfontname('Bitstream Vera Sans'); |
|
|
|
|
160
|
|
|
$this->fixture->setLabel('\phpDocumentor\Descriptor\ProjectDescriptor'); |
161
|
|
|
|
162
|
|
|
$dot = <<<DOT |
163
|
|
|
"name" [ |
164
|
|
|
label="\\\\phpDocumentor\\\\Descriptor\\\\ProjectDescriptor" |
165
|
|
|
fontsize="12" |
166
|
|
|
fontname="Bitstream Vera Sans" |
167
|
|
|
] |
168
|
|
|
DOT; |
169
|
|
|
|
170
|
|
|
$this->assertSame($dot, (string) $this->fixture); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: