Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
/vendor/
/build/
/build/
.phpunit.result.cache
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
18 changes: 8 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</include>
<report>
<html outputDirectory="build/coverage" />
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion src/MultiDijkstra.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
16 changes: 6 additions & 10 deletions tests/MultiDijkstraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -99,6 +94,7 @@ public function testDijkstraNegativeWeight()

$a->createEdge($b)->setWeight(-12);

$this->expectException(UnexpectedValueException::class);
MultiDijkstra::findShortestPaths($a, $b);
}

Expand Down
29 changes: 13 additions & 16 deletions tests/SchemaAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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');
}
}