From 91b84903b7924d2295da07dfdea22afb8ffd0d9c Mon Sep 17 00:00:00 2001 From: Dmitrii Chekaliuk Date: Thu, 16 May 2013 03:06:15 +0300 Subject: [PATCH] Fix Crawler::children() to not trigger a notice for childless node --- src/Symfony/Component/DomCrawler/Crawler.php | 4 +++- src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 03c6effebc..ff45049c7f 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -430,7 +430,9 @@ class Crawler extends \SplObjectStorage throw new \InvalidArgumentException('The current node list is empty.'); } - return new static($this->sibling($this->getNode(0)->firstChild), $this->uri); + $node = $this->getNode(0)->firstChild; + + return new static($node ? $this->sibling($node) : array(), $this->uri); } /** diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index 8aac5d082f..4411c7d443 100644 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -536,6 +536,14 @@ EOF } catch (\InvalidArgumentException $e) { $this->assertTrue(true, '->children() throws an \InvalidArgumentException if the node list is empty'); } + + try { + $crawler = new Crawler('

'); + $crawler->filter('p')->children(); + $this->assertTrue(true, '->children() does not trigger a notice if the node has no children'); + } catch (\PHPUnit_Framework_Error_Notice $e) { + $this->fail('->children() does not trigger a notice if the node has no children'); + } } public function testParents()