1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Grafizzi\Graph\Tests\IG03Test: a component of the Grafizzi library. |
6
|
|
|
* |
7
|
|
|
* (c) 2012 Frédéric G. MARAND <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Grafizzi is free software: you can redistribute it and/or modify it under the |
10
|
|
|
* terms of the GNU Lesser General Public License as published by the Free |
11
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
12
|
|
|
* later version. |
13
|
|
|
* |
14
|
|
|
* Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY |
15
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
17
|
|
|
* details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
20
|
|
|
* along with Grafizzi, in the COPYING.LESSER.txt file. If not, see |
21
|
|
|
* <http://www.gnu.org/licenses/> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Grafizzi\Graph\Tests; |
25
|
|
|
|
26
|
|
|
use Grafizzi\Graph\Attribute; |
27
|
|
|
use Grafizzi\Graph\Edge; |
28
|
|
|
use Grafizzi\Graph\Node; |
29
|
|
|
|
30
|
|
|
require 'vendor/autoload.php'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* A recreation of Image_GraphViz test3.phpt |
34
|
|
|
* |
35
|
|
|
* Image_GraphViz version author: Philippe Jausions <[email protected]> |
36
|
|
|
* |
37
|
|
|
* Test 3: "Drawing of fancy graph" |
38
|
|
|
* |
39
|
|
|
* Graph definition taken from Neato documentation, fig. 3 & 4 p. 5 |
40
|
|
|
* "Drawing graphs with dot" |
41
|
|
|
* Emden Gansner, Eleftherios Koutsofios and Stephen North / January 26, 2006 |
42
|
|
|
* |
43
|
|
|
* Setup logic and order of result lines slightly modified to account for the |
44
|
|
|
* API change: nodes must be created before they are referenced, be they |
45
|
|
|
* implicit or explicit in the resulting graph. |
46
|
|
|
*/ |
47
|
|
|
class IG03Test extends BaseGraphTest { |
48
|
|
|
|
49
|
|
|
public function setUp() : void { |
50
|
|
|
parent::setUpExtended(); |
|
|
|
|
51
|
|
|
$this->Graph->setDirected(true); |
52
|
|
|
$graph = &$this->Graph; |
53
|
|
|
$dic = &$this->dic; |
54
|
|
|
|
55
|
|
|
$graph->addChild($main = new Node($dic, 'main', array( |
56
|
|
|
new Attribute($dic, 'shape', 'box'), |
57
|
|
|
new Attribute($dic, 'comment', 'this is a comment'), |
58
|
|
|
))); |
59
|
|
|
$graph->addChild(new Edge($dic, $main, |
60
|
|
|
$parse = new Node($this->dic, 'parse'), array( |
61
|
|
|
new Attribute($dic, 'weight', 8) |
62
|
|
|
))); |
63
|
|
|
$graph->addChild(new Edge($dic, |
64
|
|
|
$parse = new Node($dic, 'parse', Node::implicit()), |
65
|
|
|
$execute = new Node($dic, 'execute', Node::implicit()) |
66
|
|
|
)); |
67
|
|
|
$graph->addChild(new Edge($dic, $main, |
68
|
|
|
$init = new Node($dic, 'init', Node::implicit()), array( |
69
|
|
|
new Attribute($dic, 'style', 'dotted') |
70
|
|
|
))); |
71
|
|
|
$graph->addChild(new Edge($dic, $main, |
72
|
|
|
$cleanup = new Node($dic, 'cleanup', Node::implicit()) |
73
|
|
|
)); |
74
|
|
|
|
75
|
|
|
// XXX The original example creates the node after the edge referencing it. |
76
|
|
|
$graph->addChild($make_string = new Node($dic, 'make_string', array( |
77
|
|
|
new Attribute($dic, 'label', "make a\nstring"), |
78
|
|
|
))); |
79
|
|
|
|
80
|
|
|
$graph->addChild(new Edge($dic, $execute, $make_string)); |
81
|
|
|
$graph->addChild(new Edge($dic, $execute, |
82
|
|
|
$printf = new Node($dic, 'printf', Node::implicit()) |
83
|
|
|
)); |
84
|
|
|
$graph->addChild(new Edge($dic, $init, $make_string)); |
85
|
|
|
$graph->addChild(new Edge($dic, $main, $printf, array( |
86
|
|
|
new Attribute($dic, 'style', 'bold'), |
87
|
|
|
new Attribute($dic, 'label', '100 times'), |
88
|
|
|
))); |
89
|
|
|
|
90
|
|
|
$graph->addChild($compare = new Node($dic, 'compare', array( |
91
|
|
|
new Attribute($dic, 'shape', 'box'), |
92
|
|
|
new Attribute($dic, 'style', 'filled'), |
93
|
|
|
new Attribute($dic, 'color', '.7 .3 1.0'), |
94
|
|
|
))); |
95
|
|
|
|
96
|
|
|
$graph->addChild(new Edge($dic, $execute, $compare, array( |
97
|
|
|
new Attribute($dic, 'color', 'red'), |
98
|
|
|
new Attribute($dic, 'comment', 'so is this'), |
99
|
|
|
))); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Tests Graph->build() |
104
|
|
|
*/ |
105
|
|
|
public function testBuild() { |
106
|
|
|
$expected = <<<'EOT' |
107
|
|
|
digraph G { |
108
|
|
|
main [ shape=box, comment="this is a comment" ]; |
109
|
|
|
main -> parse [ weight=8 ]; |
110
|
|
|
parse -> execute; |
111
|
|
|
main -> init [ style=dotted ]; |
112
|
|
|
main -> cleanup; |
113
|
|
|
make_string [ label="make a\nstring" ]; |
114
|
|
|
execute -> make_string; |
115
|
|
|
execute -> printf; |
116
|
|
|
init -> make_string; |
117
|
|
|
main -> printf [ style=bold, label="100 times" ]; |
118
|
|
|
compare [ shape=box, style=filled, color=".7 .3 1.0" ]; |
119
|
|
|
execute -> compare [ color=red, comment="so is this" ]; |
120
|
|
|
} /* /digraph G */ |
121
|
|
|
|
122
|
|
|
EOT; |
123
|
|
|
$this->check($expected, "Image_GraphViz test 3 passed."); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.