public function testExecute()
 {
     $details = $this->getDetails();
     $quoteMock = $this->getQuoteMock();
     $paymentMock = $this->getPaymentMock();
     $quoteMock->expects(self::once())->method('getPayment')->willReturn($paymentMock);
     $paymentMock->expects(self::once())->method('setMethod')->with(ConfigProvider::PAYPAL_CODE);
     $paymentMock->expects(self::once())->method('setAdditionalInformation')->with(DataAssignObserver::PAYMENT_METHOD_NONCE, self::TEST_NONCE);
     $this->updateQuoteStep($quoteMock, $details);
     $this->quoteUpdater->execute(self::TEST_NONCE, $details, $quoteMock);
 }
 /**
  * @inheritdoc
  */
 public function execute()
 {
     $requestData = json_decode($this->getRequest()->getPostValue('result', '{}'), true);
     $quote = $this->checkoutSession->getQuote();
     try {
         $this->validateQuote($quote);
         $this->validateRequestData($requestData);
         $this->quoteUpdater->execute($requestData['nonce'], $requestData['details'], $quote);
         /** @var \Magento\Framework\View\Result\Page $resultPage */
         $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
         /** @var \Magento\BraintreeTwo\Block\Paypal\Checkout\Review $reviewBlock */
         $reviewBlock = $resultPage->getLayout()->getBlock('braintreetwo.paypal.review');
         $reviewBlock->setQuote($quote);
         $reviewBlock->getChildBlock('shipping_method')->setData('quote', $quote);
         return $resultPage;
     } catch (\Exception $e) {
         $this->messageManager->addExceptionMessage($e, $e->getMessage());
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('checkout/cart', ['_secure' => true]);
 }
 public function testExecuteException()
 {
     $result = '{}';
     $quoteMock = $this->getQuoteMock();
     $resultRedirectMock = $this->getResultRedirectMock();
     $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(1);
     $this->requestMock->expects(self::once())->method('getPostValue')->with('result', '{}')->willReturn($result);
     $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock);
     $this->quoteUpdaterMock->expects(self::never())->method('execute');
     $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'Data of request cannot be empty.');
     $this->resultFactoryMock->expects(self::once())->method('create')->with(ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirectMock);
     $resultRedirectMock->expects(self::once())->method('setPath')->with('checkout/cart')->willReturnSelf();
     self::assertEquals($this->review->execute(), $resultRedirectMock);
 }