Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StartUpdaterTest.php
Go to the documentation of this file.
1 <?php
8 
11 
16 class StartUpdaterTest extends \PHPUnit\Framework\TestCase
17 {
21  private $controller;
22 
26  private $request;
27 
31  private $response;
32 
36  private $mvcEvent;
37 
41  private $payloadValidator;
42 
46  private $updaterTaskCreator;
47 
48  public function setUp()
49  {
50  $this->payloadValidator = $this->createMock(\Magento\Setup\Model\PayloadValidator::class);
51  $this->updaterTaskCreator = $this->createMock(\Magento\Setup\Model\UpdaterTaskCreator::class);
52 
53  $this->controller = new StartUpdater(
54  $this->updaterTaskCreator,
55  $this->payloadValidator
56  );
57  $this->request = $this->createMock(\Zend\Http\PhpEnvironment\Request::class);
58  $this->response = $this->createMock(\Zend\Http\PhpEnvironment\Response::class);
59  $routeMatch = $this->createMock(\Zend\Mvc\Router\RouteMatch::class);
60  $this->mvcEvent = $this->createMock(\Zend\Mvc\MvcEvent::class);
61  $this->mvcEvent->expects($this->any())
62  ->method('setRequest')
63  ->with($this->request)
64  ->willReturn($this->mvcEvent);
65  $this->mvcEvent->expects($this->any())
66  ->method('setResponse')
67  ->with($this->response)
68  ->willReturn($this->mvcEvent);
69  $this->mvcEvent->expects($this->any())
70  ->method('setTarget')
71  ->with($this->controller)
72  ->willReturn($this->mvcEvent);
73  $this->mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch);
74  }
75 
76  public function testIndexAction()
77  {
78  $viewModel = $this->controller->indexAction();
79  $this->assertInstanceOf(\Zend\View\Model\ViewModel::class, $viewModel);
80  $this->assertTrue($viewModel->terminate());
81  }
82 
88  public function testUpdateInvalidRequest($content, $payload)
89  {
90  $this->request->expects($this->any())->method('getContent')->willReturn($content);
91  $this->payloadValidator->expects($this->exactly($payload))->method('validatePayload');
92  $this->controller->setEvent($this->mvcEvent);
93  $this->controller->dispatch($this->request, $this->response);
94  $this->controller->updateAction();
95  }
96 
101  {
102  return [
103  'NoParmas' => ['{}', 0],
104  'NoArray' => ['{"packages":"test","type":"update"}', 0],
105  'NoVersion' => ['{"packages":[{"name":"vendor\/package"}],"type":"update"}', 1],
106  'NoDataOption' => ['{"packages":[{"name":"vendor\/package", "version": "1.0.0"}],"type":"uninstall"}', 1],
107  'NoPackageInfo' => ['{"packages":"test","type":"update"}', 0]
108  ];
109  }
110 
111  public function testUpdateActionSuccess()
112  {
113  $content = '{"packages":[{"name":"vendor\/package","version":"1.0"}],"type":"update",'
114  . '"headerTitle": "Update package 1" }';
115  $this->request->expects($this->any())->method('getContent')->willReturn($content);
116  $this->payloadValidator->expects($this->once())->method('validatePayload')->willReturn('');
117  $this->updaterTaskCreator->expects($this->once())->method('createUpdaterTasks')->willReturn('');
118  $this->controller->setEvent($this->mvcEvent);
119  $this->controller->dispatch($this->request, $this->response);
120  $this->controller->updateAction();
121  }
122 }
$viewModel