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
- use spec \ drupol \ phptree \ Node \ NodeObjectBehavior ;
11
+ use PhpSpec \ ObjectBehavior ;
11
12
12
13
/**
13
14
* Class GraphSpec.
14
15
*
15
- * @method shouldHaveSameGraphImageFile (string $filepath)
16
+ * @method shouldHaveSameTextExport (string $filepath)
16
17
*/
17
- class GraphSpec extends NodeObjectBehavior
18
+ class GraphSpec extends ObjectBehavior
18
19
{
19
20
/**
20
21
* {@inheritdoc}
21
22
*/
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
+ 'haveSameTextExport ' => function ($ left , $ right ) {
27
+ $ importer = new Text ();
28
+ $ exporter = new Graph ();
27
29
28
- return \sha1 (\file_get_contents ($ left )) === \sha1 (\file_get_contents ($ key ));
30
+ $ right = $ exporter ->export ($ importer ->import ($ right ));
31
+
32
+ return (new GraphViz ())->createImageSrc ($ left ) === (new GraphViz ())->createImageSrc ($ right );
29
33
},
30
34
];
31
35
}
@@ -36,7 +40,7 @@ public function it_can_generate_a_graph()
36
40
$ child1 = new ValueNode ('child1 ' );
37
41
$ child2 = new ValueNode ('child2 ' );
38
42
$ child3 = new ValueNode ('child3 ' );
39
- $ child4 = new ValueNode ('child3 ' );
43
+ $ child4 = new ValueNode ('child4 ' );
40
44
$ child1 ->add ($ child4 );
41
45
42
46
$ tree
@@ -52,7 +56,7 @@ public function it_can_generate_a_graph()
52
56
53
57
$ this
54
58
->export ($ tree )
55
- ->shouldHaveSameGraphImageFile ( ' tests/fixtures/Exporter/GraphSpec1.png ' );
59
+ ->shouldHaveSameTextExport ( ' [root[child1[child4]][child2][child3]] ' );
56
60
}
57
61
58
62
public function it_is_initializable ()
0 commit comments