Skip to content

Commit dccd4cf

Browse files
committed
MAGECLOUD-1057: Add possibility to change SCD strategy
1 parent 9c3d58d commit dccd4cf

File tree

5 files changed

+192
-27
lines changed

5 files changed

+192
-27
lines changed

src/Magento/MagentoCloud/StaticContent/Build/Option.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\MagentoCloud\Util\ArrayManager;
1313
use Magento\MagentoCloud\Config\Build as BuildConfig;
1414

15+
/**
16+
* Options for static deploy command in deploy process
17+
*/
1518
class Option implements OptionInterface
1619
{
1720
/**
@@ -95,15 +98,7 @@ public function isForce(): bool
9598
}
9699

97100
/**
98-
* Collects locales for static content deployment
99-
*
100-
* @return array List of locales.
101-
* ```php
102-
* [
103-
* 'en_US',
104-
* 'fr_FR'
105-
* ]
106-
* ```
101+
* @inheritdoc
107102
*/
108103
public function getLocales(): array
109104
{

src/Magento/MagentoCloud/StaticContent/Command.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,14 @@
55
*/
66
namespace Magento\MagentoCloud\StaticContent;
77

8-
use Magento\MagentoCloud\Config\Environment;
9-
8+
/**
9+
* Creates static deploy command
10+
*/
1011
class Command
1112
{
1213
/**
13-
* @var Environment
14-
*/
15-
private $environment;
16-
17-
/**
18-
* @param Environment $environment
19-
*/
20-
public function __construct(Environment $environment)
21-
{
22-
$this->environment = $environment;
23-
}
24-
25-
/**
14+
* Creates static deploy command based on given options
15+
*
2616
* @param OptionInterface $option
2717
* @return string
2818
*/
@@ -56,7 +46,7 @@ public function createParallel(OptionInterface $option): string
5646

5747
$parallelCommands = '';
5848
foreach ($option->getLocales() as $locale) {
59-
$parallelCommands .= $command . ' ' . $locale . "\n";
49+
$parallelCommands .= $command . ' ' . $locale . PHP_EOL;
6050
}
6151

6252
return $parallelCommands;
@@ -86,9 +76,9 @@ private function createBaseCommand(OptionInterface $option): string
8676
$command .= ' -s ' . $strategy;
8777
}
8878

89-
$verbosityLevel = $this->environment->getVerbosityLevel();
79+
$verbosityLevel = $option->getVerbosityLevel();
9080
if ($verbosityLevel) {
91-
$command .= $verbosityLevel;
81+
$command .= ' ' . $verbosityLevel;
9282
}
9383

9484
return $command;

src/Magento/MagentoCloud/StaticContent/Deploy/Option.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\MagentoCloud\Package\MagentoVersion;
1111
use Magento\MagentoCloud\StaticContent\OptionInterface;
1212

13+
/**
14+
* Options for static deploy command in build process
15+
*/
1316
class Option implements OptionInterface
1417
{
1518
/**

src/Magento/MagentoCloud/StaticContent/OptionInterface.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,41 @@
77

88
interface OptionInterface
99
{
10+
/**
11+
* @return int
12+
*/
1013
public function getTreadCount(): int;
14+
15+
/**
16+
* @return array
17+
*/
1118
public function getExcludedThemes(): array;
19+
20+
/**
21+
* @return string
22+
*/
1223
public function getStrategy(): string;
24+
25+
/**
26+
* Collects locales for static content deployment
27+
*
28+
* @return array List of locales.
29+
* ```php
30+
* [
31+
* 'en_US',
32+
* 'fr_FR'
33+
* ]
34+
* ```
35+
*/
1336
public function getLocales(): array;
37+
38+
/**
39+
* @return bool
40+
*/
1441
public function isForce(): bool;
42+
43+
/**
44+
* @return string
45+
*/
1546
public function getVerbosityLevel(): string;
1647
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Test\Unit\StaticContent;
7+
8+
use Magento\MagentoCloud\StaticContent\Command;
9+
use Magento\MagentoCloud\StaticContent\OptionInterface;
10+
use PHPUnit\Framework\TestCase;
11+
use PHPUnit_Framework_MockObject_MockObject as Mock;
12+
13+
class CommandTest extends TestCase
14+
{
15+
/**
16+
* @var Command
17+
*/
18+
private $command;
19+
20+
public function setUp()
21+
{
22+
$this->command = new Command();
23+
}
24+
25+
/**
26+
* @param array $optionConfig
27+
* @param $expected
28+
* @dataProvider createDataProvider
29+
*/
30+
public function testCreate(array $optionConfig, $expected)
31+
{
32+
$this->assertEquals(
33+
$expected,
34+
$this->command->create($this->createOption($optionConfig))
35+
);
36+
}
37+
38+
/**
39+
* @param array $optionConfig
40+
* @param $expected
41+
* @dataProvider createParallelDataProvider
42+
*/
43+
public function testCreateParallel(array $optionConfig, $expected)
44+
{
45+
$this->assertEquals(
46+
$expected,
47+
$this->command->createParallel($this->createOption($optionConfig))
48+
);
49+
}
50+
51+
/**
52+
* @return array
53+
*/
54+
public function createDataProvider()
55+
{
56+
return [
57+
[
58+
[
59+
'thread_count' => 3,
60+
'excluded_themes' => ['theme1', 'theme2'],
61+
'strategy' => 'quick',
62+
'locales' => ['en_US'],
63+
'is_force' => true,
64+
'verbosity_level' => '-v',
65+
],
66+
'php ./bin/magento setup:static-content:deploy -f --exclude-theme=theme1 --exclude-theme=theme2 -s ' .
67+
'quick -v en_US --jobs=3'
68+
],
69+
[
70+
[
71+
'thread_count' => 1,
72+
'excluded_themes' => ['theme1'],
73+
'strategy' => 'quick',
74+
'locales' => ['en_US', 'de_DE'],
75+
'is_force' => false,
76+
'verbosity_level' => '-v',
77+
],
78+
'php ./bin/magento setup:static-content:deploy --exclude-theme=theme1 -s quick -v en_US de_DE --jobs=1'
79+
],
80+
];
81+
}
82+
83+
/**
84+
* @return array
85+
*/
86+
public function createParallelDataProvider()
87+
{
88+
return [
89+
[
90+
[
91+
'excluded_themes' => ['theme1'],
92+
'strategy' => 'quick',
93+
'locales' => ['en_US', 'fr_FR', 'de_DE'],
94+
'is_force' => true,
95+
'verbosity_level' => '-v',
96+
],
97+
'php ./bin/magento setup:static-content:deploy -f --exclude-theme=theme1 -s quick -v en_US' . PHP_EOL .
98+
'php ./bin/magento setup:static-content:deploy -f --exclude-theme=theme1 -s quick -v fr_FR' . PHP_EOL .
99+
'php ./bin/magento setup:static-content:deploy -f --exclude-theme=theme1 -s quick -v de_DE' . PHP_EOL
100+
],
101+
[
102+
[
103+
'excluded_themes' => ['theme1'],
104+
'strategy' => 'quick',
105+
'locales' => ['en_US'],
106+
'is_force' => false,
107+
'verbosity_level' => '-v',
108+
],
109+
'php ./bin/magento setup:static-content:deploy --exclude-theme=theme1 -s quick -v en_US' . PHP_EOL
110+
],
111+
];
112+
}
113+
114+
/**
115+
* @param array $optionConfig
116+
* @return Mock|OptionInterface
117+
*/
118+
private function createOption(array $optionConfig)
119+
{
120+
$optionMock = $this->getMockBuilder(OptionInterface::class)
121+
->getMockForAbstractClass();
122+
123+
if (isset($optionConfig['thread_count'])) {
124+
$optionMock->expects($this->once())
125+
->method('getTreadCount')
126+
->willReturn($optionConfig['thread_count']);
127+
}
128+
$optionMock->expects($this->once())
129+
->method('getExcludedThemes')
130+
->willReturn($optionConfig['excluded_themes']);
131+
$optionMock->expects($this->once())
132+
->method('getStrategy')
133+
->willReturn($optionConfig['strategy']);
134+
$optionMock->expects($this->once())
135+
->method('getLocales')
136+
->willReturn($optionConfig['locales']);
137+
$optionMock->expects($this->once())
138+
->method('isForce')
139+
->willReturn($optionConfig['is_force']);
140+
$optionMock->expects($this->once())
141+
->method('getVerbosityLevel')
142+
->willReturn($optionConfig['verbosity_level']);
143+
144+
return $optionMock;
145+
}
146+
}

0 commit comments

Comments
 (0)