diff --git a/src/Contracts/NestedSetCollection.php b/src/Contracts/NestedSetCollection.php index c65040c..cb4162e 100644 --- a/src/Contracts/NestedSetCollection.php +++ b/src/Contracts/NestedSetCollection.php @@ -46,4 +46,32 @@ public function toTree($root = false): NestedSetCollection; * @return NestedSetCollection */ public function toFlatTree($root = false): NestedSetCollection; + + /** + * Count the number of items in the collection. + * + * @return int + */ + public function count(): int; + + /** + * Get the values of a given key. + * + * @param string|int|array|null $value + * @param string|null $key + * + * @return \Illuminate\Support\Collection + */ + public function pluck($value, $key = null); + + /** + * Run a map over each of the items. + * + * @template TMapValue + * + * @param callable(NodeModel, int): TMapValue $callback + * + * @return \Illuminate\Support\Collection + */ + public function map(callable $callback); } diff --git a/tests/NodeTest.php b/tests/NodeTest.php index d9b93ac..b0c4d3e 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -1,9 +1,14 @@ create('categories', function (Illuminate\Database\Schema\Blueprint $table) { + $schema->create('categories', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->softDeletes(); @@ -225,7 +230,7 @@ public function testCategoryMovesUp() public function testFailsToInsertIntoChild() { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $node = $this->findCategory('notebooks'); $target = $node->children()->first(); @@ -235,7 +240,7 @@ public function testFailsToInsertIntoChild() public function testFailsToAppendIntoItself() { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $node = $this->findCategory('notebooks'); @@ -244,7 +249,7 @@ public function testFailsToAppendIntoItself() public function testFailsToPrependIntoItself() { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $node = $this->findCategory('notebooks'); @@ -339,7 +344,7 @@ public function testParentIdAttributeAccessorAppendsNode() public function testFailsToSaveNodeUntilNotInserted() { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $node = new Category(); $node->save(); @@ -405,7 +410,7 @@ public function testSoftDeletedNodeisDeletedWhenParentIsDeleted() public function testFailsToSaveNodeUntilParentIsSaved() { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $node = new Category(['title' => 'Node']); $parent = new Category(['title' => 'Parent']); diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index 6886263..9e91cce 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -1,11 +1,13 @@ create('menu_items', function (Illuminate\Database\Schema\Blueprint $table) { + $schema->create('menu_items', function (\Illuminate\Database\Schema\Blueprint $table) { $table->increments('id'); $table->unsignedInteger('menu_id'); $table->string('title')->nullable(); @@ -204,7 +206,7 @@ protected function assertOtherScopeNotAffected() public function testAppendingToAnotherScopeFails() { - $this->expectException(LogicException::class); + $this->expectException(\LogicException::class); $a = MenuItem::find(1); $b = MenuItem::find(3); @@ -214,7 +216,7 @@ public function testAppendingToAnotherScopeFails() public function testInsertingBeforeAnotherScopeFails() { - $this->expectException(LogicException::class); + $this->expectException(\LogicException::class); $a = MenuItem::find(1); $b = MenuItem::find(3); diff --git a/tests/models/Category.php b/tests/models/Category.php index e3ce3a5..1f1e7d2 100644 --- a/tests/models/Category.php +++ b/tests/models/Category.php @@ -1,5 +1,7 @@