Fix Crawler::children() to not trigger a notice for childless node
This commit is contained in:
parent
78cd0452ec
commit
91b84903b7
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user