public function testEach() { $resultSet = new ResultSet(array(1 => array('_id' => 1, 'field' => 'value1'), 2 => array('_id' => 2, 'field' => 'value2'), 3 => array('_id' => 3, 'field' => 'value3'))); // skip even ids $resultSet->each(function ($item, $id, $resultSet) { if ($item['_id'] % 2 === 0) { unset($resultSet[$id]); } }); $this->assertEquals(array(1 => array('_id' => 1, 'field' => 'value1'), 3 => array('_id' => 3, 'field' => 'value3')), iterator_to_array($resultSet)); }