Skip to content

Commit

Permalink
Increase code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 11, 2018
1 parent fcb8b98 commit c563912
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
24 changes: 23 additions & 1 deletion spec/drupol/phptree/tests/TestGraphVizSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function it_can_generate_a_graph()

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

$nodes = [];
$nodes = [0 => new ValueNode()];
foreach (\range('A', 'F') as $letter) {
$nodes[] = new ValueNode($letter, 2);
}
Expand Down Expand Up @@ -78,4 +78,26 @@ public function it_can_create_a_graph()
->render($tree)
->shouldReturn($result . PHP_EOL);
}

public function it_can_display()
{
$visitor = new BreadthFirstVisitor();
$graph = new Graph();
$graphviz = new GraphViz();

$this->beConstructedWith($visitor, $graph, $graphviz);

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

$nodes = [];
foreach (\range('A', 'F') as $letter) {
$nodes[] = new ValueNode($letter, 2);
}

$tree->add(...$nodes);

$this
->display($tree)
->shouldReturn($this);
}
}
2 changes: 1 addition & 1 deletion spec/src/TestGraphViz.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class TestGraphViz extends GraphViz
*/
protected function hash(NodeInterface $node)
{
return $node->getValue();
return $node->getValue() ?? parent::hash($node);
}
}
4 changes: 0 additions & 4 deletions src/Render/GraphViz.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ public function getGraph(NodeInterface $node): Graph
/** @var int $hash_parent */
$hash_parent = $this->hash($parent);

if (false === $this->graph->hasVertex($hash_parent)) {
$this->graph->createVertex($hash_parent);
}

$this->graph->getVertex($hash_parent)->createEdgeTo($this->graph->getVertex($hash));
}

Expand Down

0 comments on commit c563912

Please sign in to comment.