Skip to content

Commit c563912

Browse files
committed
Increase code coverage.
1 parent fcb8b98 commit c563912

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

spec/drupol/phptree/tests/TestGraphVizSpec.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function it_can_generate_a_graph()
3434

3535
$tree = new ValueNode('root', 2);
3636

37-
$nodes = [];
37+
$nodes = [0 => new ValueNode()];
3838
foreach (\range('A', 'F') as $letter) {
3939
$nodes[] = new ValueNode($letter, 2);
4040
}
@@ -78,4 +78,26 @@ public function it_can_create_a_graph()
7878
->render($tree)
7979
->shouldReturn($result . PHP_EOL);
8080
}
81+
82+
public function it_can_display()
83+
{
84+
$visitor = new BreadthFirstVisitor();
85+
$graph = new Graph();
86+
$graphviz = new GraphViz();
87+
88+
$this->beConstructedWith($visitor, $graph, $graphviz);
89+
90+
$tree = new ValueNode('root', 2);
91+
92+
$nodes = [];
93+
foreach (\range('A', 'F') as $letter) {
94+
$nodes[] = new ValueNode($letter, 2);
95+
}
96+
97+
$tree->add(...$nodes);
98+
99+
$this
100+
->display($tree)
101+
->shouldReturn($this);
102+
}
81103
}

spec/src/TestGraphViz.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class TestGraphViz extends GraphViz
1717
*/
1818
protected function hash(NodeInterface $node)
1919
{
20-
return $node->getValue();
20+
return $node->getValue() ?? parent::hash($node);
2121
}
2222
}

src/Render/GraphViz.php

-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ public function getGraph(NodeInterface $node): Graph
7373
/** @var int $hash_parent */
7474
$hash_parent = $this->hash($parent);
7575

76-
if (false === $this->graph->hasVertex($hash_parent)) {
77-
$this->graph->createVertex($hash_parent);
78-
}
79-
8076
$this->graph->getVertex($hash_parent)->createEdgeTo($this->graph->getVertex($hash));
8177
}
8278

0 commit comments

Comments
 (0)