Skip to content

Commit bcfbcce

Browse files
authored
Merge pull request lazychaser#546 from area17/v6
Laravel 9 support
2 parents f535123 + de97a56 commit bcfbcce

File tree

6 files changed

+80
-56
lines changed

6 files changed

+80
-56
lines changed

.github/workflows/run-tests.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- "*"
10+
schedule:
11+
- cron: '0 0 * * *'
12+
13+
jobs:
14+
php-tests:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 15
17+
env:
18+
COMPOSER_NO_INTERACTION: 1
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
php: [8.1, 8.0, 7.4, 7.3, 7.2]
24+
25+
name: P${{ matrix.php }}
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v2
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php }}
35+
coverage: none
36+
tools: composer:v2
37+
38+
- name: Install dependencies
39+
run: |
40+
composer install -o --quiet
41+
42+
- name: Execute Unit Tests
43+
run: composer test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
composer.phar
44
composer.lock
55
.DS_Store
6+
.phpunit.result.cache

.travis.yml

-15
This file was deleted.

composer.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
],
1313

1414
"require": {
15-
"php": ">=7.1.3",
16-
"illuminate/support": "^7.0|^8.0",
17-
"illuminate/database": "^7.0|^8.0",
18-
"illuminate/events": "^7.0|^8.0"
15+
"php": "^7.2.5|^8.0",
16+
"illuminate/support": "^7.0|^8.0|^9.0",
17+
"illuminate/database": "^7.0|^8.0|^9.0",
18+
"illuminate/events": "^7.0|^8.0|^9.0"
1919
},
2020

2121
"autoload": {
@@ -25,7 +25,7 @@
2525
},
2626

2727
"require-dev": {
28-
"phpunit/phpunit": "7.*"
28+
"phpunit/phpunit": "7.*|8.*|9.*"
2929
},
3030

3131
"minimum-stability": "dev",
@@ -41,5 +41,10 @@
4141
"Kalnoy\\Nestedset\\NestedSetServiceProvider"
4242
]
4343
}
44+
},
45+
"scripts": {
46+
"test": [
47+
"@php ./vendor/bin/phpunit"
48+
]
4449
}
4550
}

tests/NodeTest.php

+17-24
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class NodeTest extends PHPUnit\Framework\TestCase
77
{
8-
public static function setUpBeforeClass()
8+
public static function setUpBeforeClass(): void
99
{
1010
$schema = Capsule::schema();
1111

@@ -23,7 +23,7 @@ public static function setUpBeforeClass()
2323
Capsule::enableQueryLog();
2424
}
2525

26-
public function setUp()
26+
public function setUp(): void
2727
{
2828
$data = include __DIR__.'/data/categories.php';
2929

@@ -36,7 +36,7 @@ public function setUp()
3636
date_default_timezone_set('America/Denver');
3737
}
3838

39-
public function tearDown()
39+
public function tearDown(): void
4040
{
4141
Capsule::table('categories')->truncate();
4242
}
@@ -221,32 +221,29 @@ public function testCategoryMovesUp()
221221
$this->assertNodeReceivesValidValues($node);
222222
}
223223

224-
/**
225-
* @expectedException Exception
226-
*/
227224
public function testFailsToInsertIntoChild()
228225
{
226+
$this->expectException(Exception::class);
227+
229228
$node = $this->findCategory('notebooks');
230229
$target = $node->children()->first();
231230

232231
$node->afterNode($target)->save();
233232
}
234233

235-
/**
236-
* @expectedException Exception
237-
*/
238234
public function testFailsToAppendIntoItself()
239235
{
236+
$this->expectException(Exception::class);
237+
240238
$node = $this->findCategory('notebooks');
241239

242240
$node->appendToNode($node)->save();
243241
}
244242

245-
/**
246-
* @expectedException Exception
247-
*/
248243
public function testFailsToPrependIntoItself()
249244
{
245+
$this->expectException(Exception::class);
246+
250247
$node = $this->findCategory('notebooks');
251248

252249
$node->prependTo($node)->save();
@@ -338,11 +335,10 @@ public function testParentIdAttributeAccessorAppendsNode()
338335
$this->assertTrue($node->isRoot());
339336
}
340337

341-
/**
342-
* @expectedException Exception
343-
*/
344338
public function testFailsToSaveNodeUntilNotInserted()
345339
{
340+
$this->expectException(Exception::class);
341+
346342
$node = new Category;
347343
$node->save();
348344
}
@@ -405,11 +401,10 @@ public function testSoftDeletedNodeisDeletedWhenParentIsDeleted()
405401
$this->assertNull($this->findCategory('sony'));
406402
}
407403

408-
/**
409-
* @expectedException Exception
410-
*/
411404
public function testFailsToSaveNodeUntilParentIsSaved()
412405
{
406+
$this->expectException(Exception::class);
407+
413408
$node = new Category(array('title' => 'Node'));
414409
$parent = new Category(array('title' => 'Parent'));
415410

@@ -641,11 +636,10 @@ public function testDescendantsOfNonExistingNode()
641636
$this->assertTrue($node->getDescendants()->isEmpty());
642637
}
643638

644-
/**
645-
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
646-
*/
647639
public function testWhereDescendantsOf()
648640
{
641+
$this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class);
642+
649643
Category::whereDescendantOf(124)->get();
650644
}
651645

@@ -852,11 +846,10 @@ public function testRebuildTreeWithDeletion()
852846
$this->assertTrue($nodes->count() > 1);
853847
}
854848

855-
/**
856-
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
857-
*/
858849
public function testRebuildFailsWithInvalidPK()
859850
{
851+
$this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class);
852+
860853
Category::rebuildTree([ [ 'id' => 24 ] ]);
861854
}
862855

tests/ScopedNodeTest.php

+9-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class ScopedNodeTest extends PHPUnit\Framework\TestCase
77
{
8-
public static function setUpBeforeClass()
8+
public static function setUpBeforeClass(): void
99
{
1010
$schema = Capsule::schema();
1111

@@ -23,7 +23,7 @@ public static function setUpBeforeClass()
2323
Capsule::enableQueryLog();
2424
}
2525

26-
public function setUp()
26+
public function setUp(): void
2727
{
2828
$data = include __DIR__.'/data/menu_items.php';
2929

@@ -36,7 +36,7 @@ public function setUp()
3636
date_default_timezone_set('America/Denver');
3737
}
3838

39-
public function tearDown()
39+
public function tearDown(): void
4040
{
4141
Capsule::table('menu_items')->truncate();
4242
}
@@ -159,11 +159,10 @@ public function testInsertion()
159159
$this->assertOtherScopeNotAffected();
160160
}
161161

162-
/**
163-
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
164-
*/
165162
public function testInsertionToParentFromOtherScope()
166163
{
164+
$this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class);
165+
167166
$node = MenuItem::create([ 'menu_id' => 2, 'parent_id' => 5 ]);
168167
}
169168

@@ -201,22 +200,20 @@ protected function assertOtherScopeNotAffected()
201200
MenuItem::scoped([ 'menu_id' => 2 ])->rebuildTree($data);
202201
}*/
203202

204-
/**
205-
* @expectedException LogicException
206-
*/
207203
public function testAppendingToAnotherScopeFails()
208204
{
205+
$this->expectException(LogicException::class);
206+
209207
$a = MenuItem::find(1);
210208
$b = MenuItem::find(3);
211209

212210
$a->appendToNode($b)->save();
213211
}
214212

215-
/**
216-
* @expectedException LogicException
217-
*/
218213
public function testInsertingBeforeAnotherScopeFails()
219214
{
215+
$this->expectException(LogicException::class);
216+
220217
$a = MenuItem::find(1);
221218
$b = MenuItem::find(3);
222219

0 commit comments

Comments
 (0)