Skip to content
Snippets Groups Projects
Commit 5838e57c authored by Natalia Momotenko's avatar Natalia Momotenko
Browse files

Merge remote-tracking branch 'origin/MAGETWO-59053' into PR

parents 13db0b11 33a6e49f
Branches
Tags
No related merge requests found
......@@ -6,6 +6,8 @@
namespace Magento\Framework\View\Asset\MergeStrategy;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Asset\Source;
/**
* 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
*/
protected $filesystem;
/**
* @var Source
*/
private $assetSource;
/**
* @param \Magento\Framework\View\Asset\MergeStrategyInterface $strategy
* @param \Magento\Framework\Filesystem $filesystem
......@@ -37,17 +44,31 @@ class Checksum implements \Magento\Framework\View\Asset\MergeStrategyInterface
$this->filesystem = $filesystem;
}
/**
* @deprecated
* @return Source
*/
private function getAssetSource()
{
if (!$this->assetSource) {
$this->assetSource = ObjectManager::getInstance()->get(Source::class);
}
return $this->assetSource;
}
/**
* {@inheritdoc}
*/
public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
{
$sourceDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
$rootDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
$mTime = null;
/** @var \Magento\Framework\View\Asset\MergeableInterface $asset */
foreach ($assetsToMerge as $asset) {
$mTime .= $sourceDir->stat($sourceDir->getRelativePath($asset->getSourceFile()))['mtime'];
$sourceFile = $this->getAssetSource()->findSource($asset);
$mTime .= $rootDir->stat($rootDir->getRelativePath($sourceFile))['mtime'];
}
if (null === $mTime) {
return; // nothing to merge
}
......
......@@ -8,6 +8,7 @@ namespace Magento\Framework\View\Test\Unit\Asset\MergeStrategy;
use \Magento\Framework\View\Asset\MergeStrategy\Checksum;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\View\Asset\Source;
class ChecksumTest extends \PHPUnit_Framework_TestCase
{
......@@ -31,6 +32,11 @@ class ChecksumTest extends \PHPUnit_Framework_TestCase
*/
private $resultAsset;
/**
* @var Source|\PHPUnit_Framework_MockObject_MockObject
*/
private $assetSource;
/**
* @var \Magento\Framework\View\Asset\MergeStrategy\Checksum
*/
......@@ -53,6 +59,15 @@ class ChecksumTest extends \PHPUnit_Framework_TestCase
->with(DirectoryList::STATIC_VIEW)
->will($this->returnValue($this->targetDir));
$this->checksum = new Checksum($this->mergerMock, $filesystem);
$this->assetSource = $this->getMockBuilder(Source::class)
->disableOriginalConstructor()
->getMock();
$reflection = new \ReflectionClass(Checksum::class);
$reflectionProperty = $reflection->getProperty('assetSource');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->checksum, $this->assetSource);
$this->resultAsset = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
}
......@@ -114,9 +129,17 @@ class ChecksumTest extends \PHPUnit_Framework_TestCase
private function getAssetsToMerge()
{
$one = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
$one->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/one.txt'));
$two = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
$two->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/two.txt'));
$one->expects($this->never())
->method('getSourceFile');
$two->expects($this->never())
->method('getSourceFile');
$this->assetSource->expects($this->exactly(2))
->method('findSource')
->withConsecutive([$one], [$two])
->willReturnOnConsecutiveCalls('/dir/file/one.txt', '/dir/file/two.txt');
$this->sourceDir->expects($this->exactly(2))
->method('getRelativePath')
->will($this->onConsecutiveCalls('file/one.txt', 'file/two.txt'));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment