1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5 |
6
|
|
|
* |
7
|
|
|
* @package phpDocumentor\GraphViz\Tests |
8
|
|
|
* @author Danny van der Sluijs <[email protected]> |
9
|
|
|
* @copyright 2012 Danny van der Sluijs (http://www.fleppuhstein.com) |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
11
|
|
|
* @link http://phpDocumentor-project.org |
12
|
|
|
*/ |
13
|
|
|
namespace phpDocumentor\GraphViz; |
14
|
|
|
|
15
|
|
|
use phpDocumentor\GraphViz\Graph; |
16
|
|
|
use phpDocumentor\GraphViz\Node; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2012-12-09 at 19:06:57. |
21
|
|
|
*/ |
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() |
149
|
|
|
{ |
150
|
|
|
$this->assertSame( |
151
|
|
|
$this->fixture, $this->fixture->setStrict(true), |
152
|
|
|
'Expecting a fluent interface' |
153
|
|
|
); |
154
|
|
|
$this->assertSame( |
155
|
|
|
$this->fixture, $this->fixture->setStrict(false), |
156
|
|
|
'Expecting a fluent interface' |
157
|
|
|
); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function testIsStrict() |
161
|
|
|
{ |
162
|
|
|
$this->assertSame( |
163
|
|
|
$this->fixture->isStrict(), |
164
|
|
|
false |
165
|
|
|
); |
166
|
|
|
$this->fixture->setStrict(true); |
167
|
|
|
$this->assertSame( |
168
|
|
|
$this->fixture->isStrict(), |
169
|
|
|
true |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function testSetPath() |
174
|
|
|
{ |
175
|
|
|
$this->assertSame( |
176
|
|
|
$this->fixture, $this->fixture->setPath(__DIR__), |
177
|
|
|
'Expecting a fluent interface' |
178
|
|
|
); |
179
|
|
|
} |
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()); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @covers phpDocumentor\GraphViz\Graph::addGraph |
193
|
|
|
*/ |
194
|
|
|
public function testAddGraph() |
195
|
|
|
{ |
196
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
197
|
|
|
|
198
|
|
|
$this->assertSame( |
199
|
|
|
$this->fixture, |
200
|
|
|
$this->fixture->addGraph($this->getMock('phpDocumentor\GraphViz\Graph')) |
|
|
|
|
201
|
|
|
); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @covers phpDocumentor\GraphViz\Graph::hasGraph |
206
|
|
|
*/ |
207
|
|
|
public function testHasGraph() |
208
|
|
|
{ |
209
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
210
|
|
|
|
211
|
|
|
$mock = $this->getMock('phpDocumentor\GraphViz\Graph'); |
|
|
|
|
212
|
|
|
$mock->expects($this->any())->method('getName')->will($this->returnValue('MyName')); |
213
|
|
|
$this->assertFalse($this->fixture->hasGraph('MyName')); |
214
|
|
|
$this->fixture->addGraph($mock); |
215
|
|
|
$this->assertTrue($this->fixture->hasGraph('MyName')); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @covers phpDocumentor\GraphViz\Graph::getGraph |
220
|
|
|
*/ |
221
|
|
|
public function testGetGraph() |
222
|
|
|
{ |
223
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
224
|
|
|
|
225
|
|
|
$mock = $this->getMock('phpDocumentor\GraphViz\Graph'); |
|
|
|
|
226
|
|
|
$mock->expects($this->any())->method('getName')->will($this->returnValue('MyName')); |
227
|
|
|
|
228
|
|
|
$this->fixture->addGraph($mock); |
229
|
|
|
$this->assertSame( |
230
|
|
|
$mock, |
231
|
|
|
$this->fixture->getGraph('MyName') |
232
|
|
|
); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @covers phpDocumentor\GraphViz\Graph::setNode |
237
|
|
|
*/ |
238
|
|
|
public function testSetNode() |
239
|
|
|
{ |
240
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
241
|
|
|
|
242
|
|
|
$mock = $this->getMock('phpDocumentor\GraphViz\Node', array(), array(), '', false); |
|
|
|
|
243
|
|
|
$mock->expects($this->any())->method('getName')->will($this->returnValue('MyName')); |
244
|
|
|
|
245
|
|
|
$this->assertSame( |
246
|
|
|
$this->fixture, |
247
|
|
|
$this->fixture->setNode($mock) |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @covers phpDocumentor\GraphViz\Graph::findNode |
253
|
|
|
*/ |
254
|
|
|
public function testFindNode() { |
255
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
256
|
|
|
|
257
|
|
|
$this->assertNull($this->fixture->findNode('MyNode')); |
258
|
|
|
|
259
|
|
|
$mock = $this->getMock('phpDocumentor\GraphViz\Node', array(), array(), '', false); |
|
|
|
|
260
|
|
|
$mock->expects($this->any())->method('getName')->will($this->returnValue('MyName')); |
261
|
|
|
$this->fixture->setNode($mock); |
262
|
|
|
$this->assertSame( |
263
|
|
|
$mock, |
264
|
|
|
$this->fixture->findNode('MyName') |
265
|
|
|
); |
266
|
|
|
|
267
|
|
|
$subGraph = Graph::create(); |
268
|
|
|
$mock2 = $this->getMock('phpDocumentor\GraphViz\Node', array(), array(), '', false); |
|
|
|
|
269
|
|
|
$mock2->expects($this->any())->method('getName')->will($this->returnValue('MyName2')); |
270
|
|
|
$subGraph->setNode($mock2); |
271
|
|
|
|
272
|
|
|
$this->fixture->addGraph($subGraph); |
273
|
|
|
$this->assertSame( |
274
|
|
|
$mock2, |
275
|
|
|
$this->fixture->findNode('MyName2') |
276
|
|
|
); |
277
|
|
|
|
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @covers phpDocumentor\GraphViz\Graph::__set |
282
|
|
|
* @todo Implement test__set(). |
283
|
|
|
*/ |
284
|
|
|
public function test__set() { |
285
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
286
|
|
|
|
287
|
|
|
$mock = $this->getMock('phpDocumentor\GraphViz\Node', array(), array(), '', false); |
|
|
|
|
288
|
|
|
$mock->expects($this->any())->method('getName')->will($this->returnValue('MyName')); |
289
|
|
|
|
290
|
|
|
$this->assertSame( |
291
|
|
|
$this->fixture, |
292
|
|
|
$this->fixture->__set('myNode', $mock) |
293
|
|
|
); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @covers phpDocumentor\GraphViz\Graph::__get |
298
|
|
|
* @todo Implement test__get(). |
299
|
|
|
*/ |
300
|
|
|
public function test__get() { |
301
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
302
|
|
|
|
303
|
|
|
$mock = $this->getMock('phpDocumentor\GraphViz\Node', array(), array(), '', false); |
|
|
|
|
304
|
|
|
$mock->expects($this->any())->method('getName')->will($this->returnValue('MyName')); |
305
|
|
|
|
306
|
|
|
$this->fixture->myNode = $mock; |
|
|
|
|
307
|
|
|
$this->assertSame( |
308
|
|
|
$mock, |
309
|
|
|
$this->fixture->myNode |
|
|
|
|
310
|
|
|
); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @covers phpDocumentor\GraphViz\Graph::link |
315
|
|
|
* @todo Implement testLink(). |
316
|
|
|
*/ |
317
|
|
|
public function testLink() { |
318
|
|
|
$this->markTestIncomplete('Need to redo mock technique.'); |
319
|
|
|
|
320
|
|
|
$mock = $this->getMock('phpDocumentor\GraphViz\Edge', array(), array(), '', false); |
|
|
|
|
321
|
|
|
|
322
|
|
|
$this->assertSame( |
323
|
|
|
$this->fixture, |
324
|
|
|
$this->fixture->link($mock) |
325
|
|
|
); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @covers phpDocumentor\GraphViz\Graph::export |
330
|
|
|
*/ |
331
|
|
|
public function testExportException() { |
332
|
|
|
$graph = Graph::create('My First Graph'); |
333
|
|
|
$filename = tempnam(sys_get_temp_dir(), 'tst'); |
334
|
|
|
|
335
|
|
|
$this->expectException('phpDocumentor\GraphViz\Exception'); |
336
|
|
|
$graph->export('fpd', $filename); |
337
|
|
|
|
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @covers phpDocumentor\GraphViz\Graph::export |
342
|
|
|
*/ |
343
|
|
|
public function testExport() { |
344
|
|
|
$graph = Graph::create('My First Graph'); |
345
|
|
|
$filename = tempnam(sys_get_temp_dir(), 'tst'); |
346
|
|
|
|
347
|
|
|
$this->assertSame( |
348
|
|
|
$graph, |
349
|
|
|
$graph->export('pdf', $filename) |
350
|
|
|
); |
351
|
|
|
$this->assertTrue(is_readable($filename)); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @covers phpDocumentor\GraphViz\Graph::__toString |
356
|
|
|
*/ |
357
|
|
|
public function test__toString() |
358
|
|
|
{ |
359
|
|
|
$graph = Graph::create('My First Graph'); |
360
|
|
|
$this->assertSame( |
361
|
|
|
$this->normalizeLineEndings( (string) $graph ), |
362
|
|
|
$this->normalizeLineEndings( ('digraph "My First Graph" {' . PHP_EOL . PHP_EOL . '}' )) |
363
|
|
|
); |
364
|
|
|
|
365
|
|
|
$graph->setLabel('PigeonPost'); |
|
|
|
|
366
|
|
|
$this->assertSame( |
367
|
|
|
$this->normalizeLineEndings( (string) $graph ), |
368
|
|
|
$this->normalizeLineEndings( ('digraph "My First Graph" {' . PHP_EOL . 'label="PigeonPost"' . PHP_EOL . '}' )) |
369
|
|
|
); |
370
|
|
|
|
371
|
|
|
$graph->setStrict(true); |
372
|
|
|
$this->assertSame( |
373
|
|
|
$this->normalizeLineEndings( (string) $graph ), |
374
|
|
|
$this->normalizeLineEndings( ('strict digraph "My First Graph" {' . PHP_EOL . 'label="PigeonPost"' . PHP_EOL . '}' )) |
375
|
|
|
); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Help avoid issue of "#Warning: Strings contain different line endings!" on Windows. |
380
|
|
|
*/ |
381
|
|
|
private function normalizeLineEndings($string) |
382
|
|
|
{ |
383
|
|
|
return preg_replace('~\R~u', "\r\n", $string); |
384
|
|
|
} |
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: