55 */
66namespace Magento \Framework \View \Asset ;
77
8+ use Exception ;
89use 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 ;
1210use Magento \Deploy \Console \DeployStaticOptions as Options ;
11+ use Magento \Deploy \Service \DeployStaticContent ;
1312use 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 ;
1431
1532/**
1633 * Tests for minifier
1936 * @magentoDbIsolation enabled
2037 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2138 */
22- class MinifierTest extends \ PHPUnit \ Framework \ TestCase
39+ class MinifierTest extends TestCase
2340{
2441 /**
25- * @var \Magento\Framework\Filesystem\Directory\ WriteInterface
42+ * @var WriteInterface
2643 */
2744 private $ staticDir ;
2845
2946 /**
30- * @var \Magento\TestFramework\ ObjectManager
47+ * @var ObjectManager
3148 */
3249 protected $ objectManager ;
3350
@@ -43,17 +60,15 @@ protected function setUp(): void
4360 {
4461 parent ::setUp ();
4562 $ 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);
5065 $ 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);
5368 $ this ->origMode = $ appState ->getMode ();
5469 $ 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);
5772 $ this ->staticDir = $ filesystem ->getDirectoryWrite (DirectoryList::STATIC_VIEW );
5873 }
5974
@@ -62,8 +77,8 @@ protected function setUp(): void
6277 */
6378 protected function tearDown (): void
6479 {
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);
6782 $ appState ->setMode ($ this ->origMode );
6883 if ($ this ->staticDir ->isExist ('frontend/FrameworkViewMinifier ' )) {
6984 $ this ->staticDir ->delete ('frontend/FrameworkViewMinifier ' );
@@ -83,7 +98,7 @@ protected function tearDown(): void
8398 */
8499 public function testCSSminLibrary ()
85100 {
86- /** @var \Magento\Framework\Code\Minifier\ AdapterInterface $adapter */
101+ /** @var AdapterInterface $adapter */
87102 $ adapter = $ this ->objectManager ->get ('cssMinificationAdapter ' );
88103 $ this ->assertEquals (
89104 file_get_contents (dirname (__DIR__ ) . '/_files/static/expected/styles.magento.min.css ' ),
@@ -101,7 +116,7 @@ public function testCSSminLibrary()
101116 */
102117 public function testJshrinkLibrary ()
103118 {
104- /** @var \Magento\Framework\Code\Minifier\ AdapterInterface $adapter */
119+ /** @var AdapterInterface $adapter */
105120 $ adapter = $ this ->objectManager ->get ('jsMinificationAdapter ' );
106121 $ this ->assertEquals (
107122 file_get_contents (dirname (__DIR__ ) . '/_files/static/expected/test.min.js ' ),
@@ -117,26 +132,26 @@ public function testJshrinkLibrary()
117132 *
118133 * @param string $requestedUri
119134 * @param callable $assertionCallback
120- * @throws \Magento\Framework\Exception\ LocalizedException
135+ * @throws LocalizedException|Exception
121136 */
122- protected function _testCssMinification ( $ requestedUri , $ assertionCallback )
137+ private function checkCssMinification ( string $ requestedUri , callable $ assertionCallback ): void
123138 {
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);
126141 $ request ->setRequestUri ($ requestedUri );
127142 $ request ->setParam ('resource ' , $ requestedUri );
128143
129- $ response = $ this ->getMockBuilder (\ Magento \ Framework \ App \ Response \ FileInterface::class)
144+ $ response = $ this ->getMockBuilder (FileInterface::class)
130145 ->setMethods (['setFilePath ' ])
131146 ->getMockForAbstractClass ();
132147 $ response
133148 ->expects ($ this ->any ())
134149 ->method ('setFilePath ' )
135150 ->willReturnCallback ($ assertionCallback );
136151
137- /** @var \Magento\Framework\App\ StaticResource $staticResourceApp */
152+ /** @var StaticResource $staticResourceApp */
138153 $ staticResourceApp = $ this ->objectManager ->create (
139- \ Magento \ Framework \ App \ StaticResource::class,
154+ StaticResource::class,
140155 ['response ' => $ response ]
141156 );
142157 $ staticResourceApp ->launch ();
@@ -148,7 +163,7 @@ protected function _testCssMinification($requestedUri, $assertionCallback)
148163 */
149164 public function testCssMinificationOff ()
150165 {
151- $ this ->_testCssMinification (
166+ $ this ->checkCssMinification (
152167 '/frontend/FrameworkViewMinifier/default/en_US/css/styles.css ' ,
153168 function ($ path ) {
154169 $ content = file_get_contents ($ path );
@@ -171,7 +186,7 @@ function ($path) {
171186 */
172187 public function testCssMinification ()
173188 {
174- $ this ->_testCssMinification (
189+ $ this ->checkCssMinification (
175190 '/frontend/FrameworkViewMinifier/default/en_US/css/styles.min.css ' ,
176191 function ($ path ) {
177192 $ this ->assertEquals (
@@ -191,7 +206,7 @@ function ($path) {
191206 */
192207 public function testCssMinificationForMinifiedFiles ()
193208 {
194- $ this ->_testCssMinification (
209+ $ this ->checkCssMinification (
195210 '/frontend/FrameworkViewMinifier/default/en_US/css/preminified-styles.min.css ' ,
196211 function ($ path ) {
197212 $ content = file_get_contents ($ path );
@@ -212,12 +227,12 @@ public function testDeploymentWithMinifierEnabled()
212227 $ fileToBePublished = $ staticPath . '/frontend/FrameworkViewMinifier/default/en_US/css/styles.min.css ' ;
213228 $ fileToTestPublishing = dirname (__DIR__ ) . '/_files/static/theme/web/css/styles.css ' ;
214229
215- $ omFactory = $ this ->createPartialMock (\ Magento \ Framework \ App \ ObjectManagerFactory::class, ['create ' ]);
230+ $ omFactory = $ this ->createPartialMock (ObjectManagerFactory::class, ['create ' ]);
216231 $ omFactory ->expects ($ this ->any ())
217232 ->method ('create ' )
218233 ->willReturn ($ this ->objectManager );
219234
220- $ filesUtil = $ this ->createMock (\ Magento \ Framework \ App \ Utility \ Files::class);
235+ $ filesUtil = $ this ->createMock (Files::class);
221236 $ filesUtil ->expects ($ this ->any ())
222237 ->method ('getStaticLibraryFiles ' )
223238 ->willReturn ([]);
@@ -234,25 +249,17 @@ public function testDeploymentWithMinifierEnabled()
234249 ]
235250 );
236251
237- $ this ->objectManager ->addSharedInstance ($ filesUtil , \ Magento \ Framework \ App \ Utility \ Files::class);
252+ $ this ->objectManager ->addSharedInstance ($ filesUtil , Files::class);
238253
239- $ output = $ this ->objectManager ->create (
240- \Symfony \Component \Console \Output \ConsoleOutput::class
241- );
254+ $ output = $ this ->objectManager ->create (ConsoleOutput::class);
242255
243- $ logger = $ this ->objectManager ->create (
244- ConsoleLogger::class,
245- ['output ' => $ output ]
246- );
256+ $ logger = $ this ->objectManager ->create (ConsoleLogger::class, ['output ' => $ output ]);
247257
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 ' ]);
252259
253- /** @var \Magento\Deploy\Service\ DeployStaticContent $deployService */
260+ /** @var DeployStaticContent $deployService */
254261 $ deployService = $ this ->objectManager ->create (
255- \ Magento \ Deploy \ Service \ DeployStaticContent::class,
262+ DeployStaticContent::class,
256263 [
257264 'objectManager ' => $ this ->objectManager ,
258265 'logger ' => $ logger ,
@@ -279,7 +286,8 @@ public function testDeploymentWithMinifierEnabled()
279286 Options::EXCLUDE_LANGUAGE => ['none ' ],
280287 Options::JOBS_AMOUNT => 0 ,
281288 Options::SYMLINK_LOCALE => false ,
282- Options::STRATEGY => DeployStrategyFactory::DEPLOY_STRATEGY_QUICK
289+ Options::STRATEGY => DeployStrategyFactory::DEPLOY_STRATEGY_QUICK ,
290+ Options::NO_PARENT => false ,
283291 ]
284292 );
285293
0 commit comments