Method each return an instance of Crawler instead DOMElement
This commit is contained in:
parent
bc6d68803e
commit
14eed63069
|
@ -277,7 +277,7 @@ class Crawler extends \SplObjectStorage
|
||||||
*
|
*
|
||||||
* $crawler->filter('h1')->each(function ($node, $i)
|
* $crawler->filter('h1')->each(function ($node, $i)
|
||||||
* {
|
* {
|
||||||
* return $node->nodeValue;
|
* return $node->text();
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @param \Closure $closure An anonymous function
|
* @param \Closure $closure An anonymous function
|
||||||
|
@ -290,6 +290,7 @@ class Crawler extends \SplObjectStorage
|
||||||
{
|
{
|
||||||
$data = array();
|
$data = array();
|
||||||
foreach ($this as $i => $node) {
|
foreach ($this as $i => $node) {
|
||||||
|
$node = new static($node, $this->uri);
|
||||||
$data[] = $closure($node, $i);
|
$data[] = $closure($node, $i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,8 +276,8 @@ EOF
|
||||||
|
|
||||||
public function testEach()
|
public function testEach()
|
||||||
{
|
{
|
||||||
$data = $this->createTestCrawler()->filterXPath('//ul[1]/li')->each(function ($node, $i) {
|
$data = $this->createTestCrawler()->filter('ul:first-child li')->each(function ($node, $i) {
|
||||||
return $i.'-'.$node->nodeValue;
|
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');
|
$this->assertEquals(array('0-One', '1-Two', '2-Three'), $data, '->each() executes an anonymous function on each node of the list');
|
||||||
|
|
Reference in New Issue