Skip to content

Commit 9a1ba15

Browse files
authored
Merge pull request #32 from clue-labs/tests
Update test suite to support PHPUnit 6 and PHPUnit 5 and support running on legacy PHP 5.3 through PHP 7.2 and HHVM
2 parents 81db404 + 174efba commit 9a1ba15

File tree

7 files changed

+68
-21
lines changed

7 files changed

+68
-21
lines changed

.travis.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
language: php
2+
23
php:
3-
- 5.6
4-
- 5.5
4+
# - 5.3 # requires old distro, see below
55
- 5.4
6-
- 5.3
7-
- hhvm
6+
- 5.5
7+
- 5.6
8+
- 7.0
9+
- 7.1
10+
- 7.2
11+
- hhvm # ignore errors, see below
12+
13+
# lock distro so future defaults will not break the build
14+
dist: trusty
15+
16+
matrix:
17+
include:
18+
- php: 5.3
19+
dist: precise
20+
allow_failures:
21+
- php: hhvm
22+
23+
sudo: false
24+
825
install:
9-
- composer install --prefer-source --no-interaction
26+
- composer install --no-interaction
27+
1028
script:
11-
- php vendor/bin/phpunit --coverage-text
29+
- vendor/bin/phpunit --coverage-text

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ The recommended way to install this library is [through composer](http://getcomp
1616
}
1717
```
1818

19+
This project aims to run on any platform and thus does not require any PHP
20+
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
21+
HHVM.
22+
It's *highly recommended to use PHP 7+* for this project.
23+
24+
## Tests
25+
26+
To run the test suite, you first need to clone this repo and then install all
27+
dependencies [through Composer](https://getcomposer.org):
28+
29+
```bash
30+
$ composer install
31+
```
32+
33+
To run the test suite, go to the project root and run:
34+
35+
```bash
36+
$ php vendor/bin/phpunit
37+
```
38+
1939
## License
2040

2141
Released under the terms of the permissive [MIT license](http://opensource.org/licenses/MIT).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"clue/graph": "~0.9.0|~0.8.0"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "~4.0"
18+
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
1919
},
2020
"autoload": {
2121
"psr-4": {"Graphp\\Algorithms\\": "src/"}

tests/MaxFlow/EdmondsKarpTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22

33
use Fhaculty\Graph\Exception\UnexpectedValueException;
4-
54
use Fhaculty\Graph\Graph;
6-
75
use Graphp\Algorithms\MaxFlow\EdmondsKarp as AlgorithmMaxFlowEdmondsKarp;
6+
use PHPUnit\Framework\TestCase;
87

9-
class EdmondsKarpTest extends PHPUnit_Framework_TestCase
8+
class EdmondsKarpTest extends TestCase
109
{
1110
public function testEdgeDirected()
1211
{

tests/MaximumMatching/FlowTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22

33
use Fhaculty\Graph\Graph;
4-
5-
use Graphp\Algorithms\MaximumMatching\Flow;
6-
74
use Fhaculty\Graph\Loader\EdgeListBipartit;
5+
use Graphp\Algorithms\MaximumMatching\Flow;
6+
use PHPUnit\Framework\TestCase;
87

9-
class FlowTest extends PHPUnit_Framework_TestCase
8+
class FlowTest extends TestCase
109
{
1110
// /**
1211
// * run algorithm with small graph and check result against known result

tests/ShortestPath/MooreBellmanFordTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function testUndirectedNegativeWeightIsCycle()
5656
$alg = $this->createAlg($v1);
5757

5858
$cycle = $alg->getCycleNegative();
59+
60+
$this->assertInstanceOf('Fhaculty\Graph\Walk', $cycle);
5961
}
6062

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

7072
$cycle = $alg->getCycleNegative();
73+
74+
$this->assertInstanceOf('Fhaculty\Graph\Walk', $cycle);
7175
}
7276

7377
public function testNegativeComponentHasCycle()
@@ -90,7 +94,16 @@ public function testNegativeComponentHasCycle()
9094

9195
// first component does not have a cycle
9296
$alg = $this->createAlg($v1);
93-
$this->setExpectedException('UnderflowException');
97+
$this->expectException('UnderflowException');
9498
$alg->getCycleNegative();
9599
}
100+
101+
public function expectException($class)
102+
{
103+
if (method_exists($this, 'setExpectedException')) {
104+
$this->setExpectedException($class);
105+
} else {
106+
parent::expectException($class);
107+
}
108+
}
96109
}

tests/bootstrap.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
use Fhaculty\Graph\Graph;
66
use Fhaculty\Graph\Vertex;
77
use Fhaculty\Graph\Set\Vertices;
8+
use PHPUnit\Framework\TestCase as BaseTestCase;
89

910
(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);
1011

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

3031
foreach ($expected->getVertices()->getMap() as $vid => $vertex) {
31-
try {
32-
$other = $actual->getVertex($vid);
33-
} catch (Exception $e) {
34-
$this->fail();
35-
}
32+
$other = $actual->getVertex($vid);
33+
3634
if ($this->getVertexDump($vertex) !== $this->getVertexDump($vertex)) {
3735
$this->fail();
3836
}

0 commit comments

Comments
 (0)