Skip to content

Commit 12191e6

Browse files
committed
fix failing test
1 parent 81d3f58 commit 12191e6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ public function isAncestor(int $id): bool
252252
*/
253253
public function getAncestor(int $id)
254254
{
255-
if ($this->parent !== null && $this->parent->id() == $id) {
256-
return $this->parent;
255+
if ($this->parent !== null) {
256+
if ($this->parent->id() == $id) {
257+
return $this->parent;
258+
}
259+
return $this->parent->getAncestor($id);
257260
}
258261
return null;
259262
}

tests/Node/ParentTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public function testGetGreatAncestor()
301301
$parent->addChild($child);
302302
$child->addChild($child2);
303303
$ancestor = $child2->getAncestor($parent->id());
304+
$this->assertNotNull($ancestor);
304305
$this->assertEquals($parent->id(), $ancestor->id());
305306
}
306307

0 commit comments

Comments
 (0)