Skip to content

Commit df0781f

Browse files
authored
Merge pull request #200 from SimonFrings/tests09
Run tests on PHP7.4, PHP8 and PHPUnit 9.3
2 parents 9cdab22 + 67b7ab5 commit df0781f

17 files changed

+156
-138
lines changed

.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.travis.yml export-ignore
4+
/examples/ export-ignore
5+
/phpunit.xml.dist export-ignore
6+
/phpunit.xml.legacy export-ignore
7+
/tests/ export-ignore

.travis.yml

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
language: php
22

3-
php:
4-
# - 5.3 # requires old distro, see below
5-
- 5.4
6-
- 5.5
7-
- 5.6
8-
- 7.0
9-
- 7.1
10-
- 7.2
11-
- hhvm # ignore errors, see below
12-
133
# lock distro so future defaults will not break the build
144
dist: trusty
155

16-
matrix:
6+
jobs:
177
include:
188
- php: 5.3
199
dist: precise
10+
- php: 5.4
11+
- php: 5.5
12+
- php: 5.6
13+
- php: 7.0
14+
- php: 7.1
15+
- php: 7.2
16+
- php: 7.3
17+
- php: 7.4
18+
- php: hhvm-3.18
2019
allow_failures:
21-
- php: hhvm
22-
23-
sudo: false
20+
- php: hhvm-3.18
2421

2522
install:
26-
- composer install --no-interaction
23+
- composer install
2724

2825
script:
29-
- vendor/bin/phpunit --coverage-text
26+
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
27+
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ $ composer require clue/graph:^0.9.1
115115
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
116116

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

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
}
2323
},
2424
"require": {
25-
"php": "^7.0 || ^5.3"
25+
"php": ">=5.3"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
28+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
2929
},
3030
"suggest": {
3131
"graphp/graphviz": "GraphViz graph drawing / DOT output",

phpunit.xml.dist

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php"
4-
colors="true" convertErrorsToExceptions="true"
5-
convertNoticesToExceptions="true"
6-
convertWarningsToExceptions="true"
7-
>
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
cacheResult="false">
89
<testsuites>
9-
<testsuite name="Graph Test Suite">
10+
<testsuite name="Graph test suite">
1011
<directory>./tests/</directory>
1112
</testsuite>
1213
</testsuites>
13-
<filter>
14-
<whitelist>
14+
<coverage>
15+
<include>
1516
<directory>./src/</directory>
16-
</whitelist>
17-
</filter>
17+
</include>
18+
</coverage>
1819
</phpunit>

phpunit.xml.legacy

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="Graph test suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

src/Exception/NegativeCycleException.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ class NegativeCycleException extends UnexpectedValueException implements Graph\E
1414
*/
1515
private $cycle;
1616

17-
public function __construct($message, $code = NULL, $previous = NULL, Walk $cycle)
17+
public function __construct($message, $code = NULL, $previous = NULL, Walk $cycle = null)
1818
{
19+
// $cycle is required, but required argument may not appear after option arguments as of PHP 8
20+
if ($cycle === null) {
21+
throw new \InvalidArgumentException('Missing required cycle');
22+
}
23+
1924
parent::__construct($message, $code, $previous);
2025
$this->cycle = $cycle;
2126
}

tests/Edge/EdgeAttributesTest.php

+13-22
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ class EdgeAttributesTest extends TestCase
1414
*/
1515
private $edge;
1616

17-
public function setUp()
17+
/**
18+
* @before
19+
*/
20+
public function setUpGraph()
1821
{
1922

2023
$graph = new Graph();
@@ -40,61 +43,49 @@ public function testCanSetFlowBeforeCapacity()
4043
$this->assertEquals(null, $this->edge->getCapacityRemaining());
4144
}
4245

43-
/**
44-
* @expectedException RangeException
45-
*/
4646
public function testFlowMustNotExceedCapacity()
4747
{
4848
$this->edge->setCapacity(20);
49+
50+
$this->setExpectedException('RangeException');
4951
$this->edge->setFlow(100);
5052
}
5153

52-
/**
53-
* @expectedException RangeException
54-
*/
5554
public function testCapacityMustBeGreaterThanFlow()
5655
{
5756
$this->edge->setFlow(100);
57+
58+
$this->setExpectedException('RangeException');
5859
$this->edge->setCapacity(20);
5960
}
6061

61-
/**
62-
* @expectedException InvalidArgumentException
63-
*/
6462
public function testWeightMustBeNumeric()
6563
{
64+
$this->setExpectedException('InvalidArgumentException');
6665
$this->edge->setWeight("10");
6766
}
6867

69-
/**
70-
* @expectedException InvalidArgumentException
71-
*/
7268
public function testCapacityMustBeNumeric()
7369
{
70+
$this->setExpectedException('InvalidArgumentException');
7471
$this->edge->setCapacity("10");
7572
}
7673

77-
/**
78-
* @expectedException InvalidArgumentException
79-
*/
8074
public function testCapacityMustBePositive()
8175
{
76+
$this->setExpectedException('InvalidArgumentException');
8277
$this->edge->setCapacity(-10);
8378
}
8479

85-
/**
86-
* @expectedException InvalidArgumentException
87-
*/
8880
public function testFlowMustBeNumeric()
8981
{
82+
$this->setExpectedException('InvalidArgumentException');
9083
$this->edge->setFlow("10");
9184
}
9285

93-
/**
94-
* @expectedException InvalidArgumentException
95-
*/
9686
public function testFlowMustBePositive()
9787
{
88+
$this->setExpectedException('InvalidArgumentException');
9889
$this->edge->setFlow(-10);
9990
}
10091
}

tests/Edge/EdgeBaseTest.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ abstract protected function createEdge();
2525
*/
2626
abstract protected function createEdgeLoop();
2727

28-
public function setUp()
28+
/**
29+
* @before
30+
*/
31+
public function setUpGraph()
2932
{
3033
$this->graph = new Graph();
3134
$this->v1 = $this->graph->createVertex(1);
@@ -53,21 +56,19 @@ public function testEdgeStartVertex()
5356
$this->assertFalse($this->edge->hasVertexTarget($v3));
5457
}
5558

56-
/**
57-
* @expectedException InvalidArgumentException
58-
*/
5959
public function testEdgeFromInvalid()
6060
{
6161
$v3 = $this->graph->createVertex(3);
62+
63+
$this->setExpectedException('InvalidArgumentException');
6264
$this->edge->getVertexFromTo($v3);
6365
}
6466

65-
/**
66-
* @expectedException InvalidArgumentException
67-
*/
6867
public function testEdgeToInvalid()
6968
{
7069
$v3 = $this->graph->createVertex(3);
70+
71+
$this->setExpectedException('InvalidArgumentException');
7172
$this->edge->getVertexToFrom($v3);
7273
}
7374

tests/Exception/NegativeCycleExceptionTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ public function testConstructor()
1818
$this->assertEquals('test', $exception->getMessage());
1919
$this->assertEquals($cycle, $exception->getCycle());
2020
}
21+
22+
public function testConstructorThrowsWhenNoCycleIsGiven()
23+
{
24+
$this->setExpectedException('InvalidArgumentException');
25+
new NegativeCycleException('test');
26+
}
2127
}

0 commit comments

Comments
 (0)