Mock IteratorAggregate with Mockery to Fix foreach in Tests

📰 Dev.to · Recca Tsai

Mocking IteratorAggregate breaks foreach in PHPUnit. Return an ArrayObject from the mocked getIterator method to make foreach iterate over test data correctly.

Published 3 Mar 2026
Read full article → ← Back to Reads