Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #7: Trying to fix png image generation on Travis. #8

Merged
merged 1 commit into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions spec/drupol/phptree/Exporter/GraphSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@
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}
*/
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);
},
];
}
Expand All @@ -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
Expand All @@ -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()
Expand Down
Binary file removed tests/fixtures/Exporter/GraphSpec1.png
Binary file not shown.