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

Test against PHP 7.4 and simplify test matrix #51

Merged
merged 2 commits into from
Mar 25, 2020
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
27 changes: 14 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
language: php

php:
# - 5.3 # requires old distro, see below
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm # ignore errors, see below

# lock distro so future defaults will not break the build
dist: trusty

matrix:
include:
- php: 5.3
dist: precise
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
- name: "Build phar"
php: 7.2
script: composer build
- php: 7.2
- name: "Test dependency installation"
php: 7.2
install: []
script: composer install --dry-run --working-dir=tests/install-as-dep
- php: hhvm-3.18
allow_failures:
- php: hhvm
- php: hhvm-3.18

sudo: false

install:
- composer install --prefer-source --no-interaction
- composer install --no-interaction

script:
- vendor/bin/phpunit --coverage-text
52 changes: 42 additions & 10 deletions tests/GraphComposerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
<?php

use Clue\GraphComposer\Graph\GraphComposer;
use Graphp\GraphViz\GraphViz;
use Fhaculty\Graph\Graph;

class GraphVizMockDisplay extends GraphViz
{
public $called = 0;
public function display(Graph $graph)
{
++$this->called;
}
}

class GraphVizMockCreateImageFile extends GraphViz
{
public $called = 0;
public function createImageFile(Graph $graph)
{
return 'test' . ++$this->called . '.png';
}
}

class GraphVizMockSetFormat extends GraphViz
{
public $called = null;
public function setFormat($format)
{
$this->called = $format;
}
}

class GraphTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -15,40 +44,43 @@ public function testCreateGraph()
$this->assertTrue(count($graph->getVertices()) > 0);
}

public function testWillDisplayGraph()
public function testDisplayGraphCallsDisplayGraphViz()
{
$dir = __DIR__ . '/../';

$graphviz = $this->getMock('Graphp\GraphViz\GraphViz');
$graphviz->expects($this->once())->method('display');
// mocking with PHP 7.4 reports error with legacy PHPUnit, create manual mock classes instead
$graphviz = new GraphVizMockDisplay();

$graphComposer = new GraphComposer($dir, $graphviz);
$graphComposer->displayGraph();

$this->assertEquals(1, $graphviz->called);
}

public function testWillWriteTemporaryGraph()
public function testGetImagePathWillCreateTemporaryImageFileViaGraphViz()
{
$dir = __DIR__ . '/../';

$graphviz = $this->getMock('Graphp\GraphViz\GraphViz');
$graphviz->expects($this->once())->method('createImageFile')->will($this->returnValue('test.png'));
// mocking with PHP 7.4 reports error with legacy PHPUnit, create manual mock classes instead
$graphviz = new GraphVizMockCreateImageFile();

$graphComposer = new GraphComposer($dir, $graphviz);
$ret = $graphComposer->getImagePath();

$this->assertEquals('test.png', $ret);
$this->assertEquals('test1.png', $ret);
}

public function testWillSetFormat()
public function testSetFormatWillSetFormatOnGraphViz()
{
$dir = __DIR__ . '/../';

$graphviz = $this->getMock('Graphp\GraphViz\GraphViz');
$graphviz->expects($this->once())->method('setFormat')->with($this->equalTo('gif'));
// mocking with PHP 7.4 reports error with legacy PHPUnit, create manual mock classes instead
$graphviz = new GraphVizMockSetFormat();

$graphComposer = new GraphComposer($dir, $graphviz);
$ret = $graphComposer->setFormat('gif');

$this->assertEquals($graphComposer, $ret);
$this->assertEquals('gif', $graphviz->called);
}
}