OnepageTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Test\Unit\Controller;
  7. use \Magento\Checkout\Controller\Onepage;
  8. /**
  9. * Class OnepageTest
  10. * @package Magento\Checkout\Controller
  11. */
  12. class OnepageTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var Onepage
  16. */
  17. protected $controller;
  18. /**
  19. * @var \Magento\Checkout\Model\Session | \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $checkoutSession;
  22. /**
  23. * @var \Magento\Customer\Model\Session | \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $customerSession;
  26. /**
  27. * @var \Magento\Framework\App\Request\Http | \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $request;
  30. /**
  31. * @var \Magento\Framework\App\Response\Http | \PHPUnit_Framework_MockObject_MockObject
  32. */
  33. protected $response;
  34. /**
  35. * @var \Magento\Quote\Model\Quote | \PHPUnit_Framework_MockObject_MockObject
  36. */
  37. protected $quote;
  38. /**
  39. * @var \Magento\Framework\Event\Manager | \PHPUnit_Framework_MockObject_MockObject
  40. */
  41. protected $eventManager;
  42. protected function setUp()
  43. {
  44. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  45. $this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
  46. $this->response = $this->createMock(\Magento\Framework\App\Response\Http::class);
  47. $this->quote = $this->createMock(\Magento\Quote\Model\Quote::class);
  48. $this->eventManager = $this->createMock(\Magento\Framework\Event\Manager::class);
  49. $this->customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
  50. $this->checkoutSession = $this->createMock(\Magento\Checkout\Model\Session::class);
  51. $this->checkoutSession->expects($this->once())
  52. ->method('getQuote')
  53. ->willReturn($this->quote);
  54. $objectManagerMock = $this->createMock(\Magento\Framework\ObjectManager\ObjectManager::class);
  55. $objectManagerMock->expects($this->at(0))
  56. ->method('get')
  57. ->with(\Magento\Checkout\Model\Session::class)
  58. ->willReturn($this->checkoutSession);
  59. $objectManagerMock->expects($this->at(1))
  60. ->method('get')
  61. ->with(\Magento\Customer\Model\Session::class)
  62. ->willReturn($this->customerSession);
  63. $context = $this->createMock(\Magento\Framework\App\Action\Context::class);
  64. $context->expects($this->once())
  65. ->method('getObjectManager')
  66. ->willReturn($objectManagerMock);
  67. $context->expects($this->once())
  68. ->method('getRequest')
  69. ->willReturn($this->request);
  70. $context->expects($this->once())
  71. ->method('getResponse')
  72. ->willReturn($this->response);
  73. $context->expects($this->once())
  74. ->method('getEventManager')
  75. ->willReturn($this->eventManager);
  76. $this->controller = $objectManager->getObject(
  77. \Magento\Checkout\Test\Unit\Controller\Stub\OnepageStub::class,
  78. [
  79. 'context' => $context
  80. ]
  81. );
  82. }
  83. public function testDispatch()
  84. {
  85. $this->request->expects($this->once())
  86. ->method('getActionName')
  87. ->willReturn('index');
  88. $this->assertEquals($this->response, $this->controller->dispatch($this->request));
  89. }
  90. }