When I was writing unit tests for one magento collection I faced with the following strange thing:
Magento allows create mock for collection with it's internal phpunit method:
\Magento\Framework\TestFramework\Unit\Helper\ObjectManager
public function getCollectionMock($className, array $data)
{
if (!is_subclass_of($className, '\Magento\Framework\Data\Collection')) {
throw new \InvalidArgumentException(
$className . ' does not instance of \Magento\Framework\Data\Collection'
);
}
$mock = $this->_testObject->getMock($className, [], [], '', false, false);
$iterator = new \ArrayIterator($data);
$mock->expects(
$this->_testObject->any()
)->method(
'getIterator'
)->will(
$this->_testObject->returnValue($iterator)
);
return $mock;
}
The problem appear when I'm trying to create Mock of \Magento\Framework\Data\Collection
.
As you can see magento checks if described class is subclass of \Magento\Framework\Data\Collection
. Not instance of
!
Magento returns the described collection here:
$product->getMediaGalleryImages();