Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
SelectVersionTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Setup\Controller\SelectVersion;
10 use \Magento\Setup\Controller\ResponseTypeInterface;
11 
12 class SelectVersionTest extends \PHPUnit\Framework\TestCase
13 {
17  private $systemPackage;
18 
24  private $controller;
25 
26  public function setUp()
27  {
28  $this->systemPackage = $this->createMock(\Magento\Setup\Model\SystemPackage::class);
29  $this->controller = new SelectVersion(
30  $this->systemPackage
31  );
32  }
33 
34  public function testIndexAction()
35  {
36  $viewModel = $this->controller->indexAction();
37  $this->assertInstanceOf(\Zend\View\Model\ViewModel::class, $viewModel);
38  $this->assertTrue($viewModel->terminate());
39  }
40 
41  public function testSystemPackageAction()
42  {
43  $this->systemPackage->expects($this->once())
44  ->method('getPackageVersions')
45  ->willReturn([
46  'package' => 'magento/product-community-edition',
47  'versions' => [
48  'id' => 'magento/product-community-edition',
49  'name' => 'Version 1.0.0'
50  ]
51  ]);
52  $jsonModel = $this->controller->systemPackageAction();
53  $this->assertInstanceOf(\Zend\View\Model\JsonModel::class, $jsonModel);
54  $variables = $jsonModel->getVariables();
55  $this->assertArrayHasKey('responseType', $variables);
56  $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_SUCCESS, $variables['responseType']);
57  }
58 
60  {
61  $this->systemPackage->expects($this->once())
62  ->method('getPackageVersions')
63  ->will($this->throwException(new \Exception("Test error message")));
64  $jsonModel = $this->controller->systemPackageAction();
65  $this->assertInstanceOf(\Zend\View\Model\JsonModel::class, $jsonModel);
66  $variables = $jsonModel->getVariables();
67  $this->assertArrayHasKey('responseType', $variables);
68  $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_ERROR, $variables['responseType']);
69  }
70 
72  {
73  $this->systemPackage->expects($this->once())
74  ->method('getInstalledSystemPackages')
75  ->willReturn([
76  'package' => 'magento/product-community-edition',
77  'versions' => [
78  'id' => 'magento/product-community-edition',
79  'name' => 'Version 1.0.0'
80  ]
81  ]);
82  $jsonModel = $this->controller->installedSystemPackageAction();
83  $this->assertInstanceOf(\Zend\View\Model\JsonModel::class, $jsonModel);
84  $variables = $jsonModel->getVariables();
85  $this->assertArrayHasKey('responseType', $variables);
86  $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_SUCCESS, $variables['responseType']);
87  }
88 
90  {
91  $this->systemPackage->expects($this->once())
92  ->method('getInstalledSystemPackages')
93  ->will($this->throwException(new \Exception("Test error message")));
94  $jsonModel = $this->controller->installedSystemPackageAction();
95  $variables = $jsonModel->getVariables();
96  $this->assertArrayHasKey('responseType', $variables);
97  $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_ERROR, $variables['responseType']);
98  }
99 }
$viewModel