/** * @test */ public function foreachOverCollection() { $model1 = new MyModel(); $model1->setId(1); $this->collection->add($model1); $model2 = new MyModel(); $model2->setId(2); $this->collection->add($model2); $model3 = new MyModel(); $model3->setId(3); $this->collection->add($model3); $i = 0; foreach ($this->collection as $model) { /** @var $model MyModel */ $this->assertSame(spl_object_hash($model), $this->collection->key()); $this->assertTrue(in_array($model->getId(), [1, 2, 3])); $i++; } $this->assertSame(3, $i); }