Skip to content

Commit 5838e57

Browse files
author
Natalia Momotenko
committed
Merge remote-tracking branch 'origin/MAGETWO-59053' into PR
2 parents 13db0b1 + 33a6e49 commit 5838e57

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

lib/internal/Magento/Framework/View/Asset/MergeStrategy/Checksum.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Framework\View\Asset\MergeStrategy;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\View\Asset\Source;
911

1012
/**
1113
* Skip merging if all of the files that need to be merged were not modified
@@ -25,6 +27,11 @@ class Checksum implements \Magento\Framework\View\Asset\MergeStrategyInterface
2527
*/
2628
protected $filesystem;
2729

30+
/**
31+
* @var Source
32+
*/
33+
private $assetSource;
34+
2835
/**
2936
* @param \Magento\Framework\View\Asset\MergeStrategyInterface $strategy
3037
* @param \Magento\Framework\Filesystem $filesystem
@@ -37,17 +44,31 @@ public function __construct(
3744
$this->filesystem = $filesystem;
3845
}
3946

47+
/**
48+
* @deprecated
49+
* @return Source
50+
*/
51+
private function getAssetSource()
52+
{
53+
if (!$this->assetSource) {
54+
$this->assetSource = ObjectManager::getInstance()->get(Source::class);
55+
}
56+
return $this->assetSource;
57+
}
58+
4059
/**
4160
* {@inheritdoc}
4261
*/
4362
public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
4463
{
45-
$sourceDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
64+
$rootDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
4665
$mTime = null;
4766
/** @var \Magento\Framework\View\Asset\MergeableInterface $asset */
4867
foreach ($assetsToMerge as $asset) {
49-
$mTime .= $sourceDir->stat($sourceDir->getRelativePath($asset->getSourceFile()))['mtime'];
68+
$sourceFile = $this->getAssetSource()->findSource($asset);
69+
$mTime .= $rootDir->stat($rootDir->getRelativePath($sourceFile))['mtime'];
5070
}
71+
5172
if (null === $mTime) {
5273
return; // nothing to merge
5374
}

lib/internal/Magento/Framework/View/Test/Unit/Asset/MergeStrategy/ChecksumTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use \Magento\Framework\View\Asset\MergeStrategy\Checksum;
99

1010
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\View\Asset\Source;
1112

1213
class ChecksumTest extends \PHPUnit_Framework_TestCase
1314
{
@@ -31,6 +32,11 @@ class ChecksumTest extends \PHPUnit_Framework_TestCase
3132
*/
3233
private $resultAsset;
3334

35+
/**
36+
* @var Source|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $assetSource;
39+
3440
/**
3541
* @var \Magento\Framework\View\Asset\MergeStrategy\Checksum
3642
*/
@@ -53,6 +59,15 @@ protected function setUp()
5359
->with(DirectoryList::STATIC_VIEW)
5460
->will($this->returnValue($this->targetDir));
5561
$this->checksum = new Checksum($this->mergerMock, $filesystem);
62+
$this->assetSource = $this->getMockBuilder(Source::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
66+
$reflection = new \ReflectionClass(Checksum::class);
67+
$reflectionProperty = $reflection->getProperty('assetSource');
68+
$reflectionProperty->setAccessible(true);
69+
$reflectionProperty->setValue($this->checksum, $this->assetSource);
70+
5671
$this->resultAsset = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
5772
}
5873

@@ -114,9 +129,17 @@ public function testMergeMtimeUnchanged()
114129
private function getAssetsToMerge()
115130
{
116131
$one = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
117-
$one->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/one.txt'));
118132
$two = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
119-
$two->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/two.txt'));
133+
$one->expects($this->never())
134+
->method('getSourceFile');
135+
$two->expects($this->never())
136+
->method('getSourceFile');
137+
138+
$this->assetSource->expects($this->exactly(2))
139+
->method('findSource')
140+
->withConsecutive([$one], [$two])
141+
->willReturnOnConsecutiveCalls('/dir/file/one.txt', '/dir/file/two.txt');
142+
120143
$this->sourceDir->expects($this->exactly(2))
121144
->method('getRelativePath')
122145
->will($this->onConsecutiveCalls('file/one.txt', 'file/two.txt'));

0 commit comments

Comments
 (0)