Skip to content

Commit e0c689d

Browse files
authored
Merge pull request #8 from drupol/7-fix-broken-tests-on-travis-only
Issue #7: Trying to fix png image generation on Travis.
2 parents bc4fcd8 + 8d2333c commit e0c689d

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ php:
1414
- 7.3
1515

1616
before_install:
17-
- sudo apt-get install -y graphviz
17+
- sudo apt-get install -y graphviz graphviz-dev
1818

1919
install:
2020
- composer install

spec/drupol/phptree/Exporter/GraphSpec.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,31 @@
55
namespace spec\drupol\phptree\Exporter;
66

77
use drupol\phptree\Exporter\Graph;
8+
use drupol\phptree\Importer\Text;
89
use drupol\phptree\Node\ValueNode;
910
use Graphp\GraphViz\GraphViz;
10-
use spec\drupol\phptree\Node\NodeObjectBehavior;
11+
use PhpSpec\ObjectBehavior;
1112

1213
/**
1314
* Class GraphSpec.
1415
*
15-
* @method shouldHaveSameGraphImageFile(string $filepath)
16+
* @method shouldHaveSameTextExport(string $filepath)
1617
*/
17-
class GraphSpec extends NodeObjectBehavior
18+
class GraphSpec extends ObjectBehavior
1819
{
1920
/**
2021
* {@inheritdoc}
2122
*/
2223
public function getMatchers(): array
2324
{
2425
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();
2729

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);
2933
},
3034
];
3135
}
@@ -36,7 +40,7 @@ public function it_can_generate_a_graph()
3640
$child1 = new ValueNode('child1');
3741
$child2 = new ValueNode('child2');
3842
$child3 = new ValueNode('child3');
39-
$child4 = new ValueNode('child3');
43+
$child4 = new ValueNode('child4');
4044
$child1->add($child4);
4145

4246
$tree
@@ -52,7 +56,7 @@ public function it_can_generate_a_graph()
5256

5357
$this
5458
->export($tree)
55-
->shouldHaveSameGraphImageFile('tests/fixtures/Exporter/GraphSpec1.png');
59+
->shouldHaveSameTextExport('[root[child1[child4]][child2][child3]]');
5660
}
5761

5862
public function it_is_initializable()
-17.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)