5
5
*/
6
6
namespace Magento \Framework \View \Asset ;
7
7
8
+ use Exception ;
8
9
use Magento \Deploy \Console \ConsoleLogger ;
9
- use Magento \Framework \App \Filesystem \DirectoryList ;
10
- use Magento \TestFramework \Helper \Bootstrap ;
11
- use Magento \Framework \App \State as AppState ;
12
10
use Magento \Deploy \Console \DeployStaticOptions as Options ;
11
+ use Magento \Deploy \Service \DeployStaticContent ;
13
12
use Magento \Deploy \Strategy \DeployStrategyFactory ;
13
+ use Magento \Framework \App \Filesystem \DirectoryList ;
14
+ use Magento \Framework \App \ObjectManagerFactory ;
15
+ use Magento \Framework \App \Request \Http ;
16
+ use Magento \Framework \App \Response \FileInterface ;
17
+ use Magento \Framework \App \State as AppState ;
18
+ use Magento \Framework \App \StaticResource ;
19
+ use Magento \Framework \App \Utility \Files ;
20
+ use Magento \Framework \App \View \Deployment \Version \StorageInterface ;
21
+ use Magento \Framework \Code \Minifier \AdapterInterface ;
22
+ use Magento \Framework \Exception \LocalizedException ;
23
+ use Magento \Framework \Filesystem ;
24
+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
25
+ use Magento \TestFramework \App \State ;
26
+ use Magento \TestFramework \Helper \Bootstrap ;
27
+ use Magento \TestFramework \ObjectManager ;
28
+ use Magento \Theme \Model \Theme \Registration ;
29
+ use PHPUnit \Framework \TestCase ;
30
+ use Symfony \Component \Console \Output \ConsoleOutput ;
14
31
15
32
/**
16
33
* Tests for minifier
19
36
* @magentoDbIsolation enabled
20
37
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21
38
*/
22
- class MinifierTest extends \ PHPUnit \ Framework \ TestCase
39
+ class MinifierTest extends TestCase
23
40
{
24
41
/**
25
- * @var \Magento\Framework\Filesystem\Directory\ WriteInterface
42
+ * @var WriteInterface
26
43
*/
27
44
private $ staticDir ;
28
45
29
46
/**
30
- * @var \Magento\TestFramework\ ObjectManager
47
+ * @var ObjectManager
31
48
*/
32
49
protected $ objectManager ;
33
50
@@ -43,17 +60,15 @@ protected function setUp(): void
43
60
{
44
61
parent ::setUp ();
45
62
$ this ->objectManager = Bootstrap::getInstance ()->getObjectManager ();
46
- /** @var \Magento\Theme\Model\Theme\Registration $registration */
47
- $ registration = $ this ->objectManager ->get (
48
- \Magento \Theme \Model \Theme \Registration::class
49
- );
63
+ /** @var Registration $registration */
64
+ $ registration = $ this ->objectManager ->get (Registration::class);
50
65
$ registration ->register ();
51
- /** @var \Magento\TestFramework\App\ State $appState */
52
- $ appState = $ this ->objectManager ->get (\ Magento \ TestFramework \ App \ State::class);
66
+ /** @var State $appState */
67
+ $ appState = $ this ->objectManager ->get (State::class);
53
68
$ this ->origMode = $ appState ->getMode ();
54
69
$ appState ->setMode (AppState::MODE_DEFAULT );
55
- /** @var \Magento\Framework\ Filesystem $filesystem */
56
- $ filesystem = Bootstrap::getObjectManager ()->get (\ Magento \ Framework \ Filesystem::class);
70
+ /** @var Filesystem $filesystem */
71
+ $ filesystem = Bootstrap::getObjectManager ()->get (Filesystem::class);
57
72
$ this ->staticDir = $ filesystem ->getDirectoryWrite (DirectoryList::STATIC_VIEW );
58
73
}
59
74
@@ -62,8 +77,8 @@ protected function setUp(): void
62
77
*/
63
78
protected function tearDown (): void
64
79
{
65
- /** @var \Magento\TestFramework\App\ State $appState */
66
- $ appState = $ this ->objectManager ->get (\ Magento \ TestFramework \ App \ State::class);
80
+ /** @var State $appState */
81
+ $ appState = $ this ->objectManager ->get (State::class);
67
82
$ appState ->setMode ($ this ->origMode );
68
83
if ($ this ->staticDir ->isExist ('frontend/FrameworkViewMinifier ' )) {
69
84
$ this ->staticDir ->delete ('frontend/FrameworkViewMinifier ' );
@@ -83,7 +98,7 @@ protected function tearDown(): void
83
98
*/
84
99
public function testCSSminLibrary ()
85
100
{
86
- /** @var \Magento\Framework\Code\Minifier\ AdapterInterface $adapter */
101
+ /** @var AdapterInterface $adapter */
87
102
$ adapter = $ this ->objectManager ->get ('cssMinificationAdapter ' );
88
103
$ this ->assertEquals (
89
104
file_get_contents (dirname (__DIR__ ) . '/_files/static/expected/styles.magento.min.css ' ),
@@ -101,7 +116,7 @@ public function testCSSminLibrary()
101
116
*/
102
117
public function testJshrinkLibrary ()
103
118
{
104
- /** @var \Magento\Framework\Code\Minifier\ AdapterInterface $adapter */
119
+ /** @var AdapterInterface $adapter */
105
120
$ adapter = $ this ->objectManager ->get ('jsMinificationAdapter ' );
106
121
$ this ->assertEquals (
107
122
file_get_contents (dirname (__DIR__ ) . '/_files/static/expected/test.min.js ' ),
@@ -117,26 +132,26 @@ public function testJshrinkLibrary()
117
132
*
118
133
* @param string $requestedUri
119
134
* @param callable $assertionCallback
120
- * @throws \Magento\Framework\Exception\ LocalizedException
135
+ * @throws LocalizedException|Exception
121
136
*/
122
- protected function _testCssMinification ( $ requestedUri , $ assertionCallback )
137
+ private function checkCssMinification ( string $ requestedUri , callable $ assertionCallback ): void
123
138
{
124
- /** @var \Magento\Framework\App\Request\ Http $request */
125
- $ request = $ this ->objectManager ->get (\ Magento \ Framework \ App \ Request \ Http::class);
139
+ /** @var Http $request */
140
+ $ request = $ this ->objectManager ->get (Http::class);
126
141
$ request ->setRequestUri ($ requestedUri );
127
142
$ request ->setParam ('resource ' , $ requestedUri );
128
143
129
- $ response = $ this ->getMockBuilder (\ Magento \ Framework \ App \ Response \ FileInterface::class)
144
+ $ response = $ this ->getMockBuilder (FileInterface::class)
130
145
->setMethods (['setFilePath ' ])
131
146
->getMockForAbstractClass ();
132
147
$ response
133
148
->expects ($ this ->any ())
134
149
->method ('setFilePath ' )
135
150
->willReturnCallback ($ assertionCallback );
136
151
137
- /** @var \Magento\Framework\App\ StaticResource $staticResourceApp */
152
+ /** @var StaticResource $staticResourceApp */
138
153
$ staticResourceApp = $ this ->objectManager ->create (
139
- \ Magento \ Framework \ App \ StaticResource::class,
154
+ StaticResource::class,
140
155
['response ' => $ response ]
141
156
);
142
157
$ staticResourceApp ->launch ();
@@ -148,7 +163,7 @@ protected function _testCssMinification($requestedUri, $assertionCallback)
148
163
*/
149
164
public function testCssMinificationOff ()
150
165
{
151
- $ this ->_testCssMinification (
166
+ $ this ->checkCssMinification (
152
167
'/frontend/FrameworkViewMinifier/default/en_US/css/styles.css ' ,
153
168
function ($ path ) {
154
169
$ content = file_get_contents ($ path );
@@ -171,7 +186,7 @@ function ($path) {
171
186
*/
172
187
public function testCssMinification ()
173
188
{
174
- $ this ->_testCssMinification (
189
+ $ this ->checkCssMinification (
175
190
'/frontend/FrameworkViewMinifier/default/en_US/css/styles.min.css ' ,
176
191
function ($ path ) {
177
192
$ this ->assertEquals (
@@ -191,7 +206,7 @@ function ($path) {
191
206
*/
192
207
public function testCssMinificationForMinifiedFiles ()
193
208
{
194
- $ this ->_testCssMinification (
209
+ $ this ->checkCssMinification (
195
210
'/frontend/FrameworkViewMinifier/default/en_US/css/preminified-styles.min.css ' ,
196
211
function ($ path ) {
197
212
$ content = file_get_contents ($ path );
@@ -212,12 +227,12 @@ public function testDeploymentWithMinifierEnabled()
212
227
$ fileToBePublished = $ staticPath . '/frontend/FrameworkViewMinifier/default/en_US/css/styles.min.css ' ;
213
228
$ fileToTestPublishing = dirname (__DIR__ ) . '/_files/static/theme/web/css/styles.css ' ;
214
229
215
- $ omFactory = $ this ->createPartialMock (\ Magento \ Framework \ App \ ObjectManagerFactory::class, ['create ' ]);
230
+ $ omFactory = $ this ->createPartialMock (ObjectManagerFactory::class, ['create ' ]);
216
231
$ omFactory ->expects ($ this ->any ())
217
232
->method ('create ' )
218
233
->willReturn ($ this ->objectManager );
219
234
220
- $ filesUtil = $ this ->createMock (\ Magento \ Framework \ App \ Utility \ Files::class);
235
+ $ filesUtil = $ this ->createMock (Files::class);
221
236
$ filesUtil ->expects ($ this ->any ())
222
237
->method ('getStaticLibraryFiles ' )
223
238
->willReturn ([]);
@@ -234,25 +249,17 @@ public function testDeploymentWithMinifierEnabled()
234
249
]
235
250
);
236
251
237
- $ this ->objectManager ->addSharedInstance ($ filesUtil , \ Magento \ Framework \ App \ Utility \ Files::class);
252
+ $ this ->objectManager ->addSharedInstance ($ filesUtil , Files::class);
238
253
239
- $ output = $ this ->objectManager ->create (
240
- \Symfony \Component \Console \Output \ConsoleOutput::class
241
- );
254
+ $ output = $ this ->objectManager ->create (ConsoleOutput::class);
242
255
243
- $ logger = $ this ->objectManager ->create (
244
- ConsoleLogger::class,
245
- ['output ' => $ output ]
246
- );
256
+ $ logger = $ this ->objectManager ->create (ConsoleLogger::class, ['output ' => $ output ]);
247
257
248
- $ versionStorage = $ this ->createPartialMock (
249
- \Magento \Framework \App \View \Deployment \Version \StorageInterface::class,
250
- ['save ' , 'load ' ]
251
- );
258
+ $ versionStorage = $ this ->createPartialMock (StorageInterface::class, ['save ' , 'load ' ]);
252
259
253
- /** @var \Magento\Deploy\Service\ DeployStaticContent $deployService */
260
+ /** @var DeployStaticContent $deployService */
254
261
$ deployService = $ this ->objectManager ->create (
255
- \ Magento \ Deploy \ Service \ DeployStaticContent::class,
262
+ DeployStaticContent::class,
256
263
[
257
264
'objectManager ' => $ this ->objectManager ,
258
265
'logger ' => $ logger ,
@@ -279,7 +286,8 @@ public function testDeploymentWithMinifierEnabled()
279
286
Options::EXCLUDE_LANGUAGE => ['none ' ],
280
287
Options::JOBS_AMOUNT => 0 ,
281
288
Options::SYMLINK_LOCALE => false ,
282
- Options::STRATEGY => DeployStrategyFactory::DEPLOY_STRATEGY_QUICK
289
+ Options::STRATEGY => DeployStrategyFactory::DEPLOY_STRATEGY_QUICK ,
290
+ Options::NO_PARENT => false ,
283
291
]
284
292
);
285
293
0 commit comments