Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91b8490

Browse files
committed
Fix Crawler::children() to not trigger a notice for childless node
1 parent 78cd045 commit 91b8490

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ public function children()
430430
throw new \InvalidArgumentException('The current node list is empty.');
431431
}
432432

433-
return new static($this->sibling($this->getNode(0)->firstChild), $this->uri);
433+
$node = $this->getNode(0)->firstChild;
434+
435+
return new static($node ? $this->sibling($node) : array(), $this->uri);
434436
}
435437

436438
/**

src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,14 @@ public function testChildren()
536536
} catch (\InvalidArgumentException $e) {
537537
$this->assertTrue(true, '->children() throws an \InvalidArgumentException if the node list is empty');
538538
}
539+
540+
try {
541+
$crawler = new Crawler('<p></p>');
542+
$crawler->filter('p')->children();
543+
$this->assertTrue(true, '->children() does not trigger a notice if the node has no children');
544+
} catch (\PHPUnit_Framework_Error_Notice $e) {
545+
$this->fail('->children() does not trigger a notice if the node has no children');
546+
}
539547
}
540548

541549
public function testParents()

0 commit comments

Comments
 (0)