Skip to content

Commit ca5ea3f

Browse files
committed
Run tests on PHPUnit 9 and minor clean up
1 parent ee2470d commit ca5ea3f

39 files changed

+178
-121
lines changed

.travis.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
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:
2926
- vendor/bin/phpunit --coverage-text

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
"graphp/graph": "dev-master#fb198e4 as 1.0.0"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
18+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
1919
},
2020
"autoload": {
2121
"psr-4": {"Graphp\\Algorithms\\": "src/"}
22+
},
23+
"autoload-dev": {
24+
"psr-4": { "Graphp\\Tests\\Algorithms\\": "tests/" }
2225
}
2326
}

phpunit.xml.dist

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="tests/bootstrap.php"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
3+
<phpunit bootstrap="vendor/autoload.php"
4+
colors="true"
5+
cacheResult="false">
96
<testsuites>
107
<testsuite name="Algorithm Test Suite">
118
<directory>./tests/</directory>
@@ -16,4 +13,4 @@
1613
<directory>./src/</directory>
1714
</whitelist>
1815
</filter>
19-
</phpunit>
16+
</phpunit>

tests/BipartitTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Bipartit as AlgorithmBipartit;
46
use Graphp\Graph\Graph;
57

@@ -73,22 +75,22 @@ public function testGraphTriangleCycleIsNotBipartit()
7375
/**
7476
*
7577
* @param AlgorithmBipartit $alg
76-
* @expectedException UnexpectedValueException
7778
* @depends testGraphTriangleCycleIsNotBipartit
7879
*/
7980
public function testGraphTriangleCycleColorsInvalid(AlgorithmBipartit $alg)
8081
{
82+
$this->setExpectedException('UnexpectedValueException');
8183
$alg->getColors();
8284
}
8385

8486
/**
8587
*
8688
* @param AlgorithmBipartit $alg
87-
* @expectedException UnexpectedValueException
8889
* @depends testGraphTriangleCycleIsNotBipartit
8990
*/
9091
public function testGraphTriangleCycleColorVerticesInvalid(AlgorithmBipartit $alg)
9192
{
93+
$this->setExpectedException('UnexpectedValueException');
9294
$alg->getColorVertices();
9395
}
9496
}

tests/CompleteTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Complete as AlgorithmComplete;
46
use Graphp\Graph\Graph;
57

tests/ConnectedComponentsTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\ConnectedComponents as AlgorithmConnected;
46
use Graphp\Graph\Graph;
57

@@ -81,9 +83,6 @@ public function testComponents()
8183
$this->assertEquals($ge, $alg->createGraphComponentVertex($v5));
8284
}
8385

84-
/**
85-
* @expectedException InvalidArgumentException
86-
*/
8786
public function testInvalidVertexPassedToAlgorithm()
8887
{
8988
$graph = new Graph();
@@ -92,6 +91,8 @@ public function testInvalidVertexPassedToAlgorithm()
9291
$v2 = $graph2->createVertex(12);
9392

9493
$alg = new AlgorithmConnected($graph);
94+
95+
$this->setExpectedException('InvalidArgumentException');
9596
$alg->createGraphComponentVertex($v2);
9697
}
9798
}

tests/DegreeTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Degree as AlgorithmDegree;
46
use Graphp\Graph\Exception\UnderflowException;
57
use Graphp\Graph\Exception\UnexpectedValueException;

tests/DetectNegativeCycleTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\DetectNegativeCycle;
46
use Graphp\Graph\Graph;
57

@@ -20,21 +22,21 @@ public function testNullGraph()
2022
*
2123
* @param DetectNegativeCycle $alg
2224
* @depends testNullGraph
23-
* @expectedException UnderflowException
2425
*/
2526
public function testNullGraphHasNoCycle(DetectNegativeCycle $alg)
2627
{
28+
$this->setExpectedException('UnderflowException');
2729
$alg->getCycleNegative();
2830
}
2931

3032
/**
3133
*
3234
* @param DetectNegativeCycle $alg
3335
* @depends testNullGraph
34-
* @expectedException UnderflowException
3536
*/
3637
public function testNullGraphHasNoCycleGraph(DetectNegativeCycle $alg)
3738
{
39+
$this->setExpectedException('UnderflowException');
3840
$alg->createGraph();
3941
}
4042

tests/DirectedTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Directed as AlgorithmDirected;
46
use Graphp\Graph\Graph;
57

tests/EulerianTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Eulerian as AlgorithmEulerian;
46
use Graphp\Graph\Graph;
57

tests/FlowTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Flow as AlgorithmFlow;
46
use Graphp\Graph\Graph;
57

@@ -24,7 +26,6 @@ public function testEdgeWithZeroFlowIsConsideredFlow()
2426
$graph = new Graph();
2527
$graph->createEdgeDirected($graph->createVertex(1), $graph->createVertex(2))->setFlow(0);
2628

27-
2829
$alg = new AlgorithmFlow($graph);
2930

3031
$this->assertTrue($alg->hasFlow());
@@ -81,18 +82,15 @@ public function testGraphBalance()
8182
$this->assertFalse($alg->isBalancedFlow());
8283
}
8384

84-
/**
85-
* @expectedException UnexpectedValueException
86-
*/
8785
public function testVertexWithUndirectedEdgeHasInvalidFlow()
8886
{
8987
// 1 -- 2
9088
$graph = new Graph();
9189
$graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2))->setFlow(10);
9290

93-
9491
$alg = new AlgorithmFlow($graph);
9592

93+
$this->setExpectedException('UnexpectedValueException');
9694
$alg->getFlowVertex($graph->getVertex(1));
9795
}
9896
}

tests/GroupsTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Groups as AlgorithmGroups;
46
use Graphp\Graph\Graph;
57

tests/LoopTest.php

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

3+
namespace Graphp\Tests\Algorithms;
4+
35
use Graphp\Algorithms\Loop as AlgorithmLoop;
46
use Graphp\Graph\Graph;
57

tests/MaxFlow/EdmondsKarpTest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3+
namespace Graphp\Tests\Algorithms\MaxFlow;
4+
35
use Graphp\Algorithms\MaxFlow\EdmondsKarp as AlgorithmMaxFlowEdmondsKarp;
46
use Graphp\Graph\Graph;
5-
use PHPUnit\Framework\TestCase;
7+
use Graphp\Tests\Algorithms\TestCase;
68

79
class EdmondsKarpTest extends TestCase
810
{
@@ -106,9 +108,6 @@ public function testEdgesMultiplePathsTree()
106108
// $this->assertEquals(10, $alg->getFlowMax());
107109
// }
108110

109-
/**
110-
* @expectedException UnexpectedValueException
111-
*/
112111
public function testEdgesUndirected()
113112
{
114113
// 0 -[0/7]- 1
@@ -121,6 +120,7 @@ public function testEdgesUndirected()
121120
// 0 -[7/7]- 1
122121
$alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1);
123122

123+
$this->setExpectedException('UnexpectedValueException');
124124
$this->assertEquals(7, $alg->getFlowMax());
125125
}
126126

@@ -136,10 +136,6 @@ public function testEdgesUndirected()
136136
// $this->assertEquals(0.735802, $alg->getFlowMax());
137137
// }
138138

139-
140-
/**
141-
* @expectedException InvalidArgumentException
142-
*/
143139
public function testInvalidFlowToOtherGraph()
144140
{
145141
$graph1 = new Graph();
@@ -148,17 +144,16 @@ public function testInvalidFlowToOtherGraph()
148144
$graph2 = new Graph();
149145
$vg2 = $graph2->createVertex(2);
150146

147+
$this->setExpectedException('InvalidArgumentException');
151148
new AlgorithmMaxFlowEdmondsKarp($vg1, $vg2);
152149
}
153150

154-
/**
155-
* @expectedException InvalidArgumentException
156-
*/
157151
public function testInvalidFlowToSelf()
158152
{
159153
$graph = new Graph();
160154
$v1 = $graph->createVertex(1);
161155

156+
$this->setExpectedException('InvalidArgumentException');
162157
new AlgorithmMaxFlowEdmondsKarp($v1, $v1);
163158
}
164159

tests/MaximumMatching/FlowTest.php

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

3+
namespace Graphp\Tests\Algorithms\MaximumMatching;
4+
35
use Graphp\Algorithms\MaximumMatching\Flow;
46
use Graphp\Graph\Graph;
5-
use PHPUnit\Framework\TestCase;
7+
use Graphp\Tests\Algorithms\TestCase;
68

79
class FlowTest extends TestCase
810
{
@@ -37,27 +39,29 @@ public function testSingleEdge()
3739

3840
/**
3941
* expect exception for directed edges
40-
* @expectedException UnexpectedValueException
4142
*/
4243
public function testInvalidDirected()
4344
{
4445
$graph = new Graph();
4546
$graph->createEdgeDirected($graph->createVertex(0)->setGroup(0), $graph->createVertex(1)->setGroup(1));
4647

4748
$alg = new Flow($graph);
49+
50+
$this->setExpectedException('UnexpectedValueException');
4851
$alg->getNumberOfMatches();
4952
}
5053

5154
/**
5255
* expect exception for non-bipartit graphs
53-
* @expectedException UnexpectedValueException
5456
*/
5557
public function testInvalidBipartit()
5658
{
5759
$graph = new Graph();
5860
$graph->createEdgeUndirected($graph->createVertex(0)->setGroup(1), $graph->createVertex(1)->setGroup(1));
5961

6062
$alg = new Flow($graph);
63+
64+
$this->setExpectedException('UnexpectedValueException');
6165
$alg->getNumberOfMatches();
6266
}
6367
}

0 commit comments

Comments
 (0)