Skip to content

Commit

Permalink
Merge pull request #51 from clue-labs/php7.4
Browse files Browse the repository at this point in the history
Test against PHP 7.4 and simplify test matrix
  • Loading branch information
clue authored Mar 25, 2020
2 parents ffb9911 + e3d6321 commit 0f96a98
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
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);
}
}

0 comments on commit 0f96a98

Please sign in to comment.