Skip to content

V5 - fix support for Laravel 5.7 and 5.8 (fixes #339, #351, #329, #334, #271, #365) #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2019
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
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

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

* **Laravel 5.5, 5.6, 5.7, 5.8** is supported since v4.3
* **Laravel 5.7, 5.8** is supported since v5
* **Laravel 5.5, 5.6** is supported since v4.3
* **Laravel 5.2, 5.3, 5.4** is supported since v4
* **Laravel 5.1** is supported in v3
* **Laravel 4** is supported in v2
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kalnoy/nestedset",
"description": "Nested Set Model for Laravel 4-5",
"description": "Nested Set Model for Laravel 5.7 and up",
"keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"],
"license": "MIT",

Expand All @@ -12,10 +12,10 @@
],

"require": {
"php": ">=5.5.9",
"illuminate/support": "5.2 - 5.8",
"illuminate/database": "5.2 - 5.8",
"illuminate/events": "5.2 - 5.8"
"php": ">=7.1.3",
"illuminate/support": "~5.7.0|~5.8.0",
"illuminate/database": "~5.7.0|~5.8.0",
"illuminate/events": "~5.7.0|~5.8.0"
},

"autoload": {
Expand All @@ -25,15 +25,15 @@
},

"require-dev": {
"phpunit/phpunit": "4.8.*"
"phpunit/phpunit": "7.*"
},

"minimum-stability": "dev",
"prefer-stable": true,

"extra": {
"branch-alias": {
"dev-master": "v4.2.x-dev"
"dev-master": "v5.0.x-dev"
},

"laravel": {
Expand Down
2 changes: 0 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
3 changes: 2 additions & 1 deletion src/AncestorsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public function addConstraints()
{
if ( ! static::$constraints) return;

$this->query->whereAncestorOf($this->parent)->defaultOrder();
$this->query->whereAncestorOf($this->parent)
->applyNestedSetScope();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/BaseRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public function getResults()
*/
public function addEagerConstraints(array $models)
{
// The first model in the array is always the parent, so add the scope constraints based on that model.
// @link https://github.com/laravel/framework/pull/25240
// @link https://github.com/lazychaser/laravel-nestedset/issues/351
optional($models[0])->applyNestedSetScope($this->query);

$this->query->whereNested(function (Builder $inner) use ($models) {
// We will use this query in order to apply constraints to the
// base query builder
Expand Down
3 changes: 2 additions & 1 deletion src/DescendantsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function addConstraints()
{
if ( ! static::$constraints) return;

$this->query->whereDescendantOf($this->parent);
$this->query->whereDescendantOf($this->parent)
->applyNestedSetScope();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/NodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function children()
*/
public function descendants()
{
return new DescendantsRelation($this->newScopedQuery(), $this);
return new DescendantsRelation($this->newQuery(), $this);
}

/**
Expand Down Expand Up @@ -337,7 +337,7 @@ public function prevNodes()
*/
public function ancestors()
{
return new AncestorsRelation($this->newScopedQuery(), $this);
return new AncestorsRelation($this->newQuery(), $this);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions tests/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Capsule\Manager as Capsule;
use Kalnoy\Nestedset\NestedSet;

class NodeTest extends PHPUnit_Framework_TestCase
class NodeTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass()
{
Expand Down Expand Up @@ -870,7 +870,9 @@ public function testFlatTree()
$this->assertEquals('galaxy', $tree[3]->name);
}

public function testSeveralNodesModelWork()
// Commented, cause there is no assertion here and otherwise the test is marked as risky in PHPUnit 7.
// What's the purpose of this method? @todo: remove/update?
/*public function testSeveralNodesModelWork()
{
$category = new Category;

Expand All @@ -883,7 +885,7 @@ public function testSeveralNodesModelWork()
$duplicate->name = 'test';

$duplicate->saveAsRoot();
}
}*/

public function testWhereIsLeaf()
{
Expand Down
8 changes: 5 additions & 3 deletions tests/ScopedNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Capsule\Manager as Capsule;
use Kalnoy\Nestedset\NestedSet;

class ScopedNodeTest extends PHPUnit_Framework_TestCase
class ScopedNodeTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass()
{
Expand Down Expand Up @@ -193,11 +193,13 @@ protected function assertOtherScopeNotAffected()
$this->assertEquals(1, $node->getLft());
}

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

/**
* @expectedException LogicException
Expand Down