/** * Run test execute method * * @param array $result * @param array $resultExpectation * * @dataProvider executeDataProvider */ public function testExecute(array $result, array $resultExpectation) { $quoteId = 99; $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock(); $tokenMock = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getData', 'getSecuretoken'])->disableOriginalConstructor()->getMock(); $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent'); $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock); $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId); $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId); $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willReturn($tokenMock); $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent'); $tokenMock->expects($this->once())->method('getData')->willReturn($result['transparent']['fields']); $tokenMock->expects($this->once())->method('getSecuretoken')->willReturn($result['success']); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock); $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf(); $this->assertEquals($jsonMock, $this->controller->execute()); }
public function testExecuteTokenRequestException() { $quoteId = 99; $resultExpectation = ['success' => false, 'error' => true, 'error_messages' => __('Your payment has been declined. Please try again.')]; $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock(); $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock); $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId); $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId); $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willThrowException(new \Exception()); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock); $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf(); $this->assertEquals($jsonMock, $this->controller->execute()); }