5
5
namespace spec \drupol \phptree \Exporter ;
6
6
7
7
use drupol \phptree \Exporter \Graph ;
8
+ use drupol \phptree \Importer \Text ;
8
9
use drupol \phptree \Node \ValueNode ;
9
10
use Graphp \GraphViz \GraphViz ;
10
11
use spec \drupol \phptree \Node \NodeObjectBehavior ;
@@ -22,20 +23,13 @@ class GraphSpec extends NodeObjectBehavior
22
23
public function getMatchers (): array
23
24
{
24
25
return [
25
- 'haveSameGraphImageFile ' => function ($ subject , $ key ) {
26
- $ left = (new GraphViz ())->setFormat ('png ' )->createImageFile ($ subject );
26
+ 'haveSameGraphImageFile ' => function ($ left , $ right ) {
27
+ $ importer = new Text ();
28
+ $ exporter = new Graph ();
27
29
28
- $ left = file_get_contents ($ left );
29
- var_dump ('file_get_contents($left) ' );
30
- print_r ($ left );
30
+ $ right = $ exporter ->export ($ importer ->import ($ right ));
31
31
32
- var_dump ('right ' );
33
- print_r (file_get_contents ($ key ));
34
-
35
- var_dump (sha1 ($ left ));
36
- var_dump (sha1 (file_get_contents ($ key )));
37
-
38
- return \sha1 ($ left ) === \sha1 (\file_get_contents ($ key ));
32
+ return (new GraphViz ())->createImageSrc ($ left ) === (new GraphViz ())->createImageSrc ($ right );
39
33
},
40
34
];
41
35
}
@@ -46,7 +40,7 @@ public function it_can_generate_a_graph()
46
40
$ child1 = new ValueNode ('child1 ' );
47
41
$ child2 = new ValueNode ('child2 ' );
48
42
$ child3 = new ValueNode ('child3 ' );
49
- $ child4 = new ValueNode ('child3 ' );
43
+ $ child4 = new ValueNode ('child4 ' );
50
44
$ child1 ->add ($ child4 );
51
45
52
46
$ tree
@@ -62,7 +56,7 @@ public function it_can_generate_a_graph()
62
56
63
57
$ this
64
58
->export ($ tree )
65
- ->shouldHaveSameGraphImageFile (getcwd () . ' /tests/fixtures/Exporter/GraphSpec1.png ' );
59
+ ->shouldHaveSameGraphImageFile (' [root[child1[child4]][child2][child3]] ' );
66
60
}
67
61
68
62
public function it_is_initializable ()
0 commit comments