requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class) ->setMethods(['getPostValue']) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->viewMock = $this->getMockBuilder(\Magento\Framework\App\ViewInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->coreRegistryMock = $this->getMockBuilder(\Magento\Framework\Registry::class) ->setMethods(['register']) ->disableOriginalConstructor() ->getMock(); $this->resultLayoutMock = $this->getMockBuilder(\Magento\Framework\View\Result\Layout::class) ->setMethods(['addDefaultHandle', 'getLayout', 'getUpdate', 'load']) ->disableOriginalConstructor() ->getMock(); $this->resultLayoutFactoryMock = $this->getMockBuilder(\Magento\Framework\View\Result\LayoutFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->resultLayoutFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultLayoutMock); $this->transactionMock = $this->getMockBuilder( \Magento\Paypal\Model\Payflow\Service\Response\Transaction::class )->setMethods(['getResponseObject', 'validateResponse', 'savePaymentInQuote']) ->disableOriginalConstructor() ->getMock(); $this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class) ->setMethods(['getRequest']) ->disableOriginalConstructor() ->getMock(); $this->contextMock->expects($this->once()) ->method('getRequest') ->willReturn($this->requestMock); $this->responseValidatorMock = $this->getMockBuilder( \Magento\Paypal\Model\Payflow\Service\Response\Validator\ResponseValidator::class )->disableOriginalConstructor() ->getMock(); $this->payflowFacade = $this->getMockBuilder(Transparent::class) ->disableOriginalConstructor() ->setMethods([]) ->getMock(); $this->paymentFailures = $this->getMockBuilder(PaymentFailuresInterface::class) ->disableOriginalConstructor() ->setMethods(['handle']) ->getMock(); $this->sessionTransparent = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() ->setMethods(['getQuoteId']) ->getMock(); $this->object = new Response( $this->contextMock, $this->coreRegistryMock, $this->transactionMock, $this->responseValidatorMock, $this->resultLayoutFactoryMock, $this->payflowFacade, $this->sessionTransparent, $this->paymentFailures ); } public function testExecute() { $objectMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) ->disableOriginalConstructor() ->getMock(); $this->transactionMock->expects($this->once()) ->method('getResponseObject') ->willReturn($objectMock); $this->responseValidatorMock->expects($this->once()) ->method('validate') ->with($objectMock, $this->payflowFacade); $this->transactionMock->expects($this->once()) ->method('savePaymentInQuote') ->with($objectMock); $this->coreRegistryMock->expects($this->once()) ->method('register') ->with('transparent_form_params', $this->logicalNot($this->arrayHasKey('error'))); $this->resultLayoutMock->expects($this->once()) ->method('addDefaultHandle') ->willReturnSelf(); $this->resultLayoutMock->expects($this->once()) ->method('getLayout') ->willReturn($this->getLayoutMock()); $this->paymentFailures->expects($this->never()) ->method('handle'); $this->assertInstanceOf(\Magento\Framework\Controller\ResultInterface::class, $this->object->execute()); } public function testExecuteWithException() { $objectMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) ->disableOriginalConstructor() ->getMock(); $this->transactionMock->expects($this->once()) ->method('getResponseObject') ->willReturn($objectMock); $this->responseValidatorMock->expects($this->once()) ->method('validate') ->with($objectMock, $this->payflowFacade) ->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('Error'))); $this->coreRegistryMock->expects($this->once()) ->method('register') ->with('transparent_form_params', $this->arrayHasKey('error')); $this->resultLayoutMock->expects($this->once()) ->method('addDefaultHandle') ->willReturnSelf(); $this->resultLayoutMock->expects($this->once()) ->method('getLayout') ->willReturn($this->getLayoutMock()); $this->sessionTransparent->method('getQuoteId') ->willReturn(1); $this->paymentFailures->expects($this->once()) ->method('handle') ->with(1) ->willReturnSelf(); $this->assertInstanceOf(\Magento\Framework\Controller\ResultInterface::class, $this->object->execute()); } /** * @return \Magento\Framework\View\Layout | \PHPUnit_Framework_MockObject_MockObject */ private function getLayoutMock() { $processorInterfaceMock = $this->getMockBuilder(\Magento\Framework\View\Layout\ProcessorInterface::class) ->getMockForAbstractClass(); $layoutMock = $this->getMockBuilder(\Magento\Framework\View\Layout::class) ->setMethods(['getUpdate']) ->disableOriginalConstructor() ->getMock(); $layoutMock->expects($this->once()) ->method('getUpdate') ->willReturn($processorInterfaceMock); return $layoutMock; } }