ExpressTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Test\Unit\Controller;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. /**
  9. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  10. */
  11. abstract class ExpressTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /** @var Express */
  14. protected $model;
  15. protected $name = '';
  16. /** @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $customerSession;
  18. /** @var \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
  19. protected $checkoutSession;
  20. /** @var \Magento\Paypal\Model\Express\Checkout\Factory|\PHPUnit_Framework_MockObject_MockObject */
  21. protected $checkoutFactory;
  22. /** @var \Magento\Framework\Session\Generic|\PHPUnit_Framework_MockObject_MockObject */
  23. protected $session;
  24. /** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject */
  25. protected $quote;
  26. /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject */
  27. protected $customerData;
  28. /** @var \Magento\Paypal\Model\Express\Checkout|\PHPUnit_Framework_MockObject_MockObject */
  29. protected $checkout;
  30. /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
  31. protected $request;
  32. /** @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject */
  33. protected $redirect;
  34. /** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */
  35. protected $response;
  36. /** @var \Magento\Paypal\Model\Config|\PHPUnit_Framework_MockObject_MockObject */
  37. protected $config;
  38. /** @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  39. protected $messageManager;
  40. /** @var \Closure */
  41. protected $objectManagerCallback;
  42. protected function setUp()
  43. {
  44. $this->markTestIncomplete();
  45. $this->messageManager = $this->getMockForAbstractClass(\Magento\Framework\Message\ManagerInterface::class);
  46. $this->config = $this->createMock(\Magento\Paypal\Model\Config::class);
  47. $this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
  48. $this->quote = $this->createMock(\Magento\Quote\Model\Quote::class);
  49. $this->quote->expects($this->any())
  50. ->method('hasItems')
  51. ->will($this->returnValue(true));
  52. $this->redirect = $this->getMockForAbstractClass(\Magento\Framework\App\Response\RedirectInterface::class);
  53. $this->response = $this->createMock(\Magento\Framework\App\Response\Http::class);
  54. $this->customerData = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
  55. $this->checkout = $this->createMock(\Magento\Paypal\Model\Express\Checkout::class);
  56. $this->customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
  57. $this->customerSession->expects($this->any())
  58. ->method('getCustomerDataObject')
  59. ->will($this->returnValue($this->customerData));
  60. $this->checkoutSession = $this->createMock(\Magento\Checkout\Model\Session::class);
  61. $this->checkoutFactory = $this->createMock(\Magento\Paypal\Model\Express\Checkout\Factory::class);
  62. $this->checkoutFactory->expects($this->any())
  63. ->method('create')
  64. ->will($this->returnValue($this->checkout));
  65. $this->checkoutSession->expects($this->any())
  66. ->method('getQuote')
  67. ->will($this->returnValue($this->quote));
  68. $this->session = $this->createMock(\Magento\Framework\Session\Generic::class);
  69. $objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  70. $this->objectManagerCallback = function ($className) {
  71. if ($className == \Magento\Paypal\Model\Config::class) {
  72. return $this->config;
  73. }
  74. return $this->createMock($className);
  75. };
  76. $objectManager->expects($this->any())
  77. ->method('get')
  78. ->will($this->returnCallback(function ($className) {
  79. return call_user_func($this->objectManagerCallback, $className);
  80. }));
  81. $objectManager->expects($this->any())
  82. ->method('create')
  83. ->will($this->returnCallback(function ($className) {
  84. return call_user_func($this->objectManagerCallback, $className);
  85. }));
  86. $helper = new ObjectManagerHelper($this);
  87. $this->model = $helper->getObject(
  88. '\\Magento\\Paypal\\Controller\\Express\\' . $this->name,
  89. [
  90. 'messageManager' => $this->messageManager,
  91. 'response' => $this->response,
  92. 'redirect' => $this->redirect,
  93. 'request' => $this->request,
  94. 'customerSession' => $this->customerSession,
  95. 'checkoutSession' => $this->checkoutSession,
  96. 'checkoutFactory' => $this->checkoutFactory,
  97. 'paypalSession' => $this->session,
  98. 'objectManager' => $objectManager,
  99. ]
  100. );
  101. }
  102. }