Fix Crawler::children() to not trigger a notice for childless node

This commit is contained in:
Dmitrii Chekaliuk 2013-05-16 03:06:15 +03:00
parent 78cd0452ec
commit 91b84903b7
2 changed files with 11 additions and 1 deletions

View File

@ -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);
}
/**

View File

@ -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('<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');
}
}
public function testParents()