/** * Invoke CreditmemoList service * * @param \Magento\Framework\Service\V1\Data\SearchCriteria $searchCriteria * @return \Magento\Framework\Service\V1\Data\SearchResults */ public function invoke(SearchCriteria $searchCriteria) { $creditmemos = []; foreach ($this->creditmemoRepository->find($searchCriteria) as $creditmemo) { $creditmemos[] = $this->creditmemoMapper->extractDto($creditmemo); } return $this->searchResultsBuilder->setItems($creditmemos)->setTotalCount(count($creditmemos))->setSearchCriteria($searchCriteria)->create(); }
public function testInvoke() { $creditmemoId = 1; $creditmemo = $this->getMock('\\Magento\\Sales\\Model\\Order\\Creditmemo', ['__wakeup', 'getEmailSent'], [], '', false); $this->creditmemoRepository->expects($this->once())->method('get')->with($creditmemoId)->will($this->returnValue($creditmemo)); $this->notifier->expects($this->any())->method('notify')->with($creditmemo)->will($this->returnValue(true)); $this->assertTrue($this->service->invoke($creditmemoId)); }
/** * Test creditmemo list service * * @return void */ public function testCreditmemo() { $this->creditmemoRepositoryMock->expects($this->once())->method('find')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnValue([$this->creditmemoMock])); $this->creditmemoMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->creditmemoMock))->will($this->returnValue($this->dataObjectMock)); $this->searchResultsBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo([$this->dataObjectMock]))->will($this->returnSelf()); $this->searchResultsBuilderMock->expects($this->once())->method('setTotalCount')->with($this->equalTo(count($this->creditmemoMock)))->will($this->returnSelf()); $this->searchResultsBuilderMock->expects($this->once())->method('setSearchCriteria')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnSelf()); $this->searchResultsBuilderMock->expects($this->once())->method('create')->will($this->returnValue('expected-result')); $this->assertEquals('expected-result', $this->creditmemoList->invoke($this->searchCriteriaMock)); }
/** * @expectedException \Magento\Framework\Exception\CouldNotSaveException * @expectedExceptionMessage Could not save credit memo */ public function testSaveWithException() { $entity = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->getMock(); $entity->expects($this->never())->method('getEntityId'); $mapper = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\Creditmemo')->disableOriginalConstructor()->getMock(); $mapper->expects($this->once())->method('save')->willThrowException(new \Exception('error')); $this->metadataMock->expects($this->any())->method('getMapper')->willReturn($mapper); $this->assertEquals($entity, $this->creditmemo->save($entity)); }
/** * Invoke creditmemo get service * * @param int $id * @return \Magento\Sales\Service\V1\Data\Creditmemo * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function invoke($id) { return $this->creditmemoMapper->extractDto($this->creditmemoRepository->get($id)); }
/** * test creditmemo cancel service */ public function testInvoke() { $this->creditmemoRepositoryMock->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->creditmemoMock)); $this->creditmemoMock->expects($this->once())->method('cancel')->will($this->returnSelf()); $this->assertTrue($this->creditmemoCancel->invoke(1)); }
/** * Invoke CreditmemoCancel service * * @param int $id * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function invoke($id) { return (bool) $this->creditmemoRepository->get($id)->cancel(); }
/** * Invoke notifyUser service * * @param int $id * @return bool */ public function invoke($id) { /** @var \Magento\Sales\Model\Order\Creditmemo $creditmemo */ $creditmemo = $this->creditmemoRepository->get($id); return $this->creditmemoNotifier->notify($creditmemo); }
/** * Test creditmemo get service */ public function testInvoke() { $this->creditmemoRepositoryMock->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->creditmemoMock)); $this->creditmemoMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->creditmemoMock))->will($this->returnValue($this->dataObjectMock)); $this->assertEquals($this->dataObjectMock, $this->creditmemoGet->invoke(1)); }