Completed
Pull Request — master (#7)
by Frédéric G.
03:39 queued 02:30
created

GraphTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @file
5
 * Grafizzi\Graph\Tests\GraphTest: 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
25
namespace Grafizzi\Graph\Tests;
26
27
require 'vendor/autoload.php';
28
29
use \Grafizzi\Graph\Attribute;
30
use \Grafizzi\Graph\Graph;
31
32
/**
33
 * Graph test case.
34
 */
35
class GraphTest extends BaseGraphTest {
36
37
  public function setUp() : void {
38
    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...
39
  }
40
41
  /**
42
   * Tests Graph->build()
43
   */
44
  public function testBuild() {
45
    $graph = $this->Graph->build();
46
    $this->assertEquals(<<<EOT
47
digraph G {
48
} /* /digraph G */
49
50
EOT
51
      , $graph, 'Empty unnamed graph matches expected format.');
52
  }
53
54
  // Normal attributes list.
55
  public function testBuildAttributesNormal() {
56
    $this->Graph->setAttributes(array(
57
      new Attribute($this->dic, 'foo', 'bar'),
58
      new Attribute($this->dic, 'baz', 'quux'),
59
    ));
60
    $expected = <<<EOT
61
digraph G {
62
  foo=bar;
63
  baz=quux;
64
} /* /digraph G */
65
66
EOT;
67
    $actual = $this->Graph->build();
68
    $this->assertEquals($expected, $actual);
69
  }
70
71
  // Attribute list with empty title in middle.
72 View Code Duplication
  public function testBuildAttributesEmptyMiddle() {
0 ignored issues
show
Duplication introduced by
This method 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...
73
    $this->Graph->setAttributes(array(
74
      new Attribute($this->dic, 'foo', 'bar'),
75
      new Attribute($this->dic, 'title', ''),
76
      new Attribute($this->dic, 'baz', 'quux'),
77
    ));
78
    $expected = <<<EOT
79
digraph G {
80
  foo=bar;
81
  baz=quux;
82
} /* /digraph G */
83
84
EOT;
85
    $actual = $this->Graph->build();
86
    $this->assertEquals($expected, $actual);
87
  }
88
89
  // Attribute list with empty title as single attribute.
90
  public function testBuildAttributesOnlyEmpty() {
91
    $this->Graph->setAttributes(array(
92
        new Attribute($this->dic, 'title', ''),
93
    ));
94
    $expected = <<<EOT
95
digraph G {
96
} /* /digraph G */
97
98
EOT;
99
    $actual = $this->Graph->build();
100
    $this->assertEquals($expected, $actual);
101
  }
102
103
  // Attribute list with empty title as last attribute.
104 View Code Duplication
  public function testBuildAttributesEmptyLast() {
0 ignored issues
show
Duplication introduced by
This method 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...
105
    $this->Graph->setAttributes(array(
106
      new Attribute($this->dic, 'foo', 'bar'),
107
      new Attribute($this->dic, 'baz', 'quux'),
108
      new Attribute($this->dic, 'title', ''),
109
    ));
110
    $expected = <<<EOT
111
digraph G {
112
  foo=bar;
113
  baz=quux;
114
} /* /digraph G */
115
116
EOT;
117
    $actual = $this->Graph->build();
118
    $this->assertEquals($expected, $actual);
119
  }
120
121
  /**
122
   * Tests Graph::getAllowedChildTypes()
123
   */
124
  public function testGetAllowedChildTypes() {
125
    $types = Graph::getAllowedChildTypes();
126
    $this->assertTrue(is_array($types) && count($types) == 5,
127
      'Five child types allowed for Graphs.');
128
    ksort($types);
129
    $expectedTypes = array(
130
      'cluster',
131
      'edge',
132
      'multiedge',
133
      'node',
134
      'subgraph',
135
    );
136
    $this->assertEquals($expectedTypes, $types);
137
  }
138
139
  /**
140
   * Tests Graph->getDirected()
141
   */
142
  public function testGetDirected() {
143
    $dir = $this->Graph->getDirected();
144
    $this->assertEquals(true, $dir, "Graph is directed by default.");
145
  }
146
147
  /**
148
   * Tests Graph::getType()
149
   */
150
  public function testGetType() {
151
    $this->Graph->setDirected(false);
152
    $type = $this->Graph->getType();
153
    $this->assertEquals('graph', $type, 'Graph type is "graph".');
154
155
    $this->Graph->setDirected(true);
156
    $type = $this->Graph->getType();
157
    $this->assertEquals('digraph', $type, 'Graph type is "digraph".');
158
  }
159
160
  /**
161
   * Tests Graph->setDirected()
162
   */
163
  public function testSetDirected() {
164
    $this->Graph->setDirected(false);
165
    $this->assertFalse($this->Graph->getDirected(),
166
      "Setting directed to false changes the result of getDirected().");
167
  }
168
}
169