From 59d54c3347d18c6e830671aaed3a93388f163bae Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Thu, 19 Mar 2015 17:33:24 +0200 Subject: [PATCH 1/6] MAGETWO-35298: Deploy script modifies LESS files with "@urls-resolved: true" line(-s) - fixed di configuration related to fileassembler --- app/etc/di.xml | 6 +++--- dev/tools/Magento/Tools/Webdev/App/FileAssembler.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/etc/di.xml b/app/etc/di.xml index a3da2e85a1954..fd0e4eeaf7861 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -560,7 +560,7 @@ - Magento\Framework\Less\FileGenerator + daemonFileGenerator @@ -590,11 +590,11 @@ lessFileGeneratorMaterialization - + lessFileGeneratorPublisher - + Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Grouped diff --git a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php index fb8529dd75969..4378f36cd0efa 100644 --- a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php +++ b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php @@ -60,7 +60,7 @@ class FileAssembler implements AppInterface /** * @var \Magento\Framework\Less\FileGenerator */ - private $sourceFileGeneratorPoll; + private $sourceFileGeneratorPool; /** * @var \Magento\Framework\View\Asset\Source @@ -109,7 +109,7 @@ public function __construct( $this->objectManager = $objectManager; $this->configLoader = $configLoader; $this->assetRepo = $assetRepo; - $this->sourceFileGeneratorPoll = $sourceFileGeneratorPoll; + $this->sourceFileGeneratorPool = $sourceFileGeneratorPoll; $this->assetSource = $assetSource; $this->logger = $logger; $this->chainFactory = $chainFactory; @@ -125,7 +125,7 @@ public function launch() $this->state->setAreaCode($this->params->getArea()); $this->objectManager->configure($this->configLoader->load($this->params->getArea())); - $sourceFileGenerator = $this->sourceFileGeneratorPoll->create($this->params->getExt()); + $sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt()); foreach ($this->params->getFiles() as $file) { $file .= '.' . $this->params->getExt(); From 97d48ee4b07020edd2f482fab5fbc698e19066bc Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Thu, 19 Mar 2015 20:41:55 +0200 Subject: [PATCH 2/6] MAGETWO-35298: Deploy script modifies LESS files with "@urls-resolved: true" line(-s) - fixed less file generator library dependency on custom application logic --- .../FileGenerator/PublicationDecorator.php | 38 ++++++ app/etc/di.xml | 24 ++-- .../Magento/Framework/Less/Config.php | 21 ++++ .../Magento/Framework/Less/File/Temporary.php | 52 ++++++++ .../Magento/Framework/Less/FileGenerator.php | 117 ++++-------------- .../Less/FileGenerator/RelatedGenerator.php | 84 +++++++++++++ 6 files changed, 230 insertions(+), 106 deletions(-) create mode 100644 app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php create mode 100644 lib/internal/Magento/Framework/Less/Config.php create mode 100644 lib/internal/Magento/Framework/Less/File/Temporary.php create mode 100644 lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php diff --git a/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php new file mode 100644 index 0000000000000..d37c90ebe5fb4 --- /dev/null +++ b/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php @@ -0,0 +1,38 @@ +publisher = $publisher; + } + + /** + * {inheritdoc} + */ + protected function generateRelatedFile($relatedFileId, LocalInterface $asset) + { + $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); + $this->publisher->publish($relatedAsset); + return $relatedAsset; + } +} diff --git a/app/etc/di.xml b/app/etc/di.xml index fd0e4eeaf7861..cb45113bb261c 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -557,13 +557,6 @@ developerPublisher - - - - daemonFileGenerator - - - developerMaterialization @@ -577,22 +570,21 @@ - + - - Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink - Magento\Framework\App\View\Asset\MaterializationStrategy\Copy + + fileassemblerFileGenerator - - + + - lessFileGeneratorMaterialization + fileassemblerRelatedFilesGenerator - + - lessFileGeneratorPublisher + developerPublisher diff --git a/lib/internal/Magento/Framework/Less/Config.php b/lib/internal/Magento/Framework/Less/Config.php new file mode 100644 index 0000000000000..a48eeff6f2349 --- /dev/null +++ b/lib/internal/Magento/Framework/Less/Config.php @@ -0,0 +1,21 @@ +tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + $this->config = $config; + } + + /** + * Write down contents to a temporary file and return its absolute path + * + * @param string $relativePath + * @param string $contents + * @return string + */ + public function createFile($relativePath, $contents) + { + $filePath = $this->config->getLessDirectory() . '/' . $relativePath; + + if (!$this->tmpDirectory->isExist($filePath)) { + $this->tmpDirectory->writeFile($filePath, $contents); + } + return $this->tmpDirectory->getAbsolutePath($filePath); + } +} diff --git a/lib/internal/Magento/Framework/Less/FileGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator.php index f45d462e7eaae..a300fbd3785d5 100644 --- a/lib/internal/Magento/Framework/Less/FileGenerator.php +++ b/lib/internal/Magento/Framework/Less/FileGenerator.php @@ -7,17 +7,11 @@ namespace Magento\Framework\Less; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\View\Asset\LocalInterface; use Magento\Framework\View\Asset\PreProcessor\Chain; use Magento\Framework\View\Asset\SourceFileGeneratorInterface; class FileGenerator implements SourceFileGeneratorInterface { - /** - * Temporary directory prefix - */ - const TMP_LESS_DIR = 'less'; - /** * Max execution (locking) time for generation process (in seconds) */ @@ -28,11 +22,6 @@ class FileGenerator implements SourceFileGeneratorInterface */ const LOCK_FILE = 'less.lock'; - /** - * @var string - */ - protected $lessDirectory; - /** * @var \Magento\Framework\Filesystem\Directory\WriteInterface */ @@ -59,17 +48,29 @@ class FileGenerator implements SourceFileGeneratorInterface private $importProcessor; /** - * @var \Magento\Framework\App\View\Asset\Publisher + * @var FileGenerator\RelatedGenerator */ - private $publisher; + private $relatedGenerator; + + /** + * @var Config + */ + private $config; + + /** + * @var File\Temporary + */ + private $temporaryFile; /** * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor - * @param \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor + * @param PreProcessor\Instruction\MagentoImport $magentoImportProcessor + * @param PreProcessor\Instruction\Import $importProcessor * @param \Magento\Framework\View\Asset\Source $assetSource - * @param \Magento\Framework\App\View\Asset\Publisher $publisher + * @param FileGenerator\RelatedGenerator $relatedGenerator + * @param Config $config + * @param File\Temporary $temporaryFile */ public function __construct( \Magento\Framework\Filesystem $filesystem, @@ -77,17 +78,20 @@ public function __construct( \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor, \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor, \Magento\Framework\View\Asset\Source $assetSource, - \Magento\Framework\App\View\Asset\Publisher $publisher + \Magento\Framework\Less\FileGenerator\RelatedGenerator $relatedGenerator, + Config $config, + File\Temporary $temporaryFile ) { $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); $this->pubDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB); - $this->lessDirectory = DirectoryList::TMP_MATERIALIZATION_DIR . '/' . self::TMP_LESS_DIR; $this->assetRepo = $assetRepo; $this->assetSource = $assetSource; $this->magentoImportProcessor = $magentoImportProcessor; $this->importProcessor = $importProcessor; - $this->publisher = $publisher; + $this->relatedGenerator = $relatedGenerator; + $this->config = $config; + $this->temporaryFile = $temporaryFile; } /** @@ -109,16 +113,14 @@ public function generateFileTree(Chain $chain) while ($this->isProcessLocked()) { sleep(1); } - $lockFilePath = $this->lessDirectory . '/' . self::LOCK_FILE; + $lockFilePath = $this->config->getLessDirectory() . '/' . self::LOCK_FILE; $this->tmpDirectory->writeFile($lockFilePath, time()); $this->magentoImportProcessor->process($chain); $this->importProcessor->process($chain); - $this->generateRelatedFiles(); + $this->relatedGenerator->generate(); $lessRelativePath = preg_replace('#\.css$#', '.less', $chain->getAsset()->getPath()); - $tmpFilePath = $this->createFile($lessRelativePath, $chain->getContent()); - - $this->createFileMain($lessRelativePath, $chain->getContent()); + $tmpFilePath = $this->temporaryFile->createFile($lessRelativePath, $chain->getContent()); $this->tmpDirectory->delete($lockFilePath); return $tmpFilePath; @@ -131,7 +133,7 @@ public function generateFileTree(Chain $chain) */ protected function isProcessLocked() { - $lockFilePath = $this->lessDirectory . '/' . self::LOCK_FILE; + $lockFilePath = $this->config->getLessDirectory() . '/' . self::LOCK_FILE; if ($this->tmpDirectory->isExist($lockFilePath)) { $lockTime = time() - (int)$this->tmpDirectory->readFile($lockFilePath); if ($lockTime >= self::MAX_LOCK_TIME) { @@ -142,69 +144,4 @@ protected function isProcessLocked() } return false; } - - /** - * Create all asset files, referenced from already processed ones - * - * @return void - */ - protected function generateRelatedFiles() - { - do { - $relatedFiles = $this->importProcessor->getRelatedFiles(); - $this->importProcessor->resetRelatedFiles(); - foreach ($relatedFiles as $relatedFileInfo) { - list($relatedFileId, $asset) = $relatedFileInfo; - $this->generateRelatedFile($relatedFileId, $asset); - } - } while ($relatedFiles); - } - - /** - * Create file, referenced relatively to an asset - * - * @param string $relatedFileId - * @param LocalInterface $asset - * @return void - */ - protected function generateRelatedFile($relatedFileId, LocalInterface $asset) - { - $relatedAsset = $this->assetRepo->createRelated($relatedFileId, $asset); - $relatedAsset->getFilePath(); - - $this->createFile($relatedAsset->getPath(), $relatedAsset->getContent()); - $relatedAsset->getSourceFile(); - $this->publisher->publish($relatedAsset); - } - - /** - * Write down contents to a temporary file and return its absolute path - * - * @param string $relativePath - * @param string $contents - * @return string - */ - private function createFile($relativePath, $contents) - { - $filePath = $this->lessDirectory . '/' . $relativePath; - - if (!$this->tmpDirectory->isExist($filePath)) { - $this->tmpDirectory->writeFile($filePath, $contents); - } - return $this->tmpDirectory->getAbsolutePath($filePath); - } - - /** - * @param string $relativePath - * @param string $contents - * - * @return void - */ - private function createFileMain($relativePath, $contents) - { - $filePath = '/static/' . $relativePath; - $contents .= '@urls-resolved: true;' . PHP_EOL . PHP_EOL; - $this->pubDirectory->writeFile($filePath, $contents); - return; - } } diff --git a/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php new file mode 100644 index 0000000000000..daac40879a97d --- /dev/null +++ b/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php @@ -0,0 +1,84 @@ +tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + $this->assetRepo = $assetRepo; + + $this->importProcessor = $importProcessor; + $this->temporaryFile = $temporaryFile; + } + + /** + * Create all asset files, referenced from already processed ones + * + * @return void + */ + public function generate() + { + do { + $relatedFiles = $this->importProcessor->getRelatedFiles(); + $this->importProcessor->resetRelatedFiles(); + foreach ($relatedFiles as $relatedFileInfo) { + list($relatedFileId, $asset) = $relatedFileInfo; + + $this->generateRelatedFile($relatedFileId, $asset); + } + } while ($relatedFiles); + } + + /** + * Create file, referenced relatively to an asset + * + * @param string $relatedFileId + * @param LocalInterface $asset + * @return \Magento\Framework\View\Asset\File + */ + protected function generateRelatedFile($relatedFileId, LocalInterface $asset) + { + $relatedAsset = $this->assetRepo->createRelated($relatedFileId, $asset); + $this->temporaryFile->createFile($relatedAsset->getPath(), $relatedAsset->getContent()); + + return $relatedAsset; + } +} From 95ddc08369e6cefd30dead86859ac743154193eb Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Thu, 19 Mar 2015 21:20:43 +0200 Subject: [PATCH 3/6] MAGETWO-35298: Deploy script modifies LESS files with "@urls-resolved: true" line(-s) - fixed code defects - fixed file generator test - fixed code review bugs - fixed fileassembler application --- .../FileGenerator/PublicationDecorator.php | 15 +- .../Magento/Tools/Webdev/file_assembler.php | 6 +- .../Magento/Framework/Less/Config.php | 7 +- .../Magento/Framework/Less/File/Temporary.php | 2 +- .../Magento/Framework/Less/FileGenerator.php | 9 +- .../Less/FileGenerator/RelatedGenerator.php | 17 +- .../Less/Test/Unit/FileGeneratorTest.php | 166 ++++++++++-------- 7 files changed, 124 insertions(+), 98 deletions(-) diff --git a/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php index d37c90ebe5fb4..d99f32d515e38 100644 --- a/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php +++ b/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php @@ -8,6 +8,12 @@ use Magento\Framework\Less\FileGenerator\RelatedGenerator; use Magento\Framework\View\Asset\LocalInterface; +/** + * Class PublicationDecorator + * Decorates generator of related assets and publishes them + * + * @package Magento\Developer\Model\Less\FileGenerator + */ class PublicationDecorator extends RelatedGenerator { /** @@ -15,14 +21,19 @@ class PublicationDecorator extends RelatedGenerator */ private $publisher; + /** + * @param \Magento\Framework\Filesystem $filesystem + * @param \Magento\Framework\View\Asset\Repository $assetRepo + * @param \Magento\Framework\Less\File\Temporary $temporaryFile + * @param \Magento\Framework\App\View\Asset\Publisher $publisher + */ public function __construct( \Magento\Framework\Filesystem $filesystem, \Magento\Framework\View\Asset\Repository $assetRepo, - \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor, \Magento\Framework\Less\File\Temporary $temporaryFile, \Magento\Framework\App\View\Asset\Publisher $publisher ) { - parent::__construct($filesystem, $assetRepo, $importProcessor, $temporaryFile); + parent::__construct($filesystem, $assetRepo, $temporaryFile); $this->publisher = $publisher; } diff --git a/dev/tools/Magento/Tools/Webdev/file_assembler.php b/dev/tools/Magento/Tools/Webdev/file_assembler.php index 72ec5b0458fdf..669ffa8d53585 100644 --- a/dev/tools/Magento/Tools/Webdev/file_assembler.php +++ b/dev/tools/Magento/Tools/Webdev/file_assembler.php @@ -35,15 +35,15 @@ $logger = new Log($params->getVerbose()); } catch (\Zend_Console_Getopt_Exception $e) { - echo $e->getUsageMessage(); - echo 'Please, use quotes(") for wrapping strings.' . "\n"; + echo $e->getMessage() . PHP_EOL; + echo 'Please, use quotes(") for wrapping strings.' . PHP_EOL; exit(1); } $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication( - 'Magento\Tools\WebDev\App\FileAssembler', + 'Magento\Tools\Webdev\App\FileAssembler', ['params' => $params, 'logger' => $logger] ); $bootstrap->run($app); diff --git a/lib/internal/Magento/Framework/Less/Config.php b/lib/internal/Magento/Framework/Less/Config.php index a48eeff6f2349..88f6c27e9ee41 100644 --- a/lib/internal/Magento/Framework/Less/Config.php +++ b/lib/internal/Magento/Framework/Less/Config.php @@ -14,7 +14,12 @@ class Config */ const TMP_LESS_DIR = 'less'; - public function getLessDirectory() + /** + * Returns relative path to less materialization directory + * + * @return string + */ + public function getLessMaterializationRelativePath() { return DirectoryList::TMP_MATERIALIZATION_DIR . '/' . self::TMP_LESS_DIR; } diff --git a/lib/internal/Magento/Framework/Less/File/Temporary.php b/lib/internal/Magento/Framework/Less/File/Temporary.php index 00a21b1373326..8da016ecde585 100644 --- a/lib/internal/Magento/Framework/Less/File/Temporary.php +++ b/lib/internal/Magento/Framework/Less/File/Temporary.php @@ -42,7 +42,7 @@ public function __construct( */ public function createFile($relativePath, $contents) { - $filePath = $this->config->getLessDirectory() . '/' . $relativePath; + $filePath = $this->config->getLessMaterializationRelativePath() . '/' . $relativePath; if (!$this->tmpDirectory->isExist($filePath)) { $this->tmpDirectory->writeFile($filePath, $contents); diff --git a/lib/internal/Magento/Framework/Less/FileGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator.php index a300fbd3785d5..49102758be873 100644 --- a/lib/internal/Magento/Framework/Less/FileGenerator.php +++ b/lib/internal/Magento/Framework/Less/FileGenerator.php @@ -71,6 +71,8 @@ class FileGenerator implements SourceFileGeneratorInterface * @param FileGenerator\RelatedGenerator $relatedGenerator * @param Config $config * @param File\Temporary $temporaryFile + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ public function __construct( \Magento\Framework\Filesystem $filesystem, @@ -83,7 +85,6 @@ public function __construct( File\Temporary $temporaryFile ) { $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); - $this->pubDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB); $this->assetRepo = $assetRepo; $this->assetSource = $assetSource; @@ -113,12 +114,12 @@ public function generateFileTree(Chain $chain) while ($this->isProcessLocked()) { sleep(1); } - $lockFilePath = $this->config->getLessDirectory() . '/' . self::LOCK_FILE; + $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE; $this->tmpDirectory->writeFile($lockFilePath, time()); $this->magentoImportProcessor->process($chain); $this->importProcessor->process($chain); - $this->relatedGenerator->generate(); + $this->relatedGenerator->generate($this->importProcessor); $lessRelativePath = preg_replace('#\.css$#', '.less', $chain->getAsset()->getPath()); $tmpFilePath = $this->temporaryFile->createFile($lessRelativePath, $chain->getContent()); @@ -133,7 +134,7 @@ public function generateFileTree(Chain $chain) */ protected function isProcessLocked() { - $lockFilePath = $this->config->getLessDirectory() . '/' . self::LOCK_FILE; + $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE; if ($this->tmpDirectory->isExist($lockFilePath)) { $lockTime = time() - (int)$this->tmpDirectory->readFile($lockFilePath); if ($lockTime >= self::MAX_LOCK_TIME) { diff --git a/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php index daac40879a97d..64564ce4c0e9f 100644 --- a/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php +++ b/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Less\FileGenerator; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Less\PreProcessor\Instruction\Import; use Magento\Framework\View\Asset\LocalInterface; class RelatedGenerator @@ -20,11 +21,6 @@ class RelatedGenerator */ private $assetRepo; - /** - * @var \Magento\Framework\Less\PreProcessor\Instruction\Import - */ - private $importProcessor; - /** * @var \Magento\Framework\Less\File\Temporary */ @@ -33,32 +29,31 @@ class RelatedGenerator /** * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor * @param \Magento\Framework\Less\File\Temporary $temporaryFile */ public function __construct( \Magento\Framework\Filesystem $filesystem, \Magento\Framework\View\Asset\Repository $assetRepo, - \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor, \Magento\Framework\Less\File\Temporary $temporaryFile ) { $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); $this->assetRepo = $assetRepo; - $this->importProcessor = $importProcessor; $this->temporaryFile = $temporaryFile; } /** * Create all asset files, referenced from already processed ones * + * @param Import $importGenerator + * * @return void */ - public function generate() + public function generate(Import $importGenerator) { do { - $relatedFiles = $this->importProcessor->getRelatedFiles(); - $this->importProcessor->resetRelatedFiles(); + $relatedFiles = $importGenerator->getRelatedFiles(); + $importGenerator->resetRelatedFiles(); foreach ($relatedFiles as $relatedFileInfo) { list($relatedFileId, $asset) = $relatedFileInfo; diff --git a/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php b/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php index 60293981b8f76..f5985fbd30f60 100644 --- a/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php +++ b/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php @@ -4,8 +4,6 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - namespace Magento\Framework\Less\Test\Unit; class FileGeneratorTest extends \PHPUnit_Framework_TestCase @@ -41,58 +39,105 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase private $object; /** - * @var \Magento\Framework\App\View\Asset\Publisher|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Less\FileGenerator\RelatedGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + private $relatedGenerator; + + /** + * @var \Magento\Framework\Less\Config|\PHPUnit_Framework_MockObject_MockObject */ - private $publisher; + private $config; + + /** + * @var \Magento\Framework\Less\File\Temporary|\PHPUnit_Framework_MockObject_MockObject + */ + private $temporaryFile; protected function setUp() { - $this->tmpDirectory = $this->getMockForAbstractClass('\Magento\Framework\Filesystem\Directory\WriteInterface'); - $this->rootDirectory = $this->getMockForAbstractClass('\Magento\Framework\Filesystem\Directory\ReadInterface'); + $this->tmpDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); + $this->rootDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface'); $this->rootDirectory->expects($this->any()) ->method('getRelativePath') ->will($this->returnArgument(0)); $this->rootDirectory->expects($this->any()) ->method('readFile') - ->will($this->returnCallback(function ($file) { - return "content of '$file'"; - })); + ->will( + $this->returnCallback( + function ($file) { + return "content of '$file'"; + } + ) + ); $filesystem = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false); - $filesystem->expects($this->exactly(2)) + $filesystem->expects($this->once()) ->method('getDirectoryWrite') - //->with(DirectoryList::VAR_DIR) ->will($this->returnValue($this->tmpDirectory)); $this->assetRepo = $this->getMock('\Magento\Framework\View\Asset\Repository', [], [], '', false); $this->magentoImport = $this->getMock( - '\Magento\Framework\Less\PreProcessor\Instruction\MagentoImport', [], [], '', false + 'Magento\Framework\Less\PreProcessor\Instruction\MagentoImport', + [], + [], + '', + false ); $this->import = $this->getMock( - '\Magento\Framework\Less\PreProcessor\Instruction\Import', [], [], '', false + 'Magento\Framework\Less\PreProcessor\Instruction\Import', + [], + [], + '', + false ); $assetSource = $this->getMock( - 'Magento\Framework\View\Asset\Source', [], [], '', false + 'Magento\Framework\View\Asset\Source', + [], + [], + '', + false ); - $this->publisher = $this->getMock('Magento\Framework\App\View\Asset\Publisher', [], [], '', false); - + $this->relatedGenerator = $this->getMockBuilder('Magento\Framework\Less\FileGenerator\RelatedGenerator') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->config = $this->getMockBuilder('Magento\Framework\Less\Config') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->temporaryFile = $this->getMockBuilder('Magento\Framework\Less\File\Temporary') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); $this->object = new \Magento\Framework\Less\FileGenerator( - $filesystem, $this->assetRepo, $this->magentoImport, $this->import, $assetSource, $this->publisher + $filesystem, + $this->assetRepo, + $this->magentoImport, + $this->import, + $assetSource, + $this->relatedGenerator, + $this->config, + $this->temporaryFile ); } public function testGenerateLessFileTree() { - $originalContent = 'original content'; + $lessDirectory = 'path/to/less'; $expectedContent = 'updated content'; - $expectedRelativePath = 'view_preprocessed/less/some/file.less'; - $expectedPath = '/var/view_preprocessed/less/some/file.less'; + $expectedRelativePath = 'some/file.less'; + $expectedPath = $lessDirectory . '/some/file.less'; - $asset = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false); - $asset->expects($this->exactly(2)) - ->method('getPath') - ->will($this->returnValue('some/file.css')); - $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($asset, $originalContent, 'less'); + + $asset = $this->getMock('Magento\Framework\View\Asset\File', [], [], '', false); + $chain = $this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false); + + $this->config->expects($this->any()) + ->method('getLessDirectory') + ->willReturn($lessDirectory); + $this->tmpDirectory->expects($this->once()) + ->method('isExist') + ->willReturn(true); $this->magentoImport->expects($this->once()) ->method('process') @@ -100,59 +145,28 @@ public function testGenerateLessFileTree() $this->import->expects($this->once()) ->method('process') ->with($chain); + $this->relatedGenerator->expects($this->once()) + ->method('generate') + ->with($this->import); - $relatedAssetOne = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false); - $relatedAssetOne->expects($this->any()) + $asset->expects($this->once()) ->method('getPath') - ->will($this->returnValue('related/file_one.css')); - $relatedAssetOne->expects($this->any()) - ->method('getContent') - ->will($this->returnValue("content of 'related/file_one.css'")); - $relatedAssetTwo = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false); - $relatedAssetTwo->expects($this->any()) - ->method('getPath') - ->will($this->returnValue('related/file_two.css')); - $relatedAssetTwo->expects($this->any()) + ->will($this->returnValue('some/file.css')); + $chain->expects($this->once()) ->method('getContent') - ->will($this->returnValue("content of 'related/file_two.css'")); - $assetsMap = [ - ['related/file_one.css', $asset, $relatedAssetOne], - ['related/file_two.css', $asset, $relatedAssetTwo], - ]; - $this->assetRepo->expects($this->any()) - ->method('createRelated') - ->will($this->returnValueMap($assetsMap)); - - $relatedFilesOne = [['related/file_one.css', $asset]]; - $this->import->expects($this->at(1)) - ->method('getRelatedFiles') - ->will($this->returnValue($relatedFilesOne)); - $relatedFilesTwo = [['related/file_two.css', $asset]]; - $this->import->expects($this->at(3)) - ->method('getRelatedFiles') - ->will($this->returnValue($relatedFilesTwo)); - $this->import->expects($this->at(5)) - ->method('getRelatedFiles') - ->will($this->returnValue([])); - - $writeMap = [ - [$expectedRelativePath, $expectedContent], - ['related/file_one.css', "content of 'related/file_one.css'"], - ['related/file_two.css', "content of 'related/file_two.css'"], - ]; - $pathsMap = [ - [$expectedRelativePath, $expectedPath], - ['related/file_one.css', '/var/view_preprocessed/less/related/file_one.css'], - ['related/file_two.css', '/var/view_preprocessed/less/related/file_two.css'], - ]; - $this->tmpDirectory->expects($this->any()) - ->method('writeFile') - ->will($this->returnValueMap($writeMap)); - $this->tmpDirectory->expects($this->any()) - ->method('getAbsolutePath') - ->will($this->returnValueMap($pathsMap)); - - $actual = $this->object->generateFileTree($chain); - $this->assertSame($expectedPath, $actual); + ->willReturn($expectedContent); + $chain->expects($this->once()) + ->method('getAsset') + ->willReturn($asset); + + $this->temporaryFile->expects($this->once()) + ->method('createFile') + ->with( + $expectedRelativePath, + $expectedContent + ) + ->willReturn($expectedPath); + + $this->assertSame($expectedPath, $this->object->generateFileTree($chain)); } } From 481915ff024a0395a979817571ba2f5d305bb91a Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Fri, 20 Mar 2015 11:08:36 +0200 Subject: [PATCH 4/6] MAGETWO-35298: Deploy script modifies LESS files with "@urls-resolved: true" line(-s) - added defect --- lib/internal/Magento/Framework/Less/FileGenerator.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Less/FileGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator.php index 49102758be873..ab7141d29dcc1 100644 --- a/lib/internal/Magento/Framework/Less/FileGenerator.php +++ b/lib/internal/Magento/Framework/Less/FileGenerator.php @@ -10,6 +10,11 @@ use Magento\Framework\View\Asset\PreProcessor\Chain; use Magento\Framework\View\Asset\SourceFileGeneratorInterface; +/** + * Class FileGenerator + * @package Magento\Framework\Less + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class FileGenerator implements SourceFileGeneratorInterface { /** @@ -71,8 +76,6 @@ class FileGenerator implements SourceFileGeneratorInterface * @param FileGenerator\RelatedGenerator $relatedGenerator * @param Config $config * @param File\Temporary $temporaryFile - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ public function __construct( \Magento\Framework\Filesystem $filesystem, From 90a817fe5f34a1c6196fa131a1c8d75dd539644b Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Fri, 20 Mar 2015 17:05:17 +0200 Subject: [PATCH 5/6] MAGETWO-35298: Deploy script modifies LESS files with "@urls-resolved: true" line(-s) - added core less file publication --- .../Tools/Webdev/App/FileAssembler.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php index 4378f36cd0efa..d55fe20573e72 100644 --- a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php +++ b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php @@ -9,6 +9,7 @@ use Magento\Framework\App; use Magento\Framework\App\State; use Magento\Framework\AppInterface; +use Magento\Framework\Filesystem; use Magento\Tools\Webdev\CliParams; use Magento\Tools\View\Deployer\Log; use Magento\Framework\View\Asset\Source; @@ -18,6 +19,7 @@ use Magento\Framework\App\ObjectManager\ConfigLoader; use Magento\Framework\View\Asset\SourceFileGeneratorPool; use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; +use Magento\Framework\App\Filesystem\DirectoryList; /** * Class FileAssembler @@ -77,6 +79,11 @@ class FileAssembler implements AppInterface */ private $chainFactory; + /** + * @var Filesystem + */ + private $filesystem; + /** * @param ObjectManagerInterface $objectManager * @param Response $response @@ -88,6 +95,7 @@ class FileAssembler implements AppInterface * @param \Magento\Framework\View\Asset\SourceFileGeneratorPool $sourceFileGeneratorPoll * @param \Magento\Tools\View\Deployer\Log $logger * @param ChainFactoryInterface $chainFactory + * @param Filesystem $filesystem, * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -101,7 +109,8 @@ public function __construct( Source $assetSource, SourceFileGeneratorPool $sourceFileGeneratorPoll, Log $logger, - ChainFactoryInterface $chainFactory + ChainFactoryInterface $chainFactory, + Filesystem $filesystem ) { $this->response = $response; $this->params = $params; @@ -113,6 +122,7 @@ public function __construct( $this->assetSource = $assetSource; $this->logger = $logger; $this->chainFactory = $chainFactory; + $this->filesystem = $filesystem; } /** @@ -152,7 +162,13 @@ public function launch() ] ); - $sourceFileGenerator->generateFileTree($chain); + $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); + + $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); + $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); + $source = $rootDir->getRelativePath($processedCoreFile); + $destination = $asset->getPath(); + $rootDir->copyFile($source, $destination, $targetDir); $this->logger->logMessage("Done"); } From 71dca9bee08e88a561ef8c49f48f26bb77d8d96d Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Fri, 20 Mar 2015 17:17:43 +0200 Subject: [PATCH 6/6] MAGETWO-35298: Deploy script modifies LESS files with "@urls-resolved: true" line(-s) - coma removed --- dev/tools/Magento/Tools/Webdev/App/FileAssembler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php index d55fe20573e72..0a07540a19c94 100644 --- a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php +++ b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php @@ -95,7 +95,7 @@ class FileAssembler implements AppInterface * @param \Magento\Framework\View\Asset\SourceFileGeneratorPool $sourceFileGeneratorPoll * @param \Magento\Tools\View\Deployer\Log $logger * @param ChainFactoryInterface $chainFactory - * @param Filesystem $filesystem, + * @param Filesystem $filesystem * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */