1 | <?php |
||
34 | class GraphTest extends TestCase |
||
35 | { |
||
36 | /** @var Graph */ |
||
37 | protected $fixture; |
||
38 | |||
39 | /** |
||
40 | * Sets up the fixture, for example, opens a network connection. |
||
41 | * This method is called before a test is executed. |
||
42 | */ |
||
43 | protected function setUp() : void |
||
47 | |||
48 | /** |
||
49 | * Tears down the fixture, for example, closes a network connection. |
||
50 | * This method is called after a test is executed. |
||
51 | */ |
||
52 | protected function tearDown() : void |
||
56 | |||
57 | /** |
||
58 | * @covers \phpDocumentor\GraphViz\Graph::create |
||
59 | */ |
||
60 | public function testCreate() : void |
||
86 | |||
87 | /** |
||
88 | * @covers \phpDocumentor\GraphViz\Graph::setName |
||
89 | */ |
||
90 | public function testSetName() : void |
||
98 | |||
99 | /** |
||
100 | * @covers \phpDocumentor\GraphViz\Graph::getName |
||
101 | */ |
||
102 | public function testGetName() : void |
||
116 | |||
117 | /** |
||
118 | * @covers \phpDocumentor\GraphViz\Graph::setType |
||
119 | */ |
||
120 | public function testSetType() : void |
||
138 | |||
139 | /** |
||
140 | * @covers \phpDocumentor\GraphViz\Graph::setType |
||
141 | */ |
||
142 | public function testSetTypeException() : void |
||
147 | |||
148 | /** |
||
149 | * @covers \phpDocumentor\GraphViz\Graph::getType |
||
150 | */ |
||
151 | public function testGetType() : void |
||
163 | |||
164 | public function testSetStrict() : void |
||
177 | |||
178 | public function testIsStrict() : void |
||
190 | |||
191 | public function testSetPath() : void |
||
199 | |||
200 | /** |
||
201 | * @covers \phpDocumentor\GraphViz\Graph::__call |
||
202 | * @covers \phpDocumentor\GraphViz\Graph::getAttribute |
||
203 | * @covers \phpDocumentor\GraphViz\Graph::setAttribute |
||
204 | */ |
||
205 | public function test__call() : void |
||
211 | |||
212 | /** |
||
213 | * @covers \phpDocumentor\GraphViz\Graph::getAttribute |
||
214 | * @covers \phpDocumentor\GraphViz\AttributeNotFound::__construct |
||
215 | */ |
||
216 | public function testGetNonExistingAttributeThrowsAttributeNotFound() : void |
||
217 | { |
||
218 | $this->expectException(AttributeNotFound::class); |
||
219 | $this->expectExceptionMessage('Attribute with name "notexisting" was not found'); |
||
220 | |||
221 | $this->fixture->getNotExisting(); |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * @covers \phpDocumentor\GraphViz\Graph::addGraph |
||
226 | */ |
||
227 | public function testAddGraph() : void |
||
228 | { |
||
229 | $mock = m::mock(Graph::class); |
||
230 | $mock->expects('setType'); |
||
231 | $mock->expects('getName'); |
||
232 | |||
233 | $this->assertSame( |
||
234 | $this->fixture, |
||
235 | $this->fixture->addGraph($mock) |
||
236 | ); |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @covers \phpDocumentor\GraphViz\Graph::hasGraph |
||
241 | */ |
||
242 | public function testHasGraph() : void |
||
243 | { |
||
244 | $mock = m::mock(Graph::class); |
||
245 | $mock->expects('getName')->andReturn('MyName'); |
||
246 | $mock->expects('setType'); |
||
247 | |||
248 | $this->assertFalse($this->fixture->hasGraph('MyName')); |
||
249 | $this->fixture->addGraph($mock); |
||
250 | $this->assertTrue($this->fixture->hasGraph('MyName')); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @covers \phpDocumentor\GraphViz\Graph::getGraph |
||
255 | */ |
||
256 | public function testGetGraph() : void |
||
257 | { |
||
258 | $mock = m::mock(Graph::class); |
||
259 | $mock->expects('setType'); |
||
260 | $mock->expects('getName')->andReturn('MyName'); |
||
261 | |||
262 | $this->fixture->addGraph($mock); |
||
263 | $this->assertSame( |
||
264 | $mock, |
||
265 | $this->fixture->getGraph('MyName') |
||
266 | ); |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * @covers \phpDocumentor\GraphViz\Graph::setNode |
||
271 | */ |
||
272 | public function testSetNode() : void |
||
273 | { |
||
274 | $mock = m::mock(Node::class); |
||
275 | $mock->expects('getName')->andReturn('MyName'); |
||
276 | |||
277 | $this->assertSame( |
||
278 | $this->fixture, |
||
279 | $this->fixture->setNode($mock) |
||
280 | ); |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @covers \phpDocumentor\GraphViz\Graph::findNode |
||
285 | */ |
||
286 | public function testFindNode() : void |
||
287 | { |
||
288 | $this->assertNull($this->fixture->findNode('MyNode')); |
||
289 | |||
290 | $mock = m::mock(Node::class); |
||
291 | $mock->expects('getName')->andReturn('MyName'); |
||
292 | |||
293 | $this->fixture->setNode($mock); |
||
294 | $this->assertSame( |
||
295 | $mock, |
||
296 | $this->fixture->findNode('MyName') |
||
297 | ); |
||
298 | |||
299 | $subGraph = Graph::create(); |
||
300 | $mock2 = m::mock(Node::class); |
||
301 | $mock2->expects('getName')->andReturn('MyName2'); |
||
302 | |||
303 | $subGraph->setNode($mock2); |
||
304 | |||
305 | $this->fixture->addGraph($subGraph); |
||
306 | $this->assertSame( |
||
307 | $mock2, |
||
308 | $this->fixture->findNode('MyName2') |
||
309 | ); |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * @covers \phpDocumentor\GraphViz\Graph::__set |
||
314 | */ |
||
315 | public function test__set() : void |
||
316 | { |
||
317 | $mock = m::mock(Node::class); |
||
318 | |||
319 | $this->fixture->__set('myNode', $mock); |
||
320 | |||
321 | self::assertSame($mock, $this->fixture->myNode); |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * @covers \phpDocumentor\GraphViz\Graph::__get |
||
326 | */ |
||
327 | public function test__get() : void |
||
337 | |||
338 | /** |
||
339 | * @covers \phpDocumentor\GraphViz\Graph::link |
||
340 | */ |
||
341 | public function testLink() : void |
||
350 | |||
351 | /** |
||
352 | * @covers \phpDocumentor\GraphViz\Graph::export |
||
353 | */ |
||
354 | public function testExportException() : void |
||
355 | { |
||
356 | $graph = Graph::create('My First Graph'); |
||
357 | $filename = tempnam(sys_get_temp_dir(), 'tst'); |
||
368 | |||
369 | /** |
||
370 | * @covers \phpDocumentor\GraphViz\Graph::export |
||
371 | */ |
||
372 | public function testExport() : void |
||
389 | |||
390 | /** |
||
391 | * @covers \phpDocumentor\GraphViz\Graph::__toString |
||
392 | */ |
||
393 | public function test__toString() : void |
||
415 | |||
416 | /** |
||
417 | * Help avoid issue of "#Warning: Strings contain different line endings!" on Windows. |
||
418 | */ |
||
419 | private function normalizeLineEndings(string $string) : string |
||
428 | } |
||
429 |
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: