From f7afd29202b36791463eddcb6416f8988657c22a Mon Sep 17 00:00:00 2001 From: asrar Date: Sat, 27 Jan 2024 21:52:58 +0100 Subject: [PATCH 1/4] deps: Upgrade pkgs + Upgrade phpunit and fix tests + Fix passing null to strpos triggering warning on new php + Raise doctrine/cache to v1.4.1 since void cache was not in 1.4 --- .gitignore | 3 ++- composer.json | 7 ++++--- phpunit.xml.dist | 18 ++++++++---------- src/MultiDijkstra.php | 2 +- src/SchemaAnalyzer.php | 2 +- tests/MultiDijkstraTest.php | 16 ++++++---------- tests/SchemaAnalyzerTest.php | 28 ++++++++++++---------------- 7 files changed, 34 insertions(+), 42 deletions(-) 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/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..b2d670e 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,12 @@ 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, "Could not find table 'rights'. Did you mean 'right'?"); $junctionTables = $schemaAnalyzer->getShortestPath('role', 'rights'); } } From a239c9dc1208971420db3ebd6496e894ada9a44c Mon Sep 17 00:00:00 2001 From: asrar Date: Sat, 27 Jan 2024 21:53:19 +0100 Subject: [PATCH 2/4] ci: Add github ci + Remove travis --- .github/workflows/ci.yml | 57 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 20 -------------- 2 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..53e9618 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +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" + exclude: + # Exclude lowest deps version as they don't support newer php versions + - dependencies: "lowest" + php-version: "8.3" + - dependencies: "lowest" + php-version: "8.2" + - dependencies: "lowest" + php-version: "8.1" + - dependencies: "lowest" + php-version: "8.0" + + 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 + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v 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 From 40ed21956fb7e15f872a0ef86ac2280b4757fbd0 Mon Sep 17 00:00:00 2001 From: asrar Date: Sun, 28 Jan 2024 22:01:48 +0100 Subject: [PATCH 3/4] ci: Check for more versions --- .github/workflows/ci.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53e9618..198939c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,16 +21,6 @@ jobs: dependencies: - "lowest" - "highest" - exclude: - # Exclude lowest deps version as they don't support newer php versions - - dependencies: "lowest" - php-version: "8.3" - - dependencies: "lowest" - php-version: "8.2" - - dependencies: "lowest" - php-version: "8.1" - - dependencies: "lowest" - php-version: "8.0" steps: - name: "Checkout" @@ -51,6 +41,9 @@ jobs: 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: | From 30809c7d3edeb812e4f270eb1363123eacf52356 Mon Sep 17 00:00:00 2001 From: asrar Date: Thu, 1 Feb 2024 10:24:06 +0100 Subject: [PATCH 4/4] test: Fix assertion Co-authored-by: homersimpsons --- tests/SchemaAnalyzerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/SchemaAnalyzerTest.php b/tests/SchemaAnalyzerTest.php index b2d670e..a1e1ee8 100644 --- a/tests/SchemaAnalyzerTest.php +++ b/tests/SchemaAnalyzerTest.php @@ -554,7 +554,8 @@ public function testWringTableName() $schemaManager = $this->getCompleteSchemaManager(); $schemaAnalyzer = new SchemaAnalyzer($schemaManager); - $this->expectException(SchemaAnalyzerTableNotFoundException::class, "Could not find table 'rights'. Did you mean 'right'?"); + $this->expectException(SchemaAnalyzerTableNotFoundException::class); + $this->expectExceptionMessage("Could not find table 'rights'. Did you mean 'right'?"); $junctionTables = $schemaAnalyzer->getShortestPath('role', 'rights'); } }