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

Skip to content

[DomCrawler] Fix Crawler::children() to not trigger a notice for childless node #8054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2013
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
4 changes: 3 additions & 1 deletion src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ public function children()
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);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ public function testChildren()
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true, '->children() throws an \InvalidArgumentException if the node list is empty');
}

try {
$crawler = new Crawler('<p></p>');
$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');
}
Copy link
Member

Choose a reason for hiding this comment

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

you should use a separate test instead of adding a separate group of assertions in the existing test. This would make it run even if the other test about siblings fails

}

public function testParents()
Expand Down