Esempio n. 1
0
 /**
  * @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\\Resource\\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);
 }
Esempio n. 3
0
 /**
  * @return mixed
  */
 public function getItemsCollection()
 {
     if (empty($this->_items)) {
         $this->_items = $this->_cmItemCollectionFactory->create()->setCreditmemoFilter($this->getId());
         if ($this->getId()) {
             foreach ($this->_items as $item) {
                 $item->setCreditmemo($this);
             }
         }
     }
     return $this->_items;
 }