Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OnepageTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Checkout\Controller\Onepage;
9 
14 class OnepageTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $controller;
20 
24  protected $checkoutSession;
25 
29  protected $customerSession;
30 
34  protected $request;
35 
39  protected $response;
40 
44  protected $quote;
45 
49  protected $eventManager;
50 
51  protected function setUp()
52  {
53  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
54 
55  $this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
56  $this->response = $this->createMock(\Magento\Framework\App\Response\Http::class);
57  $this->quote = $this->createMock(\Magento\Quote\Model\Quote::class);
58  $this->eventManager = $this->createMock(\Magento\Framework\Event\Manager::class);
59  $this->customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
60  $this->checkoutSession = $this->createMock(\Magento\Checkout\Model\Session::class);
61  $this->checkoutSession->expects($this->once())
62  ->method('getQuote')
63  ->willReturn($this->quote);
64 
65  $objectManagerMock = $this->createMock(\Magento\Framework\ObjectManager\ObjectManager::class);
66  $objectManagerMock->expects($this->at(0))
67  ->method('get')
68  ->with(\Magento\Checkout\Model\Session::class)
69  ->willReturn($this->checkoutSession);
70  $objectManagerMock->expects($this->at(1))
71  ->method('get')
72  ->with(\Magento\Customer\Model\Session::class)
73  ->willReturn($this->customerSession);
74 
75  $context = $this->createMock(\Magento\Framework\App\Action\Context::class);
76  $context->expects($this->once())
77  ->method('getObjectManager')
78  ->willReturn($objectManagerMock);
79  $context->expects($this->once())
80  ->method('getRequest')
81  ->willReturn($this->request);
82  $context->expects($this->once())
83  ->method('getResponse')
84  ->willReturn($this->response);
85  $context->expects($this->once())
86  ->method('getEventManager')
87  ->willReturn($this->eventManager);
88 
89  $this->controller = $objectManager->getObject(
90  \Magento\Checkout\Test\Unit\Controller\Stub\OnepageStub::class,
91  [
92  'context' => $context
93  ]
94  );
95  }
96 
97  public function testDispatch()
98  {
99  $this->request->expects($this->once())
100  ->method('getActionName')
101  ->willReturn('index');
102 
103  $this->assertEquals($this->response, $this->controller->dispatch($this->request));
104  }
105 }
$objectManager
Definition: bootstrap.php:17