public function test_remove_even_in_foreach() { $collection = new Collection(array(1, 2, 3, 4)); $i = 0; foreach ($collection as $entry) { if ($i % 2 === 0) { $collection->remove($entry); // remove even rows inside a foreach } ++$i; } $this->assertCount(2, $collection, 'Should be halved'); $this->assertSame(array(2, 4), $collection->toArray()); }