configMock = $this->getMockBuilder(Config::class) ->setMethods(['isVertexActive', 'invoiceOrderStatus']) ->disableOriginalConstructor() ->getMock(); $this->countryGuardMock = $this->getMockBuilder(CountryGuard::class) ->setMethods(['isOrderServiceableByVertex']) ->disableOriginalConstructor() ->getMock(); $this->taxInvoiceMock = $this->getMockBuilder(TaxInvoice::class) ->setMethods(['sendInvoiceRequest', 'sendRefundRequest']) ->disableOriginalConstructor() ->getMock(); $this->managerInterfaceMock = $this->getMockBuilder(ManagerInterface::class) ->setMethods(['addSuccessMessage']) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->configValidatorMock = $this->getMockBuilder(ConfigurationValidator::class) ->setMethods(['execute', 'isValid']) ->disableOriginalConstructor() ->getMockForAbstractClass(); $result = new ConfigurationValidator\Result(); $result->setValid(true); $this->configValidatorMock->method('execute') ->willReturn($result); $this->invoiceRequestBuilderMock = $this->getMockBuilder(InvoiceRequestBuilder::class) ->setMethods(['buildFromCreditmemo']) ->disableOriginalConstructor() ->getMock(); $this->hasInvoiceDeterminer = $this->getMockBuilder(OrderHasInvoiceDeterminer::class) ->setMethods(['hasinvoice']) ->disableOriginalConstructor() ->getMock(); $this->orderInvoiceStatusRepositoryMock = $this->getMockBuilder(OrderInvoiceStatusRepository::class) ->setMethods(['getByOrderId']) ->disableOriginalConstructor() ->getMock(); $this->orderInvoiceStatusRepositoryMock ->method('getByOrderId') ->willThrowException(new NoSuchEntityException(__('No Such Entity'))); $this->creditMemoObserver = $this->getObject( CreditMemoObserver::class, [ 'config' => $this->configMock, 'countryGuard' => $this->countryGuardMock, 'taxInvoice' => $this->taxInvoiceMock, 'messageManager' => $this->managerInterfaceMock, 'configValidator' => $this->configValidatorMock, 'invoiceRequestBuilder' => $this->invoiceRequestBuilderMock, 'hasInvoiceDeterminer' => $this->hasInvoiceDeterminer, 'orderInvoiceStatusRepository' => $this->orderInvoiceStatusRepositoryMock, ] ); } /** * Test if creditmemo is sent to Vertex * * @return void */ public function testSendRefundRequest() { /** @var MockObject|Event $eventMock */ $eventMock = $this->createPartialMock(Event::class, ['getCreditmemo']); /** @var MockObject|Observer $observerMock */ $observerMock = $this->createPartialMock(Observer::class, ['getEvent']); /** @var MockObject|Store $storeMock */ $storeMock = $this->createMock(Store::class); /** @var MockObject|Order $orderMock */ $orderMock = $this->createPartialMock(Order::class, ['getStore', 'getId', 'getStatus']); $orderMock->method('getStore')->willReturn($storeMock); /** @var MockObject|Creditmemo $creditMemoMock */ $creditMemoMock = $this->createMock(Creditmemo::class); $creditMemoMock->method('getOrder')->willReturn($orderMock); /** @var MockObject|ResponseInterface $responseMock */ $responseMock = $this->createPartialMock(Response::class, ['getItems']); $responseMock->method('getItems')->willReturn([]); $observerMock->expects($this->once()) ->method('getEvent') ->willReturn($eventMock); $eventMock->expects($this->once()) ->method('getCreditmemo') ->willReturn($creditMemoMock); $this->configMock->expects($this->once()) ->method('isVertexActive') ->with(null) ->willReturn(true); $this->hasInvoiceDeterminer->expects($this->once()) ->method('hasInvoice') ->willReturn(true); $this->countryGuardMock->expects($this->once()) ->method('isOrderServiceableByVertex') ->with($orderMock) ->willReturn(true); $this->configValidatorMock ->method('isValid') ->willReturn(true); $request = new Request(); $this->invoiceRequestBuilderMock->expects($this->once()) ->method('buildFromCreditmemo') ->with($creditMemoMock) ->willReturn($request); $this->taxInvoiceMock->expects($this->once()) ->method('sendRefundRequest') ->with($request, $orderMock) ->willReturn($responseMock); $this->managerInterfaceMock->expects($this->once()) ->method('addSuccessMessage') ->with('The Vertex invoice has been refunded.') ->willReturn($this->managerInterfaceMock); $this->creditMemoObserver->execute($observerMock); } }