I've asked this once already here: How to properly use getCollectionMock
But that was for a different reason, and in the meantime the Magento\Framework\TestFramework\Unit\Helper\ObjectManager
is deprecated so this code is not recommended anymore.
$om = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$collectionMock = $om->getCollectionMock(\Collection\Class\Here, [$obj1, $obj2]);
where $obj1, $obj2
are objects returned when iterating through the mocked collection
How can I mock a collection without the use of unit test object manager helper?