$data =
$this->
createTestCrawler()->
filterXPath('//ul[1]/li'
)->
each(fn ($node,
$i) =>
$i.'-'.
$node->
text());
$this->
assertEquals(['0-One', '1-Two', '2-Three'
],
$data, '->each() executes an anonymous function on each node of the list'
);
} public function testIteration() { $crawler =
$this->
createTestCrawler()->
filterXPath('//li'
);
$this->
assertInstanceOf(\Traversable::
class,
$crawler);
$this->
assertContainsOnlyInstancesOf('DOMElement',
iterator_to_array($crawler), 'Iterating a Crawler gives DOMElement instances'
);
} public function testSlice() { $crawler =
$this->
createTestCrawler()->
filterXPath('//ul[1]/li'
);
$this->
assertNotSame($crawler->
slice(),
$crawler, '->slice() returns a new instance of a crawler'
);
$this->
assertInstanceOf(Crawler::
class,
$crawler->
slice(), '->slice() returns a new instance of a crawler'
);
$this->
assertCount(3,
$crawler->
slice(), '->slice() does not slice the nodes in the list if any param is entered'
);
$this->
assertCount(1,
$crawler->
slice(1, 1
), '->slice() slices the nodes in the list'
);
}