Skip to content

Commit 67c789a

Browse files
committed
Update test instructions and support PHPUnit 6 and PHPUnit 5
1 parent 81db404 commit 67c789a

File tree

7 files changed

+40
-16
lines changed

7 files changed

+40
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ php:
88
install:
99
- composer install --prefer-source --no-interaction
1010
script:
11-
- php vendor/bin/phpunit --coverage-text
11+
- vendor/bin/phpunit --coverage-text

README.md

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

19+
## Tests
20+
21+
To run the test suite, you first need to clone this repo and then install all
22+
dependencies [through Composer](https://getcomposer.org):
23+
24+
```bash
25+
$ composer install
26+
```
27+
28+
To run the test suite, go to the project root and run:
29+
30+
```bash
31+
$ php vendor/bin/phpunit
32+
```
33+
1934
## License
2035

2136
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)