Skip to content
Closed
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
42 changes: 42 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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:
matrix:
php: [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
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -25,7 +25,7 @@
},

"require-dev": {
"phpunit/phpunit": "7.*"
"phpunit/phpunit": "7.*|8.*|9.*"
},

"minimum-stability": "dev",
Expand All @@ -41,5 +41,10 @@
"Kalnoy\\Nestedset\\NestedSetServiceProvider"
]
}
},
"scripts": {
"test": [
"@php ./vendor/bin/phpunit"
]
}
}
43 changes: 18 additions & 25 deletions tests/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class NodeTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$schema = Capsule::schema();

Expand All @@ -23,7 +23,7 @@ public static function setUpBeforeClass()
Capsule::enableQueryLog();
}

public function setUp()
public function setUp(): void
{
$data = include __DIR__.'/data/categories.php';

Expand All @@ -36,7 +36,7 @@ public function setUp()
date_default_timezone_set('America/Denver');
}

public function tearDown()
public function tearDown(): void
{
Capsule::table('categories')->truncate();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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'));

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

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

Expand Down Expand Up @@ -1004,4 +997,4 @@ public function testReplication()
function all($items)
{
return is_array($items) ? $items : $items->all();
}
}
23 changes: 10 additions & 13 deletions tests/ScopedNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class ScopedNodeTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$schema = Capsule::schema();

Expand All @@ -23,7 +23,7 @@ public static function setUpBeforeClass()
Capsule::enableQueryLog();
}

public function setUp()
public function setUp(): void
{
$data = include __DIR__.'/data/menu_items.php';

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

Expand Down Expand Up @@ -201,25 +200,23 @@ 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);

$a->insertAfterNode($b);
}
}
}