Skip to content

Commit a4cbbe7

Browse files
committed
Fixed lazychaser#53: support l5.1.9
1 parent 9398174 commit a4cbbe7

File tree

5 files changed

+55
-45
lines changed

5 files changed

+55
-45
lines changed

CHANGELOG.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 3.0.0
2+
3+
* Support Laravel 5.1.9
4+
* Renamed `append` to `appendNode`, `prepend` to `prependNode`
5+
* Renamed `next` to `nextNodes`, `prev` to `prevNodes`
6+
* Renamed `after` to `afterNode`, `before` to `beforeNode`
7+
18
### 2.4.0
29

310
* Added query methods `whereNotDescendantOf`, `orWhereDescendantOf`, `orWhereNotDescendantOf`

README.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ There are few ways to append a node:
106106
$node->appendTo($parent)->save();
107107

108108
// #2 Using parent node
109-
$parent->append($node);
109+
$parent->appendNode($node);
110110

111111
// #3 Using parent's children relationship
112112
$parent->children()->create($attributes);
@@ -129,7 +129,7 @@ And only a couple ways to prepend:
129129
$node->prependTo($parent)->save();
130130

131131
// #2
132-
$parent->prepend($node);
132+
$parent->prependNode($node);
133133
```
134134

135135
#### Inserting before or after specified node
@@ -141,8 +141,8 @@ it will be moved to the new position and parent will be changed if it's needed.*
141141

142142
```php
143143
# Explicit save
144-
$node->after($neighbor)->save();
145-
$node->before($neighbor)->save();
144+
$node->afterNode($neighbor)->save();
145+
$node->beforeNode($neighbor)->save();
146146

147147
# Implicit save
148148
$node->insertAfter($neighbor);

UPGRADE.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Upgrading to 3.0
2+
3+
Some methods were renamed, see changelog for more details.
4+
15
### Upgrading to 2.0
26

37
Calling `$parent->append($node)` and `$parent->prepend($node)` now automatically

src/Node.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ public function siblings($dir = null)
430430
switch ($dir)
431431
{
432432
case self::AFTER:
433-
$query = $this->next();
433+
$query = $this->nextNodes();
434434

435435
break;
436436

437437
case self::BEFORE:
438-
$query = $this->prev();
438+
$query = $this->prevNodes();
439439

440440
break;
441441

@@ -477,7 +477,7 @@ public function prevSiblings()
477477
*
478478
* @return QueryBuilder
479479
*/
480-
public function next()
480+
public function nextNodes()
481481
{
482482
return $this->newQuery()->whereIsAfter($this->getKey())->defaultOrder();
483483
}
@@ -487,7 +487,7 @@ public function next()
487487
*
488488
* @return QueryBuilder
489489
*/
490-
public function prev()
490+
public function prevNodes()
491491
{
492492
return $this->newQuery()->whereIsBefore($this->getKey())->reversed();
493493
}
@@ -529,7 +529,7 @@ public function saveAsRoot()
529529
*
530530
* @return bool
531531
*/
532-
public function append(Node $node)
532+
public function appendNode(Node $node)
533533
{
534534
return $node->appendTo($this)->save();
535535
}
@@ -541,7 +541,7 @@ public function append(Node $node)
541541
*
542542
* @return bool
543543
*/
544-
public function prepend(Node $node)
544+
public function prependNode(Node $node)
545545
{
546546
return $node->prependTo($this)->save();
547547
}
@@ -577,7 +577,7 @@ public function prependTo(Node $parent)
577577
*
578578
* @return $this
579579
*/
580-
public function after(Node $node)
580+
public function afterNode(Node $node)
581581
{
582582
return $this->setAction('after', $node);
583583
}
@@ -591,7 +591,7 @@ public function after(Node $node)
591591
*/
592592
public function insertAfter(Node $node)
593593
{
594-
return $this->after($node)->save();
594+
return $this->afterNode($node)->save();
595595
}
596596

597597
/**
@@ -601,7 +601,7 @@ public function insertAfter(Node $node)
601601
*
602602
* @return $this
603603
*/
604-
public function before(Node $node)
604+
public function beforeNode(Node $node)
605605
{
606606
return $this->setAction('before', $node);
607607
}
@@ -615,7 +615,7 @@ public function before(Node $node)
615615
*/
616616
public function insertBefore(Node $node)
617617
{
618-
if ($this->before($node)->save())
618+
if ($this->beforeNode($node)->save())
619619
{
620620
// We'll' update the target node since it will be moved
621621
$node->refreshNode();
@@ -817,7 +817,6 @@ public function newFromBuilder($attributes = array(), $connection = null)
817817
* Use `children` key on `$attributes` to create child nodes.
818818
*
819819
* @param Node $parent
820-
*
821820
*/
822821
public static function create(array $attributes = array(), Node $parent = null)
823822
{
@@ -967,7 +966,7 @@ public function getParentId()
967966
*/
968967
public function getNext(array $columns = array('*'))
969968
{
970-
return $this->next()->first($columns);
969+
return $this->nextNodes()->first($columns);
971970
}
972971

973972
/**
@@ -979,7 +978,7 @@ public function getNext(array $columns = array('*'))
979978
*/
980979
public function getPrev(array $columns = array('*'))
981980
{
982-
return $this->prev()->first($columns);
981+
return $this->prevNodes()->first($columns);
983982
}
984983

985984
/**

tests/NodeTest.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function assertTreeNotBroken($table = 'categories')
6363

6464
$sql = 'select max(error) as errors from ('.implode(' union ', $checks).') _';
6565

66-
$actual = Capsule::connection()->selectOne($sql);
66+
$actual = (array)Capsule::connection()->selectOne($sql);
6767

6868
$this->assertEquals(array('errors' => null), $actual, "The tree structure of $table is broken!");
6969
}
@@ -137,7 +137,7 @@ public function testRecievesValidValuesWhenAppendedTo()
137137

138138
$accepted = array($root->_rgt, $root->_rgt + 1, $root->id);
139139

140-
$root->append($node);
140+
$root->appendNode($node);
141141

142142
$this->assertTrue($node->hasMoved());
143143
$this->assertEquals($accepted, $this->nodeValues($node));
@@ -150,7 +150,7 @@ public function testRecievesValidValuesWhenPrependedTo()
150150
{
151151
$root = Category::root();
152152
$node = new Category([ 'name' => 'test' ]);
153-
$root->prepend($node);
153+
$root->prependNode($node);
154154

155155
$this->assertTrue($node->hasMoved());
156156
$this->assertEquals(array($root->_lft + 1, $root->_lft + 2, $root->id), $this->nodeValues($node));
@@ -164,7 +164,7 @@ public function testRecievesValidValuesWhenInsertedAfter()
164164
{
165165
$target = $this->findCategory('apple');
166166
$node = new Category([ 'name' => 'test' ]);
167-
$node->after($target)->save();
167+
$node->afterNode($target)->save();
168168

169169
$this->assertTrue($node->hasMoved());
170170
$this->assertEquals(array($target->_rgt + 1, $target->_rgt + 2, $target->parent->id), $this->nodeValues($node));
@@ -177,7 +177,7 @@ public function testRecievesValidValuesWhenInsertedBefore()
177177
{
178178
$target = $this->findCategory('apple');
179179
$node = new Category([ 'name' => 'test' ]);
180-
$node->before($target)->save();
180+
$node->beforeNode($target)->save();
181181

182182
$this->assertTrue($node->hasMoved());
183183
$this->assertEquals(array($target->_lft, $target->_lft + 1, $target->parent->id), $this->nodeValues($node));
@@ -189,7 +189,7 @@ public function testCategoryMovesDown()
189189
$node = $this->findCategory('apple');
190190
$target = $this->findCategory('mobile');
191191

192-
$target->append($node);
192+
$target->appendNode($node);
193193

194194
$this->assertTrue($node->hasMoved());
195195
$this->assertNodeRecievesValidValues($node);
@@ -201,7 +201,7 @@ public function testCategoryMovesUp()
201201
$node = $this->findCategory('samsung');
202202
$target = $this->findCategory('notebooks');
203203

204-
$target->append($node);
204+
$target->appendNode($node);
205205

206206
$this->assertTrue($node->hasMoved());
207207
$this->assertTreeNotBroken();
@@ -216,7 +216,7 @@ public function testFailsToInsertIntoItself()
216216
$node = $this->findCategory('notebooks');
217217
$target = $node->children()->first();
218218

219-
$node->after($target)->save();
219+
$node->afterNode($target)->save();
220220
}
221221

222222
public function testWithoutRootWorks()
@@ -229,42 +229,42 @@ public function testWithoutRootWorks()
229229
public function testAncestorsReturnsAncestorsWithoutNodeItself()
230230
{
231231
$node = $this->findCategory('apple');
232-
$path = $node->ancestors()->lists('name');
232+
$path = $node->ancestors()->lists('name')->all();
233233

234234
$this->assertEquals(array('store', 'notebooks'), $path);
235235
}
236236

237237
public function testGetsAncestorsByStatic()
238238
{
239-
$path = Category::ancestorsOf(3)->lists('name');
239+
$path = Category::ancestorsOf(3)->lists('name')->all();
240240

241241
$this->assertEquals(array('store', 'notebooks'), $path);
242242
}
243243

244244
public function testGetsAncestorsDirect()
245245
{
246-
$path = Category::find(8)->getAncestors()->lists('id');
246+
$path = Category::find(8)->getAncestors()->lists('id')->all();
247247

248248
$this->assertEquals(array(1, 5, 7), $path);
249249
}
250250

251251
public function testDescendants()
252252
{
253253
$node = $this->findCategory('mobile');
254-
$descendants = $node->descendants()->lists('name');
254+
$descendants = $node->descendants()->lists('name')->all();
255255
$expected = array('nokia', 'samsung', 'galaxy', 'sony', 'lenovo');
256256

257257
$this->assertEquals($expected, $descendants);
258258

259-
$descendants = $node->getDescendants()->lists('name');
259+
$descendants = $node->getDescendants()->lists('name')->all();
260260

261261
$this->assertEquals(count($descendants), $node->getDescendantCount());
262262
$this->assertEquals($expected, $descendants);
263263
}
264264

265265
public function testWithDepthWorks()
266266
{
267-
$nodes = Category::withDepth()->limit(4)->lists('depth');
267+
$nodes = Category::withDepth()->limit(4)->lists('depth')->all();
268268

269269
$this->assertEquals(array(0, 1, 2, 2), $nodes);
270270
}
@@ -378,17 +378,17 @@ public function testFailsToSaveNodeUntilParentIsSaved()
378378
public function testSiblings()
379379
{
380380
$node = $this->findCategory('samsung');
381-
$siblings = $node->siblings()->lists('id');
382-
$next = $node->nextSiblings()->lists('id');
383-
$prev = $node->prevSiblings()->lists('id');
381+
$siblings = $node->siblings()->lists('id')->all();
382+
$next = $node->nextSiblings()->lists('id')->all();
383+
$prev = $node->prevSiblings()->lists('id')->all();
384384

385385
$this->assertEquals(array(6, 9, 10), $siblings);
386386
$this->assertEquals(array(9, 10), $next);
387387
$this->assertEquals(array(6), $prev);
388388

389-
$siblings = $node->getSiblings()->lists('id');
390-
$next = $node->getNextSiblings()->lists('id');
391-
$prev = $node->getPrevSiblings()->lists('id');
389+
$siblings = $node->getSiblings()->lists('id')->all();
390+
$next = $node->getNextSiblings()->lists('id')->all();
391+
$prev = $node->getPrevSiblings()->lists('id')->all();
392392

393393
$this->assertEquals(array(6, 9, 10), $siblings);
394394
$this->assertEquals(array(9, 10), $next);
@@ -404,7 +404,7 @@ public function testSiblings()
404404
public function testFetchesReversed()
405405
{
406406
$node = $this->findCategory('sony');
407-
$siblings = $node->prevSiblings()->reversed()->pluck('id');
407+
$siblings = $node->prevSiblings()->reversed()->value('id');
408408

409409
$this->assertEquals(7, $siblings);
410410
}
@@ -468,15 +468,15 @@ public function testToTreeBuildsWithRootItemIdProvided()
468468
public function testRetrievesNextNode()
469469
{
470470
$node = $this->findCategory('apple');
471-
$next = $node->next()->first();
471+
$next = $node->nextNodes()->first();
472472

473473
$this->assertEquals('lenovo', $next->name);
474474
}
475475

476476
public function testRetrievesPrevNode()
477477
{
478478
$node = $this->findCategory('apple');
479-
$next = $node->prev()->first();
479+
$next = $node->prevNodes()->first();
480480

481481
$this->assertEquals('notebooks', $next->name);
482482
}
@@ -487,11 +487,11 @@ public function testMultipleAppendageWorks()
487487

488488
$child = new Category([ 'name' => 'test' ]);
489489

490-
$parent->append($child);
490+
$parent->appendNode($child);
491491

492-
$child->append(new Category([ 'name' => 'sub' ]));
492+
$child->appendNode(new Category([ 'name' => 'sub' ]));
493493

494-
$parent->append(new Category([ 'name' => 'test2' ]));
494+
$parent->appendNode(new Category([ 'name' => 'test2' ]));
495495

496496
$this->assertTreeNotBroken();
497497
}
@@ -592,15 +592,15 @@ public function testWhereDescendantsOf()
592592
public function testAncestorsByNode()
593593
{
594594
$category = $this->findCategory('apple');
595-
$ancestors = Category::whereAncestorOf($category)->lists('id');
595+
$ancestors = Category::whereAncestorOf($category)->lists('id')->all();
596596

597597
$this->assertEquals([ 1, 2 ], $ancestors);
598598
}
599599

600600
public function testDescendantsByNode()
601601
{
602602
$category = $this->findCategory('notebooks');
603-
$res = Category::whereDescendantOf($category)->lists('id');
603+
$res = Category::whereDescendantOf($category)->lists('id')->all();
604604

605605
$this->assertEquals([ 3, 4 ], $res);
606606
}

0 commit comments

Comments
 (0)