Skip to content

Commit 6950ccf

Browse files
authored
Merge pull request #2526 from magento-mpi/MPI-PR
[MPI] Bug fixes
2 parents a50cda7 + 9d81527 commit 6950ccf

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public function deployFile($fileName, array $params = [])
8585
{
8686
$params['publish'] = true;
8787
$asset = $this->assetRepo->createAsset($this->resolveFile($fileName), $params);
88+
if (isset($params['replace'])) {
89+
$this->deleteFile($asset->getPath());
90+
}
8891

8992
$this->assetPublisher->publish($asset);
9093

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public function deploy($area, $theme, $locale)
6868
'fileName' => $this->jsTranslationConfig->getDictionaryFileName(),
6969
'area' => $area,
7070
'theme' => $theme,
71-
'locale' => $locale
71+
'locale' => $locale,
72+
'replace' => true
7273
]
7374
);
7475
});
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Deploy\Test\Unit\Service;
9+
10+
use Magento\Deploy\Service\DeployStaticFile;
11+
use Magento\Framework\View\Asset\Repository;
12+
use Magento\Framework\View\Asset\Minification;
13+
use Magento\Framework\View\Asset\File;
14+
use Magento\Framework\View\Asset\PreProcessor\FileNameResolver;
15+
use Magento\Framework\App\View\Asset\Publisher;
16+
use Magento\Framework\Filesystem;
17+
use Magento\Framework\Filesystem\DriverInterface;
18+
use Magento\Framework\Filesystem\Directory\WriteInterface;
19+
use PHPUnit_Framework_MockObject_MockObject as Mock;
20+
use PHPUnit_Framework_MockObject_Matcher_InvokedCount as InvokedCount;
21+
22+
class DeployStaticFileTest extends \PHPUnit\Framework\TestCase
23+
{
24+
/**
25+
* @var DeployStaticFile
26+
*/
27+
private $service;
28+
29+
/**
30+
* @var FileNameResolver | Mock
31+
*/
32+
private $fileNameResolver;
33+
34+
/**
35+
* @var Repository | Mock
36+
*/
37+
private $assetRepo;
38+
39+
/**
40+
* @var Publisher | Mock
41+
*/
42+
private $assetPublisher;
43+
44+
/**
45+
* @var Filesystem | Mock
46+
*/
47+
private $filesystem;
48+
49+
/**
50+
* @var Minification | Mock
51+
*/
52+
private $minification;
53+
54+
/**
55+
* @var DriverInterface | Mock
56+
*/
57+
private $fsDriver;
58+
59+
protected function setUp()
60+
{
61+
$this->fileNameResolver = $this->createPartialMock(FileNameResolver::class, ['resolve']);
62+
$this->assetRepo = $this->createPartialMock(Repository::class, ['createAsset']);
63+
$this->assetPublisher = $this->createPartialMock(Publisher::class, ['publish']);
64+
$this->filesystem = $this->createPartialMock(Filesystem::class, ['getDirectoryWrite']);
65+
$this->minification = $this->createMock(Minification::class);
66+
$this->fsDriver = $this->getMockForAbstractClass(DriverInterface::class);
67+
68+
$directory = $this->createMock(WriteInterface::class);
69+
70+
$directory->method('isExist')
71+
->willReturn(true);
72+
73+
$directory->method('getAbsolutePath')
74+
->willReturn('path');
75+
76+
$directory->method('getDriver')
77+
->willReturn($this->fsDriver);
78+
79+
$this->filesystem
80+
->method('getDirectoryWrite')
81+
->willReturn($directory);
82+
83+
$this->service = new DeployStaticFile(
84+
$this->filesystem,
85+
$this->assetRepo,
86+
$this->assetPublisher,
87+
$this->fileNameResolver,
88+
$this->minification
89+
);
90+
}
91+
92+
/**
93+
* @param string $fileName
94+
* @param array $params
95+
* @param InvokedCount $callDelete
96+
* @dataProvider deployFileDataProvider
97+
*/
98+
public function testDeployFile($fileName, array $params, InvokedCount $callDelete)
99+
{
100+
$file = $this->createMock(File::class);
101+
$file->method('getPath')
102+
->willReturn($fileName);
103+
104+
$this->fileNameResolver
105+
->method('resolve')
106+
->with($fileName)
107+
->willReturn($fileName);
108+
109+
$this->assetRepo
110+
->method('createAsset')
111+
->willReturn($file);
112+
113+
$this->fsDriver
114+
->method('isFile')
115+
->with('path')
116+
->willReturn(true);
117+
118+
$this->fsDriver
119+
->expects($callDelete)
120+
->method('deleteFile');
121+
122+
$this->service->deployFile($fileName, $params);
123+
}
124+
125+
/**
126+
* List of options for the file deploy.
127+
*
128+
* @return array
129+
*/
130+
public function deployFileDataProvider(): array
131+
{
132+
return [
133+
[
134+
'file1',
135+
['replace' => 'any value',],
136+
self::once()
137+
],
138+
[
139+
'file1',
140+
['replace' => false,],
141+
self::once()
142+
],
143+
[
144+
'file1',
145+
[],
146+
self::never()
147+
],
148+
];
149+
}
150+
}

0 commit comments

Comments
 (0)