Skip to content

Commit 15895e6

Browse files
author
cspruiell
committed
Merge remote-tracking branch 'origin/MAGETWO-62567-Static-Content-Versioning' into okapis-mainline-2.2-pr
2 parents 151a776 + fc6d1ad commit 15895e6

File tree

5 files changed

+66
-20
lines changed

5 files changed

+66
-20
lines changed

app/code/Magento/Deploy/Console/DeployStaticOptions.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ class DeployStaticOptions
126126
*/
127127
const LANGUAGES_ARGUMENT = 'languages';
128128

129+
/**
130+
* Static content version
131+
*/
132+
const CONTENT_VERSION = 'content-version';
133+
129134
/**
130135
* Deploy static command options list
131136
*
@@ -211,7 +216,14 @@ private function getBasicOptions()
211216
null,
212217
InputOption::VALUE_NONE,
213218
'Create symlinks for the files of those locales, which are passed for deployment, '
214-
. 'but have no customizations'
219+
. 'but have no customizations.'
220+
),
221+
new InputOption(
222+
self::CONTENT_VERSION,
223+
null,
224+
InputArgument::OPTIONAL,
225+
'Custom version of static content can be used if running deployment on multiple nodes '
226+
. 'to ensure that static content version is identical and caching works properly.'
215227
),
216228
new InputArgument(
217229
self::LANGUAGES_ARGUMENT,

app/code/Magento/Deploy/Service/DeployStaticContent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ public function deploy(array $options)
9696
]
9797
);
9898

99-
$version = (new \DateTime())->getTimestamp();
99+
$version = !empty($options[Options::CONTENT_VERSION]) && is_string($options[Options::CONTENT_VERSION])
100+
? $options[Options::CONTENT_VERSION]
101+
: (new \DateTime())->getTimestamp();
100102
$this->versionStorage->save($version);
101103

102104
$packages = $deployStrategy->deploy($options);

app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ protected function setUp()
9696
'',
9797
false
9898
);
99-
$this->versionStorage->expects($this->once())->method('save');
10099

101100
$this->service = new DeployStaticContent(
102101
$this->objectManager,
@@ -107,14 +106,13 @@ protected function setUp()
107106
);
108107
}
109108

110-
public function testDeploy()
109+
/**
110+
* @param array $options
111+
* @param string $expectedContentVersion
112+
* @dataProvider deployDataProvider
113+
*/
114+
public function testDeploy($options, $expectedContentVersion)
111115
{
112-
$options = [
113-
'strategy' => 'compact',
114-
'no-javascript' => false,
115-
'no-html-minify' => false
116-
];
117-
118116
$package = $this->getMock(Package::class, [], [], '', false);
119117
$package->expects($this->exactly(1))->method('isVirtual')->willReturn(false);
120118
$package->expects($this->exactly(3))->method('getArea')->willReturn('area');
@@ -125,7 +123,11 @@ public function testDeploy()
125123
'package' => $package
126124
];
127125

128-
$this->versionStorage->expects($this->once())->method('save');
126+
if ($expectedContentVersion) {
127+
$this->versionStorage->expects($this->once())->method('save')->with($expectedContentVersion);
128+
} else {
129+
$this->versionStorage->expects($this->once())->method('save');
130+
}
129131

130132
$queue = $this->getMockBuilder(Queue::class)
131133
->disableOriginalConstructor()
@@ -193,4 +195,27 @@ public function testDeploy()
193195
$this->service->deploy($options)
194196
);
195197
}
198+
199+
public function deployDataProvider()
200+
{
201+
return [
202+
[
203+
[
204+
'strategy' => 'compact',
205+
'no-javascript' => false,
206+
'no-html-minify' => false
207+
],
208+
null // content version value should not be asserted in this case
209+
],
210+
[
211+
[
212+
'strategy' => 'compact',
213+
'no-javascript' => false,
214+
'no-html-minify' => false,
215+
'content-version' => '123456',
216+
],
217+
'123456'
218+
]
219+
];
220+
}
196221
}

dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ protected function tearDown()
130130
*/
131131
public function testDeploy()
132132
{
133-
//$this->markTestSkipped('Test blocked since it must be run in isolated Filesystem');
134133
$this->deployService->deploy($this->options);
135134

136135
$this->assertFileExists($this->staticDir->getAbsolutePath('frontend/Magento/zoom1/default/css/root.css'));

setup/src/Magento/Setup/Test/Unit/Console/Command/DeployStaticContentCommandTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class DeployStaticContentCommandTest extends \PHPUnit_Framework_TestCase
4949
*/
5050
private $deployService;
5151

52-
/**
53-
* @var DeployStaticOptions|Mock
54-
*/
55-
private $options;
56-
5752
/**
5853
* Object manager to create various objects
5954
*
@@ -75,7 +70,6 @@ protected function setUp()
7570
$this->inputValidator = $this->getMock(InputValidator::class, [], [], '', false);
7671
$this->consoleLoggerFactory = $this->getMock(ConsoleLoggerFactory::class, [], [], '', false);
7772
$this->logger = $this->getMock(ConsoleLogger::class, [], [], '', false);
78-
$this->options = $this->getMock(DeployStaticOptions::class, [], [], '', false);
7973
$this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class);
8074
$this->appState = $this->getMock(State::class, [], [], '', false);
8175
$this->deployService = $this->getMock(DeployStaticContent::class, [], [], '', false);
@@ -99,9 +93,11 @@ protected function setUp()
9993
}
10094

10195
/**
96+
* @param array $input
10297
* @see DeployStaticContentCommand::execute()
98+
* @dataProvider executeDataProvider
10399
*/
104-
public function testExecute()
100+
public function testExecute($input)
105101
{
106102
$this->appState->expects($this->once())
107103
->method('getMode')
@@ -118,7 +114,19 @@ public function testExecute()
118114
$this->deployService->expects($this->once())->method('deploy');
119115

120116
$tester = new CommandTester($this->command);
121-
$tester->execute([]);
117+
$tester->execute($input);
118+
}
119+
120+
public function executeDataProvider()
121+
{
122+
return [
123+
'No options' => [
124+
[]
125+
],
126+
'With static content version option' => [
127+
['--content-version' => '123456']
128+
]
129+
];
122130
}
123131

124132
/**

0 commit comments

Comments
 (0)