BaseCompositeTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 90
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A testBuild() 0 46 2
A testGetBuildName() 0 4 1
A testGetType() 0 4 1
1
<?php
2
3
/**
4
 * @file
5
 * Grafizzi\Graph\Tests\BaseCompositeTest: 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
require 'vendor/autoload.php';
27
28
use Grafizzi\Graph\Edge;
29
use Grafizzi\Graph\Node;
30
use Grafizzi\Graph\Subgraph;
31
32
/**
33
 * Abstract base class for SubgraphTest/ClusterTest.
34
 */
35
abstract class BaseCompositeTest extends BaseGraphTest {
36
37
  /**
38
   * @var string
39
   *   The generate name for the subgraph.
40
   */
41
  protected $name;
42
43
  /**
44
   * @var Subgraph
45
   */
46
  protected $Subgraph;
47
48
  /**
49
   * @var string
50
   *   The type of subgraph being tested.
51
   */
52
  protected $type;
53
54
  /**
55
   * Cleans up the environment after running a test.
56
   */
57
  protected function tearDown() : void {
58
    $this->Subgraph = null;
59
    parent::tearDown();
60
  }
61
62
  public function testBuild() {
63
    $n11 = new Node($this->dic, 'node11');
64
    $n12 = new Node($this->dic, 'node12');
65
    $e11_12 = new Edge($this->dic, $n11, $n12);
66
    foreach (array($n11, $n12, $e11_12) as $element) {
67
      $this->Subgraph->addChild($element);
68
    }
69
    $expected = <<<EOT
70
subgraph {$this->name} {
71
  node11;
72
  node12;
73
  node11 -> node12;
74
} /* /subgraph {$this->name} */
75
76
EOT;
77
78
    $build = $this->Subgraph->build();
79
    $this->assertEquals($expected, $build, "Unbound {$this->type} (2 nodes, 1 edge) built correctly.");
80
81
    // Test bound subgraph build.
82
    $this->Graph->addChild($this->Subgraph);
83
    $expected = <<<EOT
84
  subgraph {$this->name} {
85
    node11;
86
    node12;
87
    node11 -> node12;
88
  } /* /subgraph {$this->name} */
89
90
EOT;
91
    $build = $this->Subgraph->build();
92
    $this->assertEquals($expected, $build, "Bound {$this->type} (2 nodes, 1 edge) built correctly.");
93
94
    // Test graph with bound subgraph.
95
    $expected = <<<EOT
96
digraph G {
97
  subgraph {$this->name} {
98
    node11;
99
    node12;
100
    node11 -> node12;
101
  } /* /subgraph {$this->name} */
102
} /* /digraph G */
103
104
EOT;
105
    $build = $this->Graph->build();
106
    $this->assertEquals($expected, $build, "Graph with 1 {$this->type} (2 nodes, 1 edge) built correctly.");
107
  }
108
109
  /**
110
   * Tests Subgraph->getBuildName()
111
   */
112
  public function testGetBuildName() {
113
    $buildName = $this->Subgraph->getBuildName();
114
    $this->assertEquals($this->name, $buildName, "{$this->type} name matches the expected format.");
115
  }
116
117
  /**
118
   * Tests Subgraph->getType()
119
   */
120
  public function testGetType() {
121
    $type = $this->Subgraph->getType();
122
    $this->assertEquals('subgraph', $type, "Type of {$this->type} is \"subgraph\".");
123
  }
124
}
125