diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..438e5dd --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,43 @@ +name: Unit Tests + +on: + push: + branches: + - master + pull_request: + branches: + - "*" + schedule: + - cron: '0 0 * * *' + +jobs: + php-tests: + runs-on: ubuntu-latest + timeout-minutes: 15 + env: + COMPOSER_NO_INTERACTION: 1 + + strategy: + fail-fast: false + matrix: + php: [8.1, 8.0, 7.4, 7.3, 7.2] + + name: P${{ matrix.php }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + tools: composer:v2 + + - name: Install dependencies + run: | + composer install -o --quiet + + - name: Execute Unit Tests + run: composer test diff --git a/.gitignore b/.gitignore index 8879189..6bef520 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.phar composer.lock .DS_Store +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d0ba93c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: php - -php: - - 5.5 - - 5.6 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -before_script: - - curl -s http://getcomposer.org/installer | php - - php composer.phar install --dev - -script: phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index 5c937a9..ff3df84 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,10 @@ ], "require": { - "php": ">=7.1.3", - "illuminate/support": "^7.0|^8.0", - "illuminate/database": "^7.0|^8.0", - "illuminate/events": "^7.0|^8.0" + "php": "^7.2.5|^8.0", + "illuminate/support": "^7.0|^8.0|^9.0", + "illuminate/database": "^7.0|^8.0|^9.0", + "illuminate/events": "^7.0|^8.0|^9.0" }, "autoload": { @@ -25,7 +25,7 @@ }, "require-dev": { - "phpunit/phpunit": "7.*" + "phpunit/phpunit": "7.*|8.*|9.*" }, "minimum-stability": "dev", @@ -41,5 +41,10 @@ "Kalnoy\\Nestedset\\NestedSetServiceProvider" ] } + }, + "scripts": { + "test": [ + "@php ./vendor/bin/phpunit" + ] } } diff --git a/tests/NodeTest.php b/tests/NodeTest.php index 7c2fbae..3b0831a 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -5,7 +5,7 @@ class NodeTest extends PHPUnit\Framework\TestCase { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $schema = Capsule::schema(); @@ -23,7 +23,7 @@ public static function setUpBeforeClass() Capsule::enableQueryLog(); } - public function setUp() + public function setUp(): void { $data = include __DIR__.'/data/categories.php'; @@ -36,7 +36,7 @@ public function setUp() date_default_timezone_set('America/Denver'); } - public function tearDown() + public function tearDown(): void { Capsule::table('categories')->truncate(); } @@ -221,32 +221,29 @@ public function testCategoryMovesUp() $this->assertNodeReceivesValidValues($node); } - /** - * @expectedException Exception - */ public function testFailsToInsertIntoChild() { + $this->expectException(Exception::class); + $node = $this->findCategory('notebooks'); $target = $node->children()->first(); $node->afterNode($target)->save(); } - /** - * @expectedException Exception - */ public function testFailsToAppendIntoItself() { + $this->expectException(Exception::class); + $node = $this->findCategory('notebooks'); $node->appendToNode($node)->save(); } - /** - * @expectedException Exception - */ public function testFailsToPrependIntoItself() { + $this->expectException(Exception::class); + $node = $this->findCategory('notebooks'); $node->prependTo($node)->save(); @@ -338,11 +335,10 @@ public function testParentIdAttributeAccessorAppendsNode() $this->assertTrue($node->isRoot()); } - /** - * @expectedException Exception - */ public function testFailsToSaveNodeUntilNotInserted() { + $this->expectException(Exception::class); + $node = new Category; $node->save(); } @@ -405,11 +401,10 @@ public function testSoftDeletedNodeisDeletedWhenParentIsDeleted() $this->assertNull($this->findCategory('sony')); } - /** - * @expectedException Exception - */ public function testFailsToSaveNodeUntilParentIsSaved() { + $this->expectException(Exception::class); + $node = new Category(array('title' => 'Node')); $parent = new Category(array('title' => 'Parent')); @@ -641,11 +636,10 @@ public function testDescendantsOfNonExistingNode() $this->assertTrue($node->getDescendants()->isEmpty()); } - /** - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException - */ public function testWhereDescendantsOf() { + $this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class); + Category::whereDescendantOf(124)->get(); } @@ -852,11 +846,10 @@ public function testRebuildTreeWithDeletion() $this->assertTrue($nodes->count() > 1); } - /** - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException - */ public function testRebuildFailsWithInvalidPK() { + $this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class); + Category::rebuildTree([ [ 'id' => 24 ] ]); } diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index f1c6921..c0eac24 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -5,7 +5,7 @@ class ScopedNodeTest extends PHPUnit\Framework\TestCase { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $schema = Capsule::schema(); @@ -23,7 +23,7 @@ public static function setUpBeforeClass() Capsule::enableQueryLog(); } - public function setUp() + public function setUp(): void { $data = include __DIR__.'/data/menu_items.php'; @@ -36,7 +36,7 @@ public function setUp() date_default_timezone_set('America/Denver'); } - public function tearDown() + public function tearDown(): void { Capsule::table('menu_items')->truncate(); } @@ -159,11 +159,10 @@ public function testInsertion() $this->assertOtherScopeNotAffected(); } - /** - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException - */ public function testInsertionToParentFromOtherScope() { + $this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class); + $node = MenuItem::create([ 'menu_id' => 2, 'parent_id' => 5 ]); } @@ -201,22 +200,20 @@ protected function assertOtherScopeNotAffected() MenuItem::scoped([ 'menu_id' => 2 ])->rebuildTree($data); }*/ - /** - * @expectedException LogicException - */ public function testAppendingToAnotherScopeFails() { + $this->expectException(LogicException::class); + $a = MenuItem::find(1); $b = MenuItem::find(3); $a->appendToNode($b)->save(); } - /** - * @expectedException LogicException - */ public function testInsertingBeforeAnotherScopeFails() { + $this->expectException(LogicException::class); + $a = MenuItem::find(1); $b = MenuItem::find(3);