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

Update test suite to support PHPUnit 6 and PHPUnit 5 and support running on legacy PHP 5.3 through PHP 7.2 and HHVM #32

Merged
merged 2 commits into from
Sep 28, 2018
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
30 changes: 24 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
language: php

php:
- 5.6
- 5.5
# - 5.3 # requires old distro, see below
- 5.4
- 5.3
- hhvm
- 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
allow_failures:
- php: hhvm

sudo: false

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

script:
- php vendor/bin/phpunit --coverage-text
- vendor/bin/phpunit --coverage-text
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ The recommended way to install this library is [through composer](http://getcomp
}
```

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
HHVM.
It's *highly recommended to use PHP 7+* for this project.

## Tests

To run the test suite, you first need to clone this repo and then install all
dependencies [through Composer](https://getcomposer.org):

```bash
$ composer install
```

To run the test suite, go to the project root and run:

```bash
$ php vendor/bin/phpunit
```

## License

Released under the terms of the permissive [MIT license](http://opensource.org/licenses/MIT).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"clue/graph": "~0.9.0|~0.8.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
},
"autoload": {
"psr-4": {"Graphp\\Algorithms\\": "src/"}
Expand Down
5 changes: 2 additions & 3 deletions tests/MaxFlow/EdmondsKarpTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

use Fhaculty\Graph\Exception\UnexpectedValueException;

use Fhaculty\Graph\Graph;

use Graphp\Algorithms\MaxFlow\EdmondsKarp as AlgorithmMaxFlowEdmondsKarp;
use PHPUnit\Framework\TestCase;

class EdmondsKarpTest extends PHPUnit_Framework_TestCase
class EdmondsKarpTest extends TestCase
{
public function testEdgeDirected()
{
Expand Down
7 changes: 3 additions & 4 deletions tests/MaximumMatching/FlowTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

use Fhaculty\Graph\Graph;

use Graphp\Algorithms\MaximumMatching\Flow;

use Fhaculty\Graph\Loader\EdgeListBipartit;
use Graphp\Algorithms\MaximumMatching\Flow;
use PHPUnit\Framework\TestCase;

class FlowTest extends PHPUnit_Framework_TestCase
class FlowTest extends TestCase
{
// /**
// * run algorithm with small graph and check result against known result
Expand Down
15 changes: 14 additions & 1 deletion tests/ShortestPath/MooreBellmanFordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function testUndirectedNegativeWeightIsCycle()
$alg = $this->createAlg($v1);

$cycle = $alg->getCycleNegative();

$this->assertInstanceOf('Fhaculty\Graph\Walk', $cycle);
}

public function testLoopNegativeWeightIsCycle()
Expand All @@ -68,6 +70,8 @@ public function testLoopNegativeWeightIsCycle()
$alg = $this->createAlg($v1);

$cycle = $alg->getCycleNegative();

$this->assertInstanceOf('Fhaculty\Graph\Walk', $cycle);
}

public function testNegativeComponentHasCycle()
Expand All @@ -90,7 +94,16 @@ public function testNegativeComponentHasCycle()

// first component does not have a cycle
$alg = $this->createAlg($v1);
$this->setExpectedException('UnderflowException');
$this->expectException('UnderflowException');
$alg->getCycleNegative();
}

public function expectException($class)
{
if (method_exists($this, 'setExpectedException')) {
$this->setExpectedException($class);
} else {
parent::expectException($class);
}
}
}
10 changes: 4 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use Fhaculty\Graph\Graph;
use Fhaculty\Graph\Vertex;
use Fhaculty\Graph\Set\Vertices;
use PHPUnit\Framework\TestCase as BaseTestCase;

(include_once __DIR__ . '/../vendor/autoload.php') OR die(PHP_EOL . 'ERROR: composer autoloader not found, run "composer install" or see README for instructions' . PHP_EOL);

class TestCase extends PHPUnit_Framework_TestCase
class TestCase extends BaseTestCase
{
protected function assertGraphEquals(Graph $expected, Graph $actual)
{
Expand All @@ -28,11 +29,8 @@ protected function assertGraphEquals(Graph $expected, Graph $actual)
// do not use assertVertexEquals() in order to not increase assertion counter

foreach ($expected->getVertices()->getMap() as $vid => $vertex) {
try {
$other = $actual->getVertex($vid);
} catch (Exception $e) {
$this->fail();
}
$other = $actual->getVertex($vid);

if ($this->getVertexDump($vertex) !== $this->getVertexDump($vertex)) {
$this->fail();
}
Expand Down