1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Asset; |
4
|
|
|
|
5
|
|
|
use Magento\Deploy\Model\Mode; |
6
|
|
|
use Magento\Framework\App\State; |
7
|
|
|
use Magento\Framework\App\View\Asset\Publisher as AssetPublisher; |
8
|
|
|
use Magento\Framework\View\Asset\Repository as AssetRepo; |
9
|
|
|
use N98\Magento\Command\TestCase as BaseTestCase; |
10
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
11
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
12
|
|
|
|
13
|
|
|
class ClearCommandTest extends BaseTestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
if ($this->runsInProductionMode()) { |
21
|
|
|
$this->markTestSkipped('This command is not available in production mode'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
parent::setUp(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
private function runsInProductionMode() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$objectManager = $this->getApplication()->getObjectManager(); |
|
|
|
|
33
|
|
|
$mode = $objectManager->create( |
34
|
|
|
Mode::class, |
35
|
|
|
[ |
36
|
|
|
'input' => new ArgvInput(), |
37
|
|
|
'output' => new ConsoleOutput(), |
38
|
|
|
] |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
return $mode->getMode() === State::MODE_PRODUCTION; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
private function deployAsset() |
48
|
|
|
{ |
49
|
|
|
$objectManager = $this->getApplication()->getObjectManager(); |
|
|
|
|
50
|
|
|
$assetRepo = $objectManager->get(AssetRepo::class); |
51
|
|
|
$assetPublisher = $objectManager->create(AssetPublisher::class); |
52
|
|
|
$asset = $assetRepo->createAsset( |
53
|
|
|
'js/block-loader.js', |
54
|
|
|
[ |
55
|
|
|
'area' => 'frontend', |
56
|
|
|
'theme' => 'Magento/blank', |
57
|
|
|
'locale' => 'en_US', |
58
|
|
|
'module' => 'Magento_Ui', |
59
|
|
|
] |
60
|
|
|
); |
61
|
|
|
$assetPublisher->publish($asset); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
public function testExecuteClearAll() |
68
|
|
|
{ |
69
|
|
|
$this->deployAsset(); |
70
|
|
|
$this->assertDisplayContains( |
71
|
|
|
[ |
72
|
|
|
'command' => 'dev:asset:clear', |
73
|
|
|
], |
74
|
|
|
'static/frontend deleted' |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function testExecuteClearTheme() |
82
|
|
|
{ |
83
|
|
|
$this->deployAsset(); |
84
|
|
|
$this->assertDisplayContains( |
85
|
|
|
[ |
86
|
|
|
'command' => 'dev:asset:clear', |
87
|
|
|
'--theme' => ['Magento/blank'], |
88
|
|
|
], |
89
|
|
|
'static/frontend/Magento/blank' |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.