1 | <?php |
||
22 | class GraphTest extends TestCase { |
||
23 | |||
24 | /** |
||
25 | * @var Graph |
||
26 | */ |
||
27 | protected $fixture; |
||
28 | |||
29 | /** |
||
30 | * Sets up the fixture, for example, opens a network connection. |
||
31 | * This method is called before a test is executed. |
||
32 | */ |
||
33 | protected function setUp() |
||
34 | { |
||
35 | $this->fixture = new Graph; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Tears down the fixture, for example, closes a network connection. |
||
40 | * This method is called after a test is executed. |
||
41 | */ |
||
42 | protected function tearDown() |
||
43 | { |
||
44 | |||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @covers phpDocumentor\GraphViz\Graph::create |
||
49 | */ |
||
50 | public function testCreate() |
||
51 | { |
||
52 | $fixture = Graph::create(); |
||
53 | $this->assertInstanceOf( |
||
54 | 'phpDocumentor\GraphViz\Graph', |
||
55 | $fixture |
||
56 | ); |
||
57 | $this->assertSame( |
||
58 | 'G', |
||
59 | $fixture->getName() |
||
60 | ); |
||
61 | $this->assertSame( |
||
62 | 'digraph', |
||
63 | $fixture->getType() |
||
64 | ); |
||
65 | |||
66 | $fixture = Graph::create('MyName', false); |
||
67 | $this->assertSame( |
||
68 | 'MyName', |
||
69 | $fixture->getName() |
||
70 | ); |
||
71 | $this->assertSame( |
||
72 | 'graph', |
||
73 | $fixture->getType() |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @covers phpDocumentor\GraphViz\Graph::setName |
||
79 | */ |
||
80 | public function testSetName() |
||
81 | { |
||
82 | $this->assertSame( |
||
83 | $this->fixture, $this->fixture->setName('otherName'), |
||
84 | 'Expecting a fluent interface' |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @covers phpDocumentor\GraphViz\Graph::getName |
||
90 | */ |
||
91 | public function testGetName() |
||
92 | { |
||
93 | $this->assertSame( |
||
94 | $this->fixture->getName(), 'G', |
||
95 | 'Expecting the name to match the initial state' |
||
96 | ); |
||
97 | $this->fixture->setName('otherName'); |
||
98 | $this->assertSame( |
||
99 | $this->fixture->getName(), 'otherName', |
||
100 | 'Expecting the name to contain the new value' |
||
101 | ); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @covers phpDocumentor\GraphViz\Graph::setType |
||
106 | */ |
||
107 | public function testSetType() |
||
108 | { |
||
109 | $this->assertSame( |
||
110 | $this->fixture, $this->fixture->setType('digraph'), |
||
111 | 'Expecting a fluent interface' |
||
112 | ); |
||
113 | $this->assertSame( |
||
114 | $this->fixture, $this->fixture->setType('graph'), |
||
115 | 'Expecting a fluent interface' |
||
116 | ); |
||
117 | $this->assertSame( |
||
118 | $this->fixture, $this->fixture->setType('subgraph'), |
||
119 | 'Expecting a fluent interface' |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @covers phpDocumentor\GraphViz\Graph::setType |
||
125 | */ |
||
126 | public function testSetTypeException() |
||
127 | { |
||
128 | $this->expectException('\InvalidArgumentException'); |
||
129 | $this->fixture->setType('fakegraphg'); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @covers phpDocumentor\GraphViz\Graph::getType |
||
134 | */ |
||
135 | public function testGetType() |
||
136 | { |
||
137 | $this->assertSame( |
||
138 | $this->fixture->getType(), |
||
139 | 'digraph' |
||
140 | ); |
||
141 | $this->fixture->setType('graph'); |
||
142 | $this->assertSame( |
||
143 | $this->fixture->getType(), |
||
144 | 'graph' |
||
145 | ); |
||
146 | } |
||
147 | |||
148 | public function testSetStrict() |
||
159 | |||
160 | public function testIsStrict() |
||
172 | |||
173 | public function testSetPath() |
||
180 | |||
181 | /** |
||
182 | * @covers phpDocumentor\GraphViz\Graph::__call |
||
183 | */ |
||
184 | public function test__call() |
||
185 | { |
||
186 | $this->assertNull($this->fixture->MyMethod()); |
||
|
|||
187 | $this->assertSame($this->fixture, $this->fixture->setColor('black')); |
||
188 | $this->assertSame('black', $this->fixture->getColor()->getValue()); |
||
190 | |||
191 | /** |
||
192 | * @covers phpDocumentor\GraphViz\Graph::addGraph |
||
193 | */ |
||
194 | public function testAddGraph() |
||
203 | |||
204 | /** |
||
205 | * @covers phpDocumentor\GraphViz\Graph::hasGraph |
||
206 | */ |
||
207 | public function testHasGraph() |
||
217 | |||
218 | /** |
||
219 | * @covers phpDocumentor\GraphViz\Graph::getGraph |
||
220 | */ |
||
221 | public function testGetGraph() |
||
234 | |||
235 | /** |
||
236 | * @covers phpDocumentor\GraphViz\Graph::setNode |
||
237 | */ |
||
238 | public function testSetNode() |
||
250 | |||
251 | /** |
||
252 | * @covers phpDocumentor\GraphViz\Graph::findNode |
||
253 | */ |
||
254 | public function testFindNode() { |
||
279 | |||
280 | /** |
||
281 | * @covers phpDocumentor\GraphViz\Graph::__set |
||
282 | * @todo Implement test__set(). |
||
283 | */ |
||
284 | public function test__set() { |
||
295 | |||
296 | /** |
||
297 | * @covers phpDocumentor\GraphViz\Graph::__get |
||
298 | * @todo Implement test__get(). |
||
299 | */ |
||
300 | public function test__get() { |
||
312 | |||
313 | /** |
||
314 | * @covers phpDocumentor\GraphViz\Graph::link |
||
315 | * @todo Implement testLink(). |
||
316 | */ |
||
317 | public function testLink() { |
||
327 | |||
328 | /** |
||
329 | * @covers phpDocumentor\GraphViz\Graph::export |
||
330 | */ |
||
331 | public function testExportException() { |
||
339 | |||
340 | /** |
||
341 | * @covers phpDocumentor\GraphViz\Graph::export |
||
342 | */ |
||
343 | public function testExport() { |
||
353 | |||
354 | /** |
||
355 | * @covers phpDocumentor\GraphViz\Graph::__toString |
||
356 | */ |
||
357 | public function test__toString() |
||
377 | |||
378 | /** |
||
379 | * Help avoid issue of "#Warning: Strings contain different line endings!" on Windows. |
||
380 | */ |
||
381 | private function normalizeLineEndings($string) |
||
385 | |||
386 | } |
||
387 |
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: