diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..0a3b256
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,6 @@
+/.gitattributes export-ignore
+/.gitignore export-ignore
+/.travis.yml export-ignore
+/phpunit.xml export-ignore
+/phpunit-legacy.xml export-ignore
+/tests export-ignore
diff --git a/.travis.yml b/.travis.yml
index 30be35b..8d87e20 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,29 +1,27 @@
language: php
-php:
-# - 5.3 # requires old distro, see below
- - 5.4
- - 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:
+jobs:
include:
- php: 5.3
dist: precise
+ - php: 5.4
+ - php: 5.5
+ - php: 5.6
+ - php: 7.0
+ - php: 7.1
+ - php: 7.2
+ - php: 7.3
+ - php: 7.4
+ - php: hhvm-3.18
allow_failures:
- - php: hhvm
-
-sudo: false
+ - php: hhvm-3.18
install:
- - composer install --no-interaction
+ - composer install
script:
- - vendor/bin/phpunit --coverage-text
+ - if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
+ - if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit-legacy.xml; fi
diff --git a/composer.json b/composer.json
index 63f7db8..d9c6690 100644
--- a/composer.json
+++ b/composer.json
@@ -15,9 +15,12 @@
"graphp/graph": "dev-master#fb198e4 as 1.0.0"
},
"require-dev": {
- "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
+ "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"autoload": {
"psr-4": {"Graphp\\Algorithms\\": "src/"}
+ },
+ "autoload-dev": {
+ "psr-4": { "Graphp\\Tests\\Algorithms\\": "tests/" }
}
}
diff --git a/phpunit-legacy.xml b/phpunit-legacy.xml
new file mode 100644
index 0000000..91a3fef
--- /dev/null
+++ b/phpunit-legacy.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ ./tests/
+
+
+
+
+ ./src/
+
+
+
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..19452d4
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ ./tests/
+
+
+
+
+ ./src/
+
+
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
deleted file mode 100644
index 8748863..0000000
--- a/phpunit.xml.dist
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
- ./tests/
-
-
-
-
- ./src/
-
-
-
\ No newline at end of file
diff --git a/tests/BipartitTest.php b/tests/BipartitTest.php
index 4534b0c..f8df8d4 100644
--- a/tests/BipartitTest.php
+++ b/tests/BipartitTest.php
@@ -1,5 +1,7 @@
setExpectedException('UnexpectedValueException');
$alg->getColors();
}
/**
*
* @param AlgorithmBipartit $alg
- * @expectedException UnexpectedValueException
* @depends testGraphTriangleCycleIsNotBipartit
*/
public function testGraphTriangleCycleColorVerticesInvalid(AlgorithmBipartit $alg)
{
+ $this->setExpectedException('UnexpectedValueException');
$alg->getColorVertices();
}
}
diff --git a/tests/CompleteTest.php b/tests/CompleteTest.php
index 4a2ce01..3282bed 100644
--- a/tests/CompleteTest.php
+++ b/tests/CompleteTest.php
@@ -1,5 +1,7 @@
assertEquals($ge, $alg->createGraphComponentVertex($v5));
}
- /**
- * @expectedException InvalidArgumentException
- */
public function testInvalidVertexPassedToAlgorithm()
{
$graph = new Graph();
@@ -92,6 +91,8 @@ public function testInvalidVertexPassedToAlgorithm()
$v2 = $graph2->createVertex(12);
$alg = new AlgorithmConnected($graph);
+
+ $this->setExpectedException('InvalidArgumentException');
$alg->createGraphComponentVertex($v2);
}
}
diff --git a/tests/DegreeTest.php b/tests/DegreeTest.php
index 095ca5f..bf3c204 100644
--- a/tests/DegreeTest.php
+++ b/tests/DegreeTest.php
@@ -1,5 +1,7 @@
setExpectedException('UnderflowException');
$alg->getCycleNegative();
}
@@ -31,10 +33,10 @@ public function testNullGraphHasNoCycle(DetectNegativeCycle $alg)
*
* @param DetectNegativeCycle $alg
* @depends testNullGraph
- * @expectedException UnderflowException
*/
public function testNullGraphHasNoCycleGraph(DetectNegativeCycle $alg)
{
+ $this->setExpectedException('UnderflowException');
$alg->createGraph();
}
diff --git a/tests/DirectedTest.php b/tests/DirectedTest.php
index 321f026..f3b1b94 100644
--- a/tests/DirectedTest.php
+++ b/tests/DirectedTest.php
@@ -1,5 +1,7 @@
createEdgeDirected($graph->createVertex(1), $graph->createVertex(2))->setFlow(0);
-
$alg = new AlgorithmFlow($graph);
$this->assertTrue($alg->hasFlow());
@@ -81,18 +82,15 @@ public function testGraphBalance()
$this->assertFalse($alg->isBalancedFlow());
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testVertexWithUndirectedEdgeHasInvalidFlow()
{
// 1 -- 2
$graph = new Graph();
$graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2))->setFlow(10);
-
$alg = new AlgorithmFlow($graph);
+ $this->setExpectedException('UnexpectedValueException');
$alg->getFlowVertex($graph->getVertex(1));
}
}
diff --git a/tests/GroupsTest.php b/tests/GroupsTest.php
index 5ee6311..89c0fdf 100644
--- a/tests/GroupsTest.php
+++ b/tests/GroupsTest.php
@@ -1,5 +1,7 @@
assertEquals(10, $alg->getFlowMax());
// }
- /**
- * @expectedException UnexpectedValueException
- */
public function testEdgesUndirected()
{
// 0 -[0/7]- 1
@@ -121,6 +120,7 @@ public function testEdgesUndirected()
// 0 -[7/7]- 1
$alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1);
+ $this->setExpectedException('UnexpectedValueException');
$this->assertEquals(7, $alg->getFlowMax());
}
@@ -136,10 +136,6 @@ public function testEdgesUndirected()
// $this->assertEquals(0.735802, $alg->getFlowMax());
// }
-
- /**
- * @expectedException InvalidArgumentException
- */
public function testInvalidFlowToOtherGraph()
{
$graph1 = new Graph();
@@ -148,17 +144,16 @@ public function testInvalidFlowToOtherGraph()
$graph2 = new Graph();
$vg2 = $graph2->createVertex(2);
+ $this->setExpectedException('InvalidArgumentException');
new AlgorithmMaxFlowEdmondsKarp($vg1, $vg2);
}
- /**
- * @expectedException InvalidArgumentException
- */
public function testInvalidFlowToSelf()
{
$graph = new Graph();
$v1 = $graph->createVertex(1);
+ $this->setExpectedException('InvalidArgumentException');
new AlgorithmMaxFlowEdmondsKarp($v1, $v1);
}
diff --git a/tests/MaximumMatching/FlowTest.php b/tests/MaximumMatching/FlowTest.php
index 652fa53..d457ef0 100644
--- a/tests/MaximumMatching/FlowTest.php
+++ b/tests/MaximumMatching/FlowTest.php
@@ -1,8 +1,10 @@
createEdgeDirected($graph->createVertex(0)->setGroup(0), $graph->createVertex(1)->setGroup(1));
$alg = new Flow($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getNumberOfMatches();
}
/**
* expect exception for non-bipartit graphs
- * @expectedException UnexpectedValueException
*/
public function testInvalidBipartit()
{
@@ -58,6 +60,8 @@ public function testInvalidBipartit()
$graph->createEdgeUndirected($graph->createVertex(0)->setGroup(1), $graph->createVertex(1)->setGroup(1));
$alg = new Flow($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getNumberOfMatches();
}
}
diff --git a/tests/MinimumCostFlow/BaseMcfTest.php b/tests/MinimumCostFlow/BaseMcfTest.php
index aef3aa5..35342c3 100644
--- a/tests/MinimumCostFlow/BaseMcfTest.php
+++ b/tests/MinimumCostFlow/BaseMcfTest.php
@@ -1,7 +1,10 @@
assertEquals(14, $alg->getWeightFlow()); // 4*1 + 2*2 + 2*1 + 2*2
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testEdgeCapacityInsufficientFails()
{
// 1(+2) -[0/1]-> 2(-2)
@@ -124,12 +124,11 @@ public function testEdgeCapacityInsufficientFails()
$graph->createEdgeDirected($v1, $v2)->setCapacity(1);
$alg = $this->createAlgorithm($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getWeightFlow();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testEdgeCapacityUnsetFails()
{
// 1(+2) -> 2(-2)
@@ -139,12 +138,11 @@ public function testEdgeCapacityUnsetFails()
$graph->createEdgeDirected($v1, $v2);
$alg = $this->createAlgorithm($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getWeightFlow();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testIsolatedVerticesFail()
{
// 1(+2), 2(-2)
@@ -153,12 +151,11 @@ public function testIsolatedVerticesFail()
$graph->createVertex(2)->setBalance(-2);
$alg = $this->createAlgorithm($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getWeightFlow();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testUnbalancedFails()
{
// 1(+2) -> 2(-3)
@@ -168,12 +165,11 @@ public function testUnbalancedFails()
$graph->createEdgeDirected($v1, $v2)->setCapacity(3);
$alg = $this->createAlgorithm($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getWeightFlow();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testUndirectedFails()
{
// 1(+2) -- 2(-2)
@@ -183,12 +179,11 @@ public function testUndirectedFails()
$graph->createEdgeUndirected($v1, $v2)->setCapacity(2);
$alg = $this->createAlgorithm($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getWeightFlow();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testUndirectedNegativeCycleFails()
{
// 1(+2) -[0/2/-1]- 2(-2)
@@ -198,6 +193,8 @@ public function testUndirectedNegativeCycleFails()
$graph->createEdgeUndirected($v1, $v2)->setCapacity(2)->setWeight(-1);
$alg = $this->createAlgorithm($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getWeightFlow();
}
}
diff --git a/tests/MinimumCostFlow/CycleCancellingTest.php b/tests/MinimumCostFlow/CycleCancellingTest.php
index 841fc1a..62f45fc 100644
--- a/tests/MinimumCostFlow/CycleCancellingTest.php
+++ b/tests/MinimumCostFlow/CycleCancellingTest.php
@@ -1,5 +1,7 @@
assertGraphEquals($graph, $alg->createGraph());
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testMultipleComponentsFail()
{
// 1 --[1]-- 2, 3 --[1]-- 4
@@ -146,12 +146,11 @@ public function testMultipleComponentsFail()
$graph->createEdgeUndirected($v3, $v4)->setWeight(1);
$alg = $this->createAlg($v1);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getEdges();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testMultipleIsolatedVerticesFormMultipleComponentsFail()
{
// 1, 2
@@ -160,6 +159,8 @@ public function testMultipleIsolatedVerticesFormMultipleComponentsFail()
$graph->createVertex(2);
$alg = $this->createAlg($v1);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getEdges();
}
diff --git a/tests/MinimumSpanningTree/KruskalTest.php b/tests/MinimumSpanningTree/KruskalTest.php
index d145b78..9a4d53a 100644
--- a/tests/MinimumSpanningTree/KruskalTest.php
+++ b/tests/MinimumSpanningTree/KruskalTest.php
@@ -1,5 +1,7 @@
getGraph());
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testNullGraphIsNotConsideredToBeConnected()
{
$graph = new Graph();
$alg = new Kruskal($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getEdges();
}
}
diff --git a/tests/MinimumSpanningTree/PrimTest.php b/tests/MinimumSpanningTree/PrimTest.php
index f860df7..5969ba0 100644
--- a/tests/MinimumSpanningTree/PrimTest.php
+++ b/tests/MinimumSpanningTree/PrimTest.php
@@ -1,5 +1,7 @@
setCapacity(2);
$alg = new ResidualGraph($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->createGraph();
}
/**
* expect exception for edges with no flow
- * @expectedException UnexpectedValueException
*/
public function testInvalidNoFlow()
{
@@ -186,12 +188,13 @@ public function testInvalidNoFlow()
$graph->createEdgeDirected($graph->createVertex(), $graph->createVertex())->setCapacity(1);
$alg = new ResidualGraph($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->createGraph();
}
/**
* expect exception for edges with no capacity
- * @expectedException UnexpectedValueException
*/
public function testInvalidNoCapacity()
{
@@ -200,6 +203,8 @@ public function testInvalidNoCapacity()
$graph->createEdgeDirected($graph->createVertex(), $graph->createVertex())->setFlow(1);
$alg = new ResidualGraph($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->createGraph();
}
diff --git a/tests/Search/BreadthFirstTest.php b/tests/Search/BreadthFirstTest.php
index 6fba9da..62034c8 100644
--- a/tests/Search/BreadthFirstTest.php
+++ b/tests/Search/BreadthFirstTest.php
@@ -1,7 +1,10 @@
assertEquals(2, \count($walk->getEdges()));
}
- /**
- * @expectedException OutOfBoundsException
- */
public function testIsolatedVertexIsNotReachable()
{
// 1, 2
@@ -96,12 +96,10 @@ public function testIsolatedVertexIsNotReachable()
$this->assertFalse($alg->hasVertex($v2));
+ $this->setExpectedException('OutOfBoundsException');
$alg->getEdgesTo($v2);
}
- /**
- * @expectedException OutOfBoundsException
- */
public function testSeparateGraphsAreNotReachable()
{
// 1
@@ -113,6 +111,7 @@ public function testSeparateGraphsAreNotReachable()
$alg = $this->createAlg($vg1);
+ $this->setExpectedException('OutOfBoundsException');
$alg->getEdgesTo($vg2);
}
diff --git a/tests/ShortestPath/BreadthFirstTest.php b/tests/ShortestPath/BreadthFirstTest.php
index bc0d00a..cf723da 100644
--- a/tests/ShortestPath/BreadthFirstTest.php
+++ b/tests/ShortestPath/BreadthFirstTest.php
@@ -1,5 +1,7 @@
2
@@ -27,6 +26,7 @@ public function testGraphParallelNegative()
$alg = $this->createAlg($v1);
+ $this->setExpectedException('UnexpectedValueException');
$alg->getEdges();
}
}
diff --git a/tests/ShortestPath/MooreBellmanFordTest.php b/tests/ShortestPath/MooreBellmanFordTest.php
index 0fadcce..421e655 100644
--- a/tests/ShortestPath/MooreBellmanFordTest.php
+++ b/tests/ShortestPath/MooreBellmanFordTest.php
@@ -1,5 +1,7 @@
setExpectedException('UnderflowException');
$alg->getCycleNegative();
}
@@ -96,16 +98,8 @@ public function testNegativeComponentHasCycle()
// first component does not have a cycle
$alg = $this->createAlg($v1);
- $this->expectException('UnderflowException');
- $alg->getCycleNegative();
- }
- public function expectException($class)
- {
- if (\method_exists($this, 'setExpectedException')) {
- $this->setExpectedException($class);
- } else {
- parent::expectException($class);
- }
+ $this->setExpectedException('UnderflowException');
+ $alg->getCycleNegative();
}
}
diff --git a/tests/SymmetricTest.php b/tests/SymmetricTest.php
index c1544cb..64ba0b5 100644
--- a/tests/SymmetricTest.php
+++ b/tests/SymmetricTest.php
@@ -1,5 +1,7 @@
expectException($exception);
+ if ($exceptionMessage !== '') {
+ $this->expectExceptionMessage($exceptionMessage);
+ }
+ if ($exceptionCode !== null) {
+ $this->expectExceptionCode($exceptionCode);
+ }
+ } else {
+ // legacy PHPUnit 4 - PHPUnit 5
+ parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
+ }
+ }
}
diff --git a/tests/TopologicalSortTest.php b/tests/TopologicalSortTest.php
index ce5e3c4..bfa0909 100644
--- a/tests/TopologicalSortTest.php
+++ b/tests/TopologicalSortTest.php
@@ -1,5 +1,7 @@
assertSame(array($graph->getVertex(1), $graph->getVertex(2)), $alg->getVertices()->getVector());
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testFailUndirected()
{
$graph = new Graph();
$graph->createEdgeUndirected($graph->createVertex(1), $graph->createVertex(2));
$alg = new TopologicalSort($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getVertices();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testFailLoop()
{
$graph = new Graph();
$graph->createEdgeDirected($graph->createVertex(1), $graph->getVertex(1));
$alg = new TopologicalSort($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getVertices();
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testFailCycle()
{
$graph = new Graph();
@@ -70,6 +67,8 @@ public function testFailCycle()
$graph->createEdgeDirected($graph->getVertex(2), $graph->getVertex(1));
$alg = new TopologicalSort($graph);
+
+ $this->setExpectedException('UnexpectedValueException');
$alg->getVertices();
}
}
diff --git a/tests/TravelingSalesmanProblem/BruteforceTest.php b/tests/TravelingSalesmanProblem/BruteforceTest.php
index bb43e3c..41c10e5 100644
--- a/tests/TravelingSalesmanProblem/BruteforceTest.php
+++ b/tests/TravelingSalesmanProblem/BruteforceTest.php
@@ -1,7 +1,10 @@
setUpperLimitMst();
- $ref = new ReflectionProperty($alg, 'upperLimit');
+ $ref = new \ReflectionProperty($alg, 'upperLimit');
$ref->setAccessible(true);
$this->assertEquals(6, $ref->getValue($alg));
diff --git a/tests/Tree/BaseDirectedTest.php b/tests/Tree/BaseDirectedTest.php
index 4713392..804e5a4 100644
--- a/tests/Tree/BaseDirectedTest.php
+++ b/tests/Tree/BaseDirectedTest.php
@@ -1,8 +1,11 @@
setExpectedException('UnderflowException');
$tree->getVertexRoot();
}
/**
* @param BaseDirected $tree
* @depends testNullGraph
- * @expectedException UnderflowException
*/
public function testEmptyGraphDoesNotHaveDegree(BaseDirected $tree)
{
+ $this->setExpectedException('UnderflowException');
$tree->getDegree();
}
/**
* @param BaseDirected $tree
* @depends testNullGraph
- * @expectedException UnderflowException
*/
public function testEmptyGraphDoesNotHaveHeight(BaseDirected $tree)
{
+ $this->setExpectedException('UnderflowException');
$tree->getHeight();
}
@@ -108,11 +111,12 @@ public function testGraphTree()
*
* @param BaseDirected $tree
* @depends testGraphTree
- * @expectedException UnderflowException
*/
public function testGraphTreeRootDoesNotHaveParent(BaseDirected $tree)
{
$root = $tree->getVertexRoot();
+
+ $this->setExpectedException('UnderflowException');
$tree->getVertexParent($root);
}
@@ -125,15 +129,13 @@ public function testNonTree()
$this->assertFalse($tree->isTree());
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testNonTreeVertexHasMoreThanOneParent()
{
$graph = $this->createGraphNonTree();
$tree = $this->createTreeAlg($graph);
+ $this->setExpectedException('UnexpectedValueException');
$tree->getVertexParent($graph->getVertex('v3'));
}
@@ -157,9 +159,6 @@ public function testGraphWithLoopIsNotTree()
$this->assertFalse($tree->isTree());
}
- /**
- * @expectedException UnexpectedValueException
- */
public function testGraphWithLoopCanNotGetSubgraph()
{
// v1 -> v1
@@ -168,6 +167,7 @@ public function testGraphWithLoopCanNotGetSubgraph()
$tree = $this->createTreeAlg($graph);
+ $this->setExpectedException('UnexpectedValueException');
$tree->getVerticesSubtree($graph->getVertex('v1'));
}
diff --git a/tests/Tree/InTreeTest.php b/tests/Tree/InTreeTest.php
index 3d05496..eec4a13 100644
--- a/tests/Tree/InTreeTest.php
+++ b/tests/Tree/InTreeTest.php
@@ -1,5 +1,7 @@