diff --git a/.travis.yml b/.travis.yml index 918f106..da676f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ php: - 7.3 before_install: -- sudo apt-get install -y graphviz +- sudo apt-get install -y graphviz graphviz-dev install: - composer install diff --git a/spec/drupol/phptree/Exporter/GraphSpec.php b/spec/drupol/phptree/Exporter/GraphSpec.php index 36674e9..3cba2dd 100644 --- a/spec/drupol/phptree/Exporter/GraphSpec.php +++ b/spec/drupol/phptree/Exporter/GraphSpec.php @@ -5,16 +5,17 @@ namespace spec\drupol\phptree\Exporter; use drupol\phptree\Exporter\Graph; +use drupol\phptree\Importer\Text; use drupol\phptree\Node\ValueNode; use Graphp\GraphViz\GraphViz; -use spec\drupol\phptree\Node\NodeObjectBehavior; +use PhpSpec\ObjectBehavior; /** * Class GraphSpec. * - * @method shouldHaveSameGraphImageFile(string $filepath) + * @method shouldHaveSameTextExport(string $filepath) */ -class GraphSpec extends NodeObjectBehavior +class GraphSpec extends ObjectBehavior { /** * {@inheritdoc} @@ -22,10 +23,13 @@ class GraphSpec extends NodeObjectBehavior public function getMatchers(): array { return [ - 'haveSameGraphImageFile' => function ($subject, $key) { - $left = (new GraphViz())->setFormat('png')->createImageFile($subject); + 'haveSameTextExport' => function ($left, $right) { + $importer = new Text(); + $exporter = new Graph(); - return \sha1(\file_get_contents($left)) === \sha1(\file_get_contents($key)); + $right = $exporter->export($importer->import($right)); + + return (new GraphViz())->createImageSrc($left) === (new GraphViz())->createImageSrc($right); }, ]; } @@ -36,7 +40,7 @@ public function it_can_generate_a_graph() $child1 = new ValueNode('child1'); $child2 = new ValueNode('child2'); $child3 = new ValueNode('child3'); - $child4 = new ValueNode('child3'); + $child4 = new ValueNode('child4'); $child1->add($child4); $tree @@ -52,7 +56,7 @@ public function it_can_generate_a_graph() $this ->export($tree) - ->shouldHaveSameGraphImageFile('tests/fixtures/Exporter/GraphSpec1.png'); + ->shouldHaveSameTextExport('[root[child1[child4]][child2][child3]]'); } public function it_is_initializable() diff --git a/tests/fixtures/Exporter/GraphSpec1.png b/tests/fixtures/Exporter/GraphSpec1.png deleted file mode 100644 index b60ddd9..0000000 Binary files a/tests/fixtures/Exporter/GraphSpec1.png and /dev/null differ