diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..198939c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: "Continuous Integration" + +on: + pull_request: + push: + branches: + - 2.0 +jobs: + test: + name: "Test" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + - "8.0" + - "8.1" + - "8.2" + - "8.3" + dependencies: + - "lowest" + - "highest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "xdebug" + php-version: "${{ matrix.php-version }}" + ini-values: "zend.assertions=1" + + - uses: "ramsey/composer-install@v2" + with: + dependency-versions: "${{ matrix.dependencies }}" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c phpunit.xml.dist" + + - name: Upload coverage results to Coveralls + # skip php-coversalls for lowest deps + # it fails on lowest depedencies because old versions of guzzle doesn't work well with newer php versions + if: "${{ 'highest' == matrix.dependencies }}" + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v diff --git a/.gitignore b/.gitignore index 7e43412..7f570ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock /vendor/ -/build/ \ No newline at end of file +/build/ +.phpunit.result.cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e2d63bf..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php - -php: - - 5.6 - - 7.0 - - 7.4 - -env: - matrix: - - PREFER_LOWEST="--prefer-lowest" - - PREFER_LOWEST="" - -before_script: - - composer update --prefer-source $PREFER_LOWEST - -script: - - ./vendor/bin/phpunit - -after_script: - - php vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index a8f7075..1299fa8 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,14 @@ } }, "require": { + "php": "^7.4 || ^8.0", "clue/graph": "~0.9.0", "doctrine/dbal": "^3.0", - "doctrine/cache": "^1.4", + "doctrine/cache": "^1.4.1", "graphp/algorithms": "~0.8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.36", - "satooshi/php-coveralls": "^1.0" + "phpunit/phpunit": "^9.6.16", + "php-coveralls/php-coveralls": "^2.7.0" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f62ca6c..397b79d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="tests/bootstrap.php" > @@ -16,14 +15,13 @@ ./tests/ - - + + src - - - - - - - + + + + + + diff --git a/src/MultiDijkstra.php b/src/MultiDijkstra.php index 5e554c4..c7b3e73 100644 --- a/src/MultiDijkstra.php +++ b/src/MultiDijkstra.php @@ -146,7 +146,7 @@ public static function getCheapestPathFromPredecesArray(Vertex $startVertex, Ver if (count($predecessorEdges) > 1) { throw new MultiDijkstraAmbiguityException("There are many possible shortest paths to link vertex '".$startVertex->getId()."' to '".$endVertex->getId()."'"); } - /* @var $edge \Fhaculty\Graph\Edge\Base */ + /** @var $edge \Fhaculty\Graph\Edge\Base */ $edge = $predecessorEdges[0]; $edges[] = $edge; if ($currentVertex === $edge->getVerticesStart()->getVertexFirst()) { diff --git a/src/SchemaAnalyzer.php b/src/SchemaAnalyzer.php index 52a5778..4c50b43 100644 --- a/src/SchemaAnalyzer.php +++ b/src/SchemaAnalyzer.php @@ -169,7 +169,7 @@ public function isJunctionTable(Table $table, $ignoreReferencedTables = false) // Let's check that the primary key is autoincremented $pkColumn = $table->getColumn($pkColumns[0]); - if (!$pkColumn->getAutoincrement() && strpos($pkColumn->getComment(), '@Autoincrement') === false) { + if (!$pkColumn->getAutoincrement() && strpos($pkColumn->getComment() ?? '', '@Autoincrement') === false) { return false; } } diff --git a/tests/MultiDijkstraTest.php b/tests/MultiDijkstraTest.php index 56976cc..ee83660 100644 --- a/tests/MultiDijkstraTest.php +++ b/tests/MultiDijkstraTest.php @@ -5,8 +5,10 @@ use Fhaculty\Graph\Graph; use Fhaculty\Graph\Vertex; use Fhaculty\Graph\Edge; +use Fhaculty\Graph\Exception\UnexpectedValueException; +use PHPUnit\Framework\TestCase; -class MultiDijkstraTest extends \PHPUnit_Framework_TestCase +class MultiDijkstraTest extends TestCase { public function testDijkstra() { @@ -47,9 +49,6 @@ public function testDijkstra() $this->assertTrue($this->hasVertex($edges[2], $h)); } - /** - * @expectedException \Mouf\Database\SchemaAnalyzer\MultiDijkstraAmbiguityException - */ public function testDijkstraAmbiguity() { $graph = new Graph(); @@ -66,12 +65,10 @@ public function testDijkstraAmbiguity() $predecessors = MultiDijkstra::findShortestPaths($a, $d); + $this->expectException(MultiDijkstraAmbiguityException::class); MultiDijkstra::getCheapestPathFromPredecesArray($a, $d, $predecessors); } - /** - * @expectedException \Mouf\Database\SchemaAnalyzer\MultiDijkstraNoPathException - */ public function testDijkstraNoPath() { $graph = new Graph(); @@ -84,12 +81,10 @@ public function testDijkstraNoPath() $a->createEdge($b)->setWeight(12); $a->createEdge($c)->setWeight(42); + $this->expectException(MultiDijkstraNoPathException::class); MultiDijkstra::findShortestPaths($a, $d); } - /** - * @expectedException \Fhaculty\Graph\Exception\UnexpectedValueException - */ public function testDijkstraNegativeWeight() { $graph = new Graph(); @@ -99,6 +94,7 @@ public function testDijkstraNegativeWeight() $a->createEdge($b)->setWeight(-12); + $this->expectException(UnexpectedValueException::class); MultiDijkstra::findShortestPaths($a, $b); } diff --git a/tests/SchemaAnalyzerTest.php b/tests/SchemaAnalyzerTest.php index 3a88ab3..a1e1ee8 100644 --- a/tests/SchemaAnalyzerTest.php +++ b/tests/SchemaAnalyzerTest.php @@ -4,8 +4,9 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\DBAL\Schema\Schema; +use PHPUnit\Framework\TestCase; -class SchemaAnalyzerTest extends \PHPUnit_Framework_TestCase +class SchemaAnalyzerTest extends TestCase { /** * Returns a base schema with a role and a right table. @@ -294,12 +295,10 @@ public function testShortestPathInLine() $this->assertEquals('role', $fks[0]->getForeignTableName()); } - /** - * @expectedException \Mouf\Database\SchemaAnalyzer\SchemaAnalyzerException - */ public function testWrongConstructor() { $schema = $this->getBaseSchema(); + $this->expectException(SchemaAnalyzerException::class); new SchemaAnalyzer(new StubSchemaManager($schema), new ArrayCache()); } @@ -347,8 +346,8 @@ public function testAmbiguityException() try { $schemaAnalyzer->getShortestPath('role', 'right'); } catch (ShortestPathAmbiguityException $e) { - $this->assertContains('role <=(role_right)=> right', $e->getMessage()); - $this->assertContains('role <=(role_right2)=> right', $e->getMessage()); + $this->assertStringContainsString('role <=(role_right)=> right', $e->getMessage()); + $this->assertStringContainsString('role <=(role_right2)=> right', $e->getMessage()); $exceptionTriggered = true; } $this->assertTrue($exceptionTriggered); @@ -357,8 +356,8 @@ public function testAmbiguityException() try { $schemaAnalyzer->getShortestPath('right', 'role'); } catch (ShortestPathAmbiguityException $e) { - $this->assertContains('right <=(role_right)=> role', $e->getMessage()); - $this->assertContains('right <=(role_right2)=> role', $e->getMessage()); + $this->assertStringContainsString('right <=(role_right)=> role', $e->getMessage()); + $this->assertStringContainsString('right <=(role_right2)=> role', $e->getMessage()); $exceptionTriggered = true; } $this->assertTrue($exceptionTriggered); @@ -380,8 +379,8 @@ public function testAmbiguityExceptionWithNoJointure() try { $schemaAnalyzer->getShortestPath('role', 'right'); } catch (ShortestPathAmbiguityException $e) { - $this->assertContains('role <--(role_id)-- right', $e->getMessage()); - $this->assertContains('role <--(role_id2)-- right', $e->getMessage()); + $this->assertStringContainsString('role <--(role_id)-- right', $e->getMessage()); + $this->assertStringContainsString('role <--(role_id2)-- right', $e->getMessage()); $exceptionTriggered = true; } $this->assertTrue($exceptionTriggered); @@ -390,8 +389,8 @@ public function testAmbiguityExceptionWithNoJointure() try { $schemaAnalyzer->getShortestPath('right', 'role'); } catch (ShortestPathAmbiguityException $e) { - $this->assertContains('right --(role_id)--> role', $e->getMessage()); - $this->assertContains('right --(role_id2)--> role', $e->getMessage()); + $this->assertStringContainsString('right --(role_id)--> role', $e->getMessage()); + $this->assertStringContainsString('right --(role_id2)--> role', $e->getMessage()); $exceptionTriggered = true; } $this->assertTrue($exceptionTriggered); @@ -550,15 +549,13 @@ public function testChainedJunctionTables() $this->assertEquals('role_users', $fks[3]->getName()); } - /** - * @expectedException \Mouf\Database\SchemaAnalyzer\SchemaAnalyzerTableNotFoundException - * @expectedExceptionMessage Could not find table 'rights'. Did you mean 'right'? - */ public function testWringTableName() { $schemaManager = $this->getCompleteSchemaManager(); $schemaAnalyzer = new SchemaAnalyzer($schemaManager); + $this->expectException(SchemaAnalyzerTableNotFoundException::class); + $this->expectExceptionMessage("Could not find table 'rights'. Did you mean 'right'?"); $junctionTables = $schemaAnalyzer->getShortestPath('role', 'rights'); } }