/** * {@inheritdoc} */ public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset) { $dir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR); if (!$dir->isExist($resultAsset->getPath())) { $this->strategy->merge($assetsToMerge, $resultAsset); } }
public function testMergeMtimeUnchanged() { $this->targetDir->expects($this->once())->method('isExist')->with('merged/result.txt.dat')->will($this->returnValue(true)); $this->targetDir->expects($this->once())->method('readFile')->with('merged/result.txt.dat')->will($this->returnValue('11')); $assets = $this->getAssetsToMerge(); $this->mergerMock->expects($this->never())->method('merge'); $this->targetDir->expects($this->never())->method('writeFile'); $this->checksum->merge($assets, $this->resultAsset); }
/** * {@inheritdoc} */ public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset) { $sourceDir = $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']; } if (null === $mTime) { return; // nothing to merge } $dat = $resultAsset->getPath() . '.dat'; $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); if (!$targetDir->isExist($dat) || strcmp($mTime, $targetDir->readFile($dat)) !== 0) { $this->strategy->merge($assetsToMerge, $resultAsset); $targetDir->writeFile($dat, $mTime); } }
public function testIteratorInterfaceMerge() { $assets = [$this->assetJsOne, $this->assetJsTwo]; $this->logger->expects($this->never())->method('critical'); /** @var Merged $merged */ $merged = (new ObjectManager($this))->getObject(Merged::class, ['logger' => $this->logger, 'mergeStrategy' => $this->mergeStrategy, 'assetRepo' => $this->assetRepo, 'assets' => $assets]); $mergedAsset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false); $this->mergeStrategy->expects($this->once())->method('merge')->with($assets, $mergedAsset)->willReturn(null); $this->assetRepo->expects($this->once())->method('createArbitrary')->willReturn($mergedAsset); $expectedResult = [$mergedAsset]; $this->assertIteratorEquals($expectedResult, $merged); $this->assertIteratorEquals($expectedResult, $merged); // ensure merging happens only once }
public function testMergeNotExists() { $this->dirMock->expects($this->once())->method('isExist')->with('foo/file')->will($this->returnValue(false)); $this->mergerMock->expects($this->once())->method('merge')->with([], $this->resultAsset); $this->fileExists->merge([], $this->resultAsset); }