Skip to content

Commit 086807a

Browse files
authored
Merge pull request #370 from Ciaro/v5
V5 - fix support for Laravel 5.7 and 5.8 (fixes #339, #351, #329, #334, #271, #365)
2 parents 351fab2 + 10732f1 commit 086807a

File tree

9 files changed

+30
-20
lines changed

9 files changed

+30
-20
lines changed

README.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
This is a Laravel 4-5 package for working with trees in relational databases.
88

9-
* **Laravel 5.5, 5.6, 5.7, 5.8** is supported since v4.3
9+
* **Laravel 5.7, 5.8** is supported since v5
10+
* **Laravel 5.5, 5.6** is supported since v4.3
1011
* **Laravel 5.2, 5.3, 5.4** is supported since v4
1112
* **Laravel 5.1** is supported in v3
1213
* **Laravel 4** is supported in v2

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kalnoy/nestedset",
3-
"description": "Nested Set Model for Laravel 4-5",
3+
"description": "Nested Set Model for Laravel 5.7 and up",
44
"keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"],
55
"license": "MIT",
66

@@ -12,10 +12,10 @@
1212
],
1313

1414
"require": {
15-
"php": ">=5.5.9",
16-
"illuminate/support": "5.2 - 5.8",
17-
"illuminate/database": "5.2 - 5.8",
18-
"illuminate/events": "5.2 - 5.8"
15+
"php": ">=7.1.3",
16+
"illuminate/support": "~5.7.0|~5.8.0",
17+
"illuminate/database": "~5.7.0|~5.8.0",
18+
"illuminate/events": "~5.7.0|~5.8.0"
1919
},
2020

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

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

3131
"minimum-stability": "dev",
3232
"prefer-stable": true,
3333

3434
"extra": {
3535
"branch-alias": {
36-
"dev-master": "v4.2.x-dev"
36+
"dev-master": "v5.0.x-dev"
3737
},
3838

3939
"laravel": {

phpunit.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
99
processIsolation="false"
10-
stopOnFailure="true"
11-
syntaxCheck="false"
1210
>
1311
<testsuites>
1412
<testsuite name="Package Test Suite">

src/AncestorsRelation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public function addConstraints()
1515
{
1616
if ( ! static::$constraints) return;
1717

18-
$this->query->whereAncestorOf($this->parent)->defaultOrder();
18+
$this->query->whereAncestorOf($this->parent)
19+
->applyNestedSetScope();
1920
}
2021

2122
/**

src/BaseRelation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ public function getResults()
154154
*/
155155
public function addEagerConstraints(array $models)
156156
{
157+
// The first model in the array is always the parent, so add the scope constraints based on that model.
158+
// @link https://github.com/laravel/framework/pull/25240
159+
// @link https://github.com/lazychaser/laravel-nestedset/issues/351
160+
optional($models[0])->applyNestedSetScope($this->query);
161+
157162
$this->query->whereNested(function (Builder $inner) use ($models) {
158163
// We will use this query in order to apply constraints to the
159164
// base query builder

src/DescendantsRelation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public function addConstraints()
1717
{
1818
if ( ! static::$constraints) return;
1919

20-
$this->query->whereDescendantOf($this->parent);
20+
$this->query->whereDescendantOf($this->parent)
21+
->applyNestedSetScope();
2122
}
2223

2324
/**

src/NodeTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function children()
248248
*/
249249
public function descendants()
250250
{
251-
return new DescendantsRelation($this->newScopedQuery(), $this);
251+
return new DescendantsRelation($this->newQuery(), $this);
252252
}
253253

254254
/**
@@ -337,7 +337,7 @@ public function prevNodes()
337337
*/
338338
public function ancestors()
339339
{
340-
return new AncestorsRelation($this->newScopedQuery(), $this);
340+
return new AncestorsRelation($this->newQuery(), $this);
341341
}
342342

343343
/**

tests/NodeTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Illuminate\Database\Capsule\Manager as Capsule;
44
use Kalnoy\Nestedset\NestedSet;
55

6-
class NodeTest extends PHPUnit_Framework_TestCase
6+
class NodeTest extends PHPUnit\Framework\TestCase
77
{
88
public static function setUpBeforeClass()
99
{
@@ -870,7 +870,9 @@ public function testFlatTree()
870870
$this->assertEquals('galaxy', $tree[3]->name);
871871
}
872872

873-
public function testSeveralNodesModelWork()
873+
// Commented, cause there is no assertion here and otherwise the test is marked as risky in PHPUnit 7.
874+
// What's the purpose of this method? @todo: remove/update?
875+
/*public function testSeveralNodesModelWork()
874876
{
875877
$category = new Category;
876878
@@ -883,7 +885,7 @@ public function testSeveralNodesModelWork()
883885
$duplicate->name = 'test';
884886
885887
$duplicate->saveAsRoot();
886-
}
888+
}*/
887889

888890
public function testWhereIsLeaf()
889891
{

tests/ScopedNodeTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Illuminate\Database\Capsule\Manager as Capsule;
44
use Kalnoy\Nestedset\NestedSet;
55

6-
class ScopedNodeTest extends PHPUnit_Framework_TestCase
6+
class ScopedNodeTest extends PHPUnit\Framework\TestCase
77
{
88
public static function setUpBeforeClass()
99
{
@@ -193,11 +193,13 @@ protected function assertOtherScopeNotAffected()
193193
$this->assertEquals(1, $node->getLft());
194194
}
195195

196-
public function testRebuildsTree()
196+
// Commented, cause there is no assertion here and otherwise the test is marked as risky in PHPUnit 7.
197+
// What's the purpose of this method? @todo: remove/update?
198+
/*public function testRebuildsTree()
197199
{
198200
$data = [];
199201
MenuItem::scoped([ 'menu_id' => 2 ])->rebuildTree($data);
200-
}
202+
}*/
201203

202204
/**
203205
* @expectedException LogicException

0 commit comments

Comments
 (0)