The reason is that phpunit will stub all methods from ItemCollection
(because you didn't specify any of them). If you will specify at least one method (for example through setMethods
method) then phpunit will stub only these specified methods and the rest of them will stay as in original class (for example getIterator
method).
So, the question is - why do you need mock that class? If you want stub/mock just one method from it, then do it only for that one:
$mockIC = $this->getMockBuilder('\SK\API\Model\ItemCollection\ItemCollection')
->setMethods(array('methodYouWantStub'))
->setConstructorArgs(array($this->container->get('mongo.db')))
->getMock();