/** * @return mixed */ public function getItemsCollection() { $collection = $this->_cmItemCollectionFactory->create()->setCreditmemoFilter($this->getId()); if ($this->getId()) { foreach ($collection as $item) { $item->setCreditmemo($this); } } return $collection; }
public function testGetItemsCollectionWithoutId() { $items = []; $itemMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Creditmemo\\Item')->disableOriginalConstructor()->getMock(); $itemMock->expects($this->never())->method('setCreditmemo'); $items[] = $itemMock; /** @var ItemCollection|\PHPUnit_Framework_MockObject_MockObject $itemCollectionMock */ $itemCollectionMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\ResourceModel\\Order\\Creditmemo\\Item\\Collection')->disableOriginalConstructor()->getMock(); $itemCollectionMock->expects($this->once())->method('setCreditmemoFilter')->with(null)->will($this->returnValue($items)); $this->cmItemCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($itemCollectionMock)); $itemsCollection = $this->creditmemo->getItemsCollection(); $this->assertEquals($items, $itemsCollection); }