Skip to content
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: 3 additions & 0 deletions src/Storage/DbalNestedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ public function getTree() {
* {@inheritdoc}
*/
public function deleteNode(Node $node) {
if ($node->getLeft() < 1 || $node->getRight() < 1) {
throw new \InvalidArgumentException("Left and right values must be > 0");
}
$left = $node->getLeft();
$right = $node->getRight();
$width = $right - $left + 1;
Expand Down
10 changes: 10 additions & 0 deletions tests/Functional/DbalNestedSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ public function testDeleteNode() {
$tree = $this->nestedSet->getTree();
}

/**
* Tests deleting a node with missing values.
*
* @expectedException \InvalidArgumentException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, although ->setExpectedException is preferred over @ExpectedException see https://thephp.cc/news/2016/02/questioning-phpunit-best-practices

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed up on #10

*/
public function testDeleteNodeInvalid() {
$node = new Node(1, 1);
$this->nestedSet->deleteNode($node);
}

/**
* Tests deleting a node and its sub-tree.
*/
Expand Down