Skip to content

Commit

Permalink
Fixed behaviour of getAncestors method. Issue-4
Browse files Browse the repository at this point in the history
  • Loading branch information
nicmart committed Apr 21, 2014
1 parent e63a822 commit da19b7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
In Tree you can find a basic but flexible tree data structure for php together with and an handful Builder class, that enables you to build tree in a fluent way.

## Changelog
- 0.2.3 Node::getAncestors now does not return the current node ([Issue 4](https://github.com/nicmart/Tree/issues/4))
- 0.2.2 Fixed a bug in the builder ([Issue 3](https://github.com/nicmart/Tree/issues/3))
- 0.2.1 root() and isRoot() methods
- 0.2.0 Dropped php 5.3 support. Node implemented as a trait.
Expand Down
2 changes: 1 addition & 1 deletion src/Tree/Node/NodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getParent()
*/
public function getAncestors()
{
$parents = [$this];
$parents = [];
$node = $this;
while ($parent = $node->getParent()) {
array_unshift($parents, $parent);
Expand Down
10 changes: 10 additions & 0 deletions tests/Tree/Node/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ public function testRemoveAllChildren()
$this->assertEmpty($root->getChildren());
}

public function testGetAncestors()
{
$root = new Node('r');
$root->addChild($a = new Node('a'));
$a->addChild($b = new Node('b'));
$b->addChild($c = new Node('c'));

$this->assertEquals([$root, $a, $b], $c->getAncestors());
}

public function testIsLeaf()
{
$root = new Node;
Expand Down

0 comments on commit da19b7a

Please sign in to comment.