Skip to content

Commit fbc9db3

Browse files
author
Anton Evers
committed
Add unit tests
1 parent 17a44e2 commit fbc9db3

File tree

2 files changed

+78
-39
lines changed

2 files changed

+78
-39
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function deploy(array $options)
8080
: (new \DateTime())->getTimestamp();
8181
$this->versionStorage->save($version);
8282

83-
if ($options[Options::REFRESH_CONTENT_VERSION_ONLY]) {
83+
if ($this->getRefreshContentVersionOnly($options)) {
8484
$this->logger->warning(PHP_EOL . "New content version: " . $version);
8585
return;
8686
}
@@ -140,4 +140,15 @@ private function getProcessesAmount(array $options)
140140
{
141141
return isset($options[Options::JOBS_AMOUNT]) ? (int)$options[Options::JOBS_AMOUNT] : 0;
142142
}
143+
144+
/**
145+
* @param array $options
146+
* @return bool
147+
*/
148+
private function getRefreshContentVersionOnly(array $options)
149+
{
150+
return isset($options[Options::REFRESH_CONTENT_VERSION_ONLY])
151+
? (bool)$options[Options::REFRESH_CONTENT_VERSION_ONLY]
152+
: false;
153+
}
143154
}

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

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,17 @@ protected function setUp()
114114
public function testDeploy($options, $expectedContentVersion)
115115
{
116116
$package = $this->getMock(Package::class, [], [], '', false);
117-
$package->expects($this->exactly(1))->method('isVirtual')->willReturn(false);
118-
$package->expects($this->exactly(3))->method('getArea')->willReturn('area');
119-
$package->expects($this->exactly(3))->method('getTheme')->willReturn('theme');
120-
$package->expects($this->exactly(2))->method('getLocale')->willReturn('locale');
121-
117+
if ($options['refresh-content-version-only']) {
118+
$package->expects($this->never())->method('isVirtual');
119+
$package->expects($this->never())->method('getArea');
120+
$package->expects($this->never())->method('getTheme');
121+
$package->expects($this->never())->method('getLocale');
122+
} else {
123+
$package->expects($this->exactly(1))->method('isVirtual')->willReturn(false);
124+
$package->expects($this->exactly(3))->method('getArea')->willReturn('area');
125+
$package->expects($this->exactly(3))->method('getTheme')->willReturn('theme');
126+
$package->expects($this->exactly(2))->method('getLocale')->willReturn('locale');
127+
}
122128
$packages = [
123129
'package' => $package
124130
];
@@ -132,20 +138,28 @@ public function testDeploy($options, $expectedContentVersion)
132138
$queue = $this->getMockBuilder(Queue::class)
133139
->disableOriginalConstructor()
134140
->getMockForAbstractClass();
135-
$this->queueFactory->expects($this->once())->method('create')->willReturn($queue);
141+
if ($options['refresh-content-version-only']) {
142+
$this->queueFactory->expects($this->never())->method('create');
143+
} else {
144+
$this->queueFactory->expects($this->once())->method('create')->willReturn($queue);
145+
}
136146

137147
$strategy = $this->getMockBuilder(CompactDeploy::class)
138148
->setMethods(['deploy'])
139149
->disableOriginalConstructor()
140150
->getMockForAbstractClass();
141-
$strategy->expects($this->once())->method('deploy')
142-
->with($options)
143-
->willReturn($packages);
144-
$this->deployStrategyFactory->expects($this->once())
145-
->method('create')
146-
->with('compact', ['queue' => $queue])
147-
->willReturn($strategy);
148-
151+
if ($options['refresh-content-version-only']) {
152+
$strategy->expects($this->never())->method('deploy');
153+
$this->deployStrategyFactory->expects($this->never())->method('create');
154+
} else {
155+
$strategy->expects($this->once())->method('deploy')
156+
->with($options)
157+
->willReturn($packages);
158+
$this->deployStrategyFactory->expects($this->once())
159+
->method('create')
160+
->with('compact', ['queue' => $queue])
161+
->willReturn($strategy);
162+
}
149163
$deployPackageService = $this->getMockBuilder(DeployPackage::class)
150164
->disableOriginalConstructor()
151165
->getMockForAbstractClass();
@@ -166,29 +180,34 @@ public function testDeploy($options, $expectedContentVersion)
166180
->disableOriginalConstructor()
167181
->getMockForAbstractClass();
168182

169-
$this->objectManager->expects($this->exactly(4))
170-
->method('create')
171-
->withConsecutive(
172-
[DeployPackage::class, ['logger' => $this->logger]],
173-
[DeployRequireJsConfig::class, ['logger' => $this->logger]],
174-
[DeployTranslationsDictionary::class, ['logger' => $this->logger]],
175-
[Bundle::class, ['logger' => $this->logger]]
176-
)
177-
->willReturnOnConsecutiveCalls(
178-
$deployPackageService,
179-
$deployRjsConfig,
180-
$deployI18n,
181-
$deployBundle
182-
);
183-
184-
$this->objectManager->expects($this->exactly(1))
185-
->method('get')
186-
->withConsecutive(
187-
[MinifyTemplates::class]
188-
)
189-
->willReturnOnConsecutiveCalls(
190-
$minifyTemplates
191-
);
183+
if ($options['refresh-content-version-only']) {
184+
$this->objectManager->expects($this->never())->method('create');
185+
$this->objectManager->expects($this->never())->method('get');
186+
} else {
187+
$this->objectManager->expects($this->exactly(4))
188+
->method('create')
189+
->withConsecutive(
190+
[DeployPackage::class, ['logger' => $this->logger]],
191+
[DeployRequireJsConfig::class, ['logger' => $this->logger]],
192+
[DeployTranslationsDictionary::class, ['logger' => $this->logger]],
193+
[Bundle::class, ['logger' => $this->logger]]
194+
)
195+
->willReturnOnConsecutiveCalls(
196+
$deployPackageService,
197+
$deployRjsConfig,
198+
$deployI18n,
199+
$deployBundle
200+
);
201+
202+
$this->objectManager->expects($this->exactly(1))
203+
->method('get')
204+
->withConsecutive(
205+
[MinifyTemplates::class]
206+
)
207+
->willReturnOnConsecutiveCalls(
208+
$minifyTemplates
209+
);
210+
}
192211

193212
$this->assertEquals(
194213
null,
@@ -203,7 +222,8 @@ public function deployDataProvider()
203222
[
204223
'strategy' => 'compact',
205224
'no-javascript' => false,
206-
'no-html-minify' => false
225+
'no-html-minify' => false,
226+
'refresh-content-version-only' => false,
207227
],
208228
null // content version value should not be asserted in this case
209229
],
@@ -212,9 +232,17 @@ public function deployDataProvider()
212232
'strategy' => 'compact',
213233
'no-javascript' => false,
214234
'no-html-minify' => false,
235+
'refresh-content-version-only' => false,
215236
'content-version' => '123456',
216237
],
217238
'123456'
239+
],
240+
[
241+
[
242+
'refresh-content-version-only' => true,
243+
'content-version' => '654321',
244+
],
245+
'654321'
218246
]
219247
];
220248
}

0 commit comments

Comments
 (0)