Skip to content

Instantly share code, notes, and snippets.

@philipobenito
Created October 9, 2014 08:53
Show Gist options
  • Save philipobenito/7ef4cbd678ae41ce34e6 to your computer and use it in GitHub Desktop.
Save philipobenito/7ef4cbd678ae41ce34e6 to your computer and use it in GitHub Desktop.
<?php
function mockIteratorItems(\Iterator $iterator, array $items, $includeCallsToKey = false)
{
$iterator->expects($this->at(0))->method('rewind');
$counter = 1;
foreach ($items as $k => $v) {
$iterator->expects($this->at($counter++))->method('valid')->will($this->returnValue(true));
$iterator->expects($this->at($counter++))->method('current')->will($this->returnValue($v));
if ($includeCallsToKey) {
$iterator->expects($this->at($counter++))->method('key')->will($this->returnValue($k));
}
$iterator->expects($this->at($counter++))->method('next');
}
$iterator->expects($this->at($counter))->method('valid')->will($this->returnValue(false));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment