Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ApplicationTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Test;
8 
19 
23 class ApplicationTest extends \PHPUnit\Framework\TestCase
24 {
30  private $subject;
31 
35  private $tempDir;
36 
40  protected function setUp()
41  {
43  $shell = $this->createMock(Shell::class);
45  $autoloadWrapper = $this->getMockBuilder(ClassLoaderWrapper::class)
46  ->disableOriginalConstructor()->getMock();
47  $this->tempDir = '/temp/dir';
49 
50  $this->subject = new Application(
51  $shell,
52  $this->tempDir,
53  'config.php',
54  'global-config.php',
55  '',
56  $appMode,
58  );
59  }
60 
66  public function testConstructor()
67  {
68  $this->assertEquals($this->tempDir, $this->subject->getTempDir(), 'Temp directory is not set in Application');
69 
70  $initParams = $this->subject->getInitParams();
71  $this->assertInternalType('array', $initParams, 'Wrong initialization parameters type');
72  $this->assertArrayHasKey(
74  $initParams,
75  'Directories are not configured'
76  );
77  $this->assertArrayHasKey(State::PARAM_MODE, $initParams, 'Application mode is not configured');
78  $this->assertEquals(
80  $initParams[State::PARAM_MODE],
81  'Wrong application mode configured'
82  );
83  }
84 
92  public function testPartialLoadArea(string $areaCode)
93  {
94  $configScope = $this->getMockBuilder(Scope::class)
95  ->disableOriginalConstructor()
96  ->getMock();
97  $configScope->expects($this->once())
98  ->method('setCurrentScope')
99  ->with($this->identicalTo($areaCode));
100 
101  $configLoader = $this->getMockBuilder(ConfigLoader::class)
102  ->disableOriginalConstructor()
103  ->getMock();
104  $configLoader->expects($this->once())
105  ->method('load')
106  ->with($this->identicalTo($areaCode))
107  ->willReturn([]);
108 
109  $area = $this->getMockBuilder(Area::class)
110  ->disableOriginalConstructor()
111  ->getMock();
112  $area->expects($this->once())
113  ->method('load')
114  ->with($this->identicalTo(Area::PART_CONFIG));
115 
116  $areaList = $this->getMockBuilder(AreaList::class)
117  ->disableOriginalConstructor()
118  ->getMock();
119  $areaList->expects($this->once())
120  ->method('getArea')
121  ->with($this->identicalTo($areaCode))
122  ->willReturn($area);
123 
125  $objectManager = $this->getMockBuilder(ObjectManagerInterface::class)
126  ->disableOriginalConstructor()
127  ->getMock();
128  $objectManager->expects($this->once())
129  ->method('configure')
130  ->with($this->identicalTo([]));
131  $objectManager->expects($this->exactly(3))
132  ->method('get')
133  ->willReturnOnConsecutiveCalls(
134  $configScope,
135  $configLoader,
136  $areaList
137  );
138 
140 
141  $this->subject->loadArea($areaCode);
142  }
143 
149  public function partialLoadAreaDataProvider()
150  {
151  return [
152  [
153  'area_code' => Area::AREA_GLOBAL,
154  ],
155  [
156  'area_code' => Area::AREA_WEBAPI_REST,
157  ],
158  [
159  'area_code' => Area::AREA_WEBAPI_SOAP,
160  ],
161  [
162  'area_code' => Area::AREA_CRONTAB,
163  ],
164  [
165  'area_code' => Area::AREA_GRAPHQL,
166  ],
167  ];
168  }
169 }
$objectManager
Definition: bootstrap.php:17
if(!file_exists($installConfigFile)) if(!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) $shell
Definition: bootstrap.php:46
$autoloadWrapper
Definition: autoload.php:12
static setObjectManager(\Magento\Framework\ObjectManagerInterface $objectManager)
Definition: Bootstrap.php:135