public function testUnsetInForeach()
{
$data = array('Delete me');
$collection = new Collection(array('data' => $data));
$this->assertIdentical($data, $collection->to('array'));
$cpt = 0;
foreach ($collection as $i => $word) {
if ($word === 'Delete me') {
unset($collection[$i]);
}
$cpt++;
}
$this->assertEqual(1, $cpt);
$this->assertIdentical(array(), $collection->to('array'));
$data = array('Hello', 'Delete me', 'Delete me', 'Delete me', 'Delete me', 'Delete me', 'Hello again!', 'Delete me');
$collection = new Collection(array('data' => $data));
$this->assertIdentical($data, $collection->to('array'));
foreach ($collection as $i => $word) {
if ($word === 'Delete me') {
unset($collection[$i]);
}
}
$expected = array(0 => 'Hello', 6 => 'Hello again!');
$results = $collection->to('array');
$this->assertIdentical($expected, $results);
$data = array('Delete me', 'Hello', 'Delete me', 'Delete me', 'Delete me', 'Delete me', 'Hello again!', 'Delete me');
$collection = new Collection(array('data' => $data));
$this->assertIdentical($data, $collection->to('array'));
foreach ($collection as $i => $word) {
if ($word === 'Delete me') {
unset($collection[$i]);
}
}
$expected = array(1 => 'Hello', 6 => 'Hello again!');
$results = $collection->to('array');
$this->assertIdentical($expected, $results);
}