3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Test ;
7
8
9
+ use Magento \Framework \App \Area ;
10
+ use Magento \Framework \App \AreaList ;
8
11
use Magento \Framework \App \Bootstrap ;
12
+ use Magento \Framework \App \ObjectManager \ConfigLoader ;
9
13
use Magento \Framework \App \State ;
14
+ use Magento \Framework \Autoload \ClassLoaderWrapper ;
15
+ use Magento \Framework \Config \Scope ;
16
+ use Magento \Framework \ObjectManagerInterface ;
17
+ use Magento \Framework \Shell ;
18
+ use Magento \TestFramework \Application ;
10
19
20
+ /**
21
+ * Provide tests for \Magento\TestFramework\Application.
22
+ */
11
23
class ApplicationTest extends \PHPUnit \Framework \TestCase
12
24
{
13
25
/**
14
- * @covers \Magento\TestFramework\Application::getTempDir
15
- * @covers \Magento\TestFramework\Application::getDbInstance()
16
- * @covers \Magento\TestFramework\ Application::getInitParams()
26
+ * Test subject.
27
+ *
28
+ * @var Application
17
29
*/
18
- public function testConstructor ()
30
+ private $ subject ;
31
+
32
+ /**
33
+ * @var string
34
+ */
35
+ private $ tempDir ;
36
+
37
+ /**
38
+ * @inheritdoc
39
+ */
40
+ protected function setUp ()
19
41
{
20
- $ shell = $ this ->createMock (\Magento \Framework \Shell::class);
21
- $ autoloadWrapper = $ this ->getMockBuilder (\Magento \Framework \Autoload \ClassLoaderWrapper::class)
42
+ /** @var Shell|\PHPUnit_Framework_MockObject_MockObject $shell */
43
+ $ shell = $ this ->createMock (Shell::class);
44
+ /** @var ClassLoaderWrapper|\PHPUnit_Framework_MockObject_MockObject $autoloadWrapper */
45
+ $ autoloadWrapper = $ this ->getMockBuilder (ClassLoaderWrapper::class)
22
46
->disableOriginalConstructor ()->getMock ();
23
- $ tempDir = '/temp/dir ' ;
47
+ $ this -> tempDir = '/temp/dir ' ;
24
48
$ appMode = \Magento \Framework \App \State::MODE_DEVELOPER ;
25
49
26
- $ object = new \ Magento \ TestFramework \ Application (
50
+ $ this -> subject = new Application (
27
51
$ shell ,
28
- $ tempDir ,
52
+ $ this -> tempDir ,
29
53
'config.php ' ,
30
54
'global-config.php ' ,
31
55
'' ,
32
56
$ appMode ,
33
57
$ autoloadWrapper
34
58
);
59
+ }
35
60
36
- $ this ->assertEquals ($ tempDir , $ object ->getTempDir (), 'Temp directory is not set in Application ' );
61
+ /**
62
+ * @covers \Magento\TestFramework\Application::getTempDir
63
+ * @covers \Magento\TestFramework\Application::getDbInstance()
64
+ * @covers \Magento\TestFramework\Application::getInitParams()
65
+ */
66
+ public function testConstructor ()
67
+ {
68
+ $ this ->assertEquals ($ this ->tempDir , $ this ->subject ->getTempDir (), 'Temp directory is not set in Application ' );
37
69
38
- $ initParams = $ object ->getInitParams ();
70
+ $ initParams = $ this -> subject ->getInitParams ();
39
71
$ this ->assertInternalType ('array ' , $ initParams , 'Wrong initialization parameters type ' );
40
72
$ this ->assertArrayHasKey (
41
73
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS ,
@@ -49,4 +81,85 @@ public function testConstructor()
49
81
'Wrong application mode configured '
50
82
);
51
83
}
84
+
85
+ /**
86
+ * Test \Magento\TestFramework\Application will correctly load specified areas.
87
+ *
88
+ * @dataProvider partialLoadAreaDataProvider
89
+ * @param string $areaCode
90
+ */
91
+ public function testPartialLoadArea (string $ areaCode )
92
+ {
93
+ $ configScope = $ this ->getMockBuilder (Scope::class)
94
+ ->disableOriginalConstructor ()
95
+ ->getMock ();
96
+ $ configScope ->expects ($ this ->once ())
97
+ ->method ('setCurrentScope ' )
98
+ ->with ($ this ->identicalTo ($ areaCode ));
99
+
100
+ $ configLoader = $ this ->getMockBuilder (ConfigLoader::class)
101
+ ->disableOriginalConstructor ()
102
+ ->getMock ();
103
+ $ configLoader ->expects ($ this ->once ())
104
+ ->method ('load ' )
105
+ ->with ($ this ->identicalTo ($ areaCode ))
106
+ ->willReturn ([]);
107
+
108
+ $ area = $ this ->getMockBuilder (Area::class)
109
+ ->disableOriginalConstructor ()
110
+ ->getMock ();
111
+ $ area ->expects ($ this ->once ())
112
+ ->method ('load ' )
113
+ ->with ($ this ->identicalTo (Area::PART_CONFIG ));
114
+
115
+ $ areaList = $ this ->getMockBuilder (AreaList::class)
116
+ ->disableOriginalConstructor ()
117
+ ->getMock ();
118
+ $ areaList ->expects ($ this ->once ())
119
+ ->method ('getArea ' )
120
+ ->with ($ this ->identicalTo ($ areaCode ))
121
+ ->willReturn ($ area );
122
+
123
+ /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
124
+ $ objectManager = $ this ->getMockBuilder (ObjectManagerInterface::class)
125
+ ->disableOriginalConstructor ()
126
+ ->getMock ();
127
+ $ objectManager ->expects ($ this ->once ())
128
+ ->method ('configure ' )
129
+ ->with ($ this ->identicalTo ([]));
130
+ $ objectManager ->expects ($ this ->exactly (3 ))
131
+ ->method ('get ' )
132
+ ->willReturnOnConsecutiveCalls (
133
+ $ configScope ,
134
+ $ configLoader ,
135
+ $ areaList
136
+ );
137
+
138
+ \Magento \TestFramework \Helper \Bootstrap::setObjectManager ($ objectManager );
139
+
140
+ $ this ->subject ->loadArea ($ areaCode );
141
+ }
142
+
143
+ /**
144
+ * Provide test data for testPartialLoadArea().
145
+ *
146
+ * @return array
147
+ */
148
+ public function partialLoadAreaDataProvider ()
149
+ {
150
+ return [
151
+ [
152
+ 'area_code ' => Area::AREA_GLOBAL ,
153
+ ],
154
+ [
155
+ 'area_code ' => Area::AREA_WEBAPI_REST ,
156
+ ],
157
+ [
158
+ 'area_code ' => Area::AREA_WEBAPI_SOAP ,
159
+ ],
160
+ [
161
+ 'area_code ' => Area::AREA_CRONTAB ,
162
+ ],
163
+ ];
164
+ }
52
165
}
0 commit comments