Method each return an instance of Crawler instead DOMElement

This commit is contained in:
Diego Saint Esteben 2012-12-25 20:45:05 -03:00 committed by Fabien Potencier
parent bc6d68803e
commit 14eed63069
2 changed files with 4 additions and 3 deletions

View File

@ -277,7 +277,7 @@ class Crawler extends \SplObjectStorage
*
* $crawler->filter('h1')->each(function ($node, $i)
* {
* return $node->nodeValue;
* return $node->text();
* });
*
* @param \Closure $closure An anonymous function
@ -290,6 +290,7 @@ class Crawler extends \SplObjectStorage
{
$data = array();
foreach ($this as $i => $node) {
$node = new static($node, $this->uri);
$data[] = $closure($node, $i);
}

View File

@ -276,8 +276,8 @@ EOF
public function testEach()
{
$data = $this->createTestCrawler()->filterXPath('//ul[1]/li')->each(function ($node, $i) {
return $i.'-'.$node->nodeValue;
$data = $this->createTestCrawler()->filter('ul:first-child li')->each(function ($node, $i) {
return $i.'-'.$node->text();
});
$this->assertEquals(array('0-One', '1-Two', '2-Three'), $data, '->each() executes an anonymous function on each node of the list');