Skip to content

Commit

Permalink
Fix calling getAncestors on empty collection (#20)
Browse files Browse the repository at this point in the history
* Fix executing getAncestors on empty collection
  • Loading branch information
Art4es authored Mar 16, 2020
1 parent c87bae6 commit 31b5e0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Helpers/LTreeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ public static function pathAsString($path): string

public static function getAncestors(Collection $collection): Collection
{
if ($collection->count() === 0) {
return new Collection();
}
$first = $collection->first();
$paths = $collection->pluck('path')->map(function ($item) {
$paths = $collection->pluck($first->getLtreePathColumn())->map(function ($item) {
return "'${item}'";
});
$paths = $paths->implode(', ');
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/LtreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function deleteViaServiceSubtree(): void
/** @test */
public function ancestors(): void
{
$this->assertCount(0, LTreeHelper::getAncestors(new CollectionBase()));
$nodes = $this->createTreeNodes($this->getTreeNodes());
$this->assertSame(3, $nodes[1]::ancestorsOf($nodes[6])->get()->count());
$this->assertTrue($nodes[2]->isParentOf(5));
Expand Down

0 comments on commit 31b5e0d

Please sign in to comment.