IG20bTest::testBuild()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
dl 32
loc 32
rs 9.408
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @file
5
 * Grafizzi\Graph\Tests\IG20bTest: 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\Cluster;
28
use Grafizzi\Graph\Edge;
29
use Grafizzi\Graph\Node;
30
31
require 'vendor/autoload.php';
32
33
/**
34
 * A recreation of Image_GraphViz test20b.phpt
35
 *
36
 * Image_GraphViz version author: Philippe Jausions <[email protected]>
37
 *
38
 * Test 20b: "Graph with edges on clusters not 'cluster'-named IDs"
39
 *
40
 * "Graph definition taken from GraphViz documentation"
41
 */
42 View Code Duplication
class IG20bTest extends BaseGraphTest {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
44
  public function setUp() : void {
45
    // not strict by default.
46
    parent::setUpExtended();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setUpExtended() instead of setUp()). Are you sure this is correct? If so, you might want to change this to $this->setUpExtended().

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:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
47
    $graph = $this->Graph;
48
    $dic = $this->dic;
49
    $graph->setDirected(true);
50
    $graph->setAttributes(array(
51
      new Attribute($dic, 'compound', true),
52
    ));
53
54
    $nullTitle = array(new Attribute($dic, 'title', NULL));
55
    $nodes = array();
56
57
    $graph->addChild($cluster0 = new Cluster($dic, 0, $nullTitle));
58
    foreach (array('a', 'b', 'c', 'd') as $name) {
59
      $cluster0->addChild($nodes[$name] = new Node($dic, $name));
60
    }
61
62
    $graph->addChild($cluster1 = new Cluster($dic, 1, $nullTitle));
63
    foreach (array('e', 'f', 'g') as $name) {
64
      $cluster1->addChild($nodes[$name] = new Node($dic, $name));
65
    }
66
67
    $graph->addChild(new Edge($dic, $nodes['a'], $nodes['b']));
68
    $graph->addChild(new Edge($dic, $nodes['a'], $nodes['c']));
69
    $graph->addChild(new Edge($dic, $nodes['b'], $nodes['d']));
70
71
    // Note how we use getBuildName() instead of getName() for lhead/ltail,
72
    // because this are the strings GraphViz expects.
73
    $graph->addChild(new Edge($dic, $nodes['b'], $nodes['f'], array(
74
      new Attribute($dic, 'lhead', $cluster1->getBuildName()),
75
    )));
76
    $graph->addChild(new Edge($dic, $nodes['c'], $nodes['d']));
77
    $graph->addChild(new Edge($dic, $nodes['c'], $nodes['g'], array(
78
      new Attribute($dic, 'ltail', $cluster0->getBuildName()),
79
      new Attribute($dic, 'lhead', $cluster1->getBuildName()),
80
    )));
81
    $graph->addChild(new Edge($dic, $nodes['c'],  $nodes['e'], array(
82
      new Attribute($dic, 'ltail', $cluster0->getBuildName()),
83
    )));
84
    $graph->addChild(new Edge($dic, $nodes['e'], $nodes['g']));
85
    $graph->addChild(new Edge($dic, $nodes['e'], $nodes['f']));
86
    $graph->addChild(new Edge($dic, $nodes['d'], $nodes['e']));
87
    $graph->addChild(new Edge($dic, $nodes['d'], $nodes['h'] = new Node($dic, 'h', array('implicit' => true))));
88
  }
89
90
  /**
91
   * Tests g->build()
92
   */
93
  public function testBuild() {
94
    $expected = <<<'EOT'
95
digraph G {
96
  compound=true;
97
98
  subgraph cluster_0 {
99
    a;
100
    b;
101
    c;
102
    d;
103
  } /* /subgraph cluster_0 */
104
  subgraph cluster_1 {
105
    e;
106
    f;
107
    g;
108
  } /* /subgraph cluster_1 */
109
  a -> b;
110
  a -> c;
111
  b -> d;
112
  b -> f [ lhead=cluster_1 ];
113
  c -> d;
114
  c -> g [ ltail=cluster_0, lhead=cluster_1 ];
115
  c -> e [ ltail=cluster_0 ];
116
  e -> g;
117
  e -> f;
118
  d -> e;
119
  d -> h;
120
} /* /digraph G */
121
122
EOT;
123
    $this->check($expected, "Image_graphViz test 20b passed.");
124
  }
125
}
126