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 0000000000000000000000000000000000000000..d99f32d515e38db2784169e6f21c5fa0fe4034ed
--- /dev/null
+++ b/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Developer\Model\Less\FileGenerator;
+
+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
+{
+    /**
+     * @var \Magento\Framework\App\View\Asset\Publisher
+     */
+    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\File\Temporary $temporaryFile,
+        \Magento\Framework\App\View\Asset\Publisher $publisher
+    ) {
+        parent::__construct($filesystem, $assetRepo, $temporaryFile);
+        $this->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 a3da2e85a1954b11a9415d002266b285fad6b676..cb45113bb261c8ce90486a5a1d4be251fc658744 100755
--- a/app/etc/di.xml
+++ b/app/etc/di.xml
@@ -557,13 +557,6 @@
             <argument name="publisher" xsi:type="object">developerPublisher</argument>
         </arguments>
     </type>
-    <type name="Magento\Framework\View\Asset\SourceFileGeneratorPool">
-        <arguments>
-            <argument name="fileGeneratorTypes" xsi:type="array">
-                <item name="less" xsi:type="object">Magento\Framework\Less\FileGenerator</item>
-            </argument>
-        </arguments>
-    </type>
     <virtualType name="developerPublisher" type="Magento\Framework\App\View\Asset\Publisher">
         <arguments>
             <argument name="materializationStrategyFactory" xsi:type="object">developerMaterialization</argument>
@@ -577,24 +570,23 @@
             </argument>
         </arguments>
     </virtualType>
-    <virtualType name="lessFileGeneratorMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
+    <type name="Magento\Framework\View\Asset\SourceFileGeneratorPool">
         <arguments>
-            <argument name="strategiesList" xsi:type="array">
-                <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
-                <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
+            <argument name="fileGeneratorTypes" xsi:type="array">
+                <item name="less" xsi:type="object">fileassemblerFileGenerator</item>
             </argument>
         </arguments>
-    </virtualType>
-    <virtualType name="lessFileGeneratorPublisher" type="Magento\Framework\App\View\Asset\Publisher">
+    </type>
+    <virtualType name="fileassemblerFileGenerator" type="Magento\Framework\Less\FileGenerator">
         <arguments>
-            <argument name="materializationStrategyFactory" xsi:type="object">lessFileGeneratorMaterialization</argument>
+            <argument name="relatedGenerator" xsi:type="object">fileassemblerRelatedFilesGenerator</argument>
         </arguments>
     </virtualType>
-    <type name="Magento\Framework\Less\FileGenerator">
+    <virtualType name="fileassemblerRelatedFilesGenerator" type="Magento\Developer\Model\Less\FileGenerator\PublicationDecorator">
         <arguments>
-            <argument name="publisher" xsi:type="object">lessFileGeneratorPublisher</argument>
+            <argument name="publisher" xsi:type="object">developerPublisher</argument>
         </arguments>
-    </type>
+    </virtualType>
     <virtualType name="fallbackResolverSimpleWithGroupedCache" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple">
         <arguments>
             <argument name="cache" xsi:type="object">Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Grouped</argument>
diff --git a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php
index fb8529dd7596966ce189816f5276a222fb7bd4fa..0a07540a19c94695f0a9454f0f5f4b3b86c12182 100644
--- a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php
+++ b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php
@@ -9,6 +9,7 @@ namespace Magento\Tools\Webdev\App;
 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\ObjectManagerInterface;
 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
@@ -60,7 +62,7 @@ class FileAssembler implements AppInterface
     /**
      * @var \Magento\Framework\Less\FileGenerator
      */
-    private $sourceFileGeneratorPoll;
+    private $sourceFileGeneratorPool;
 
     /**
      * @var \Magento\Framework\View\Asset\Source
@@ -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 @@ class FileAssembler implements AppInterface
         Source $assetSource,
         SourceFileGeneratorPool $sourceFileGeneratorPoll,
         Log $logger,
-        ChainFactoryInterface $chainFactory
+        ChainFactoryInterface $chainFactory,
+        Filesystem $filesystem
     ) {
         $this->response = $response;
         $this->params = $params;
@@ -109,10 +118,11 @@ class FileAssembler implements AppInterface
         $this->objectManager = $objectManager;
         $this->configLoader = $configLoader;
         $this->assetRepo = $assetRepo;
-        $this->sourceFileGeneratorPoll = $sourceFileGeneratorPoll;
+        $this->sourceFileGeneratorPool = $sourceFileGeneratorPoll;
         $this->assetSource = $assetSource;
         $this->logger = $logger;
         $this->chainFactory = $chainFactory;
+        $this->filesystem = $filesystem;
     }
 
     /**
@@ -125,7 +135,7 @@ class FileAssembler implements AppInterface
         $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();
@@ -152,7 +162,13 @@ class FileAssembler implements AppInterface
                 ]
             );
 
-            $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");
         }
diff --git a/dev/tools/Magento/Tools/Webdev/file_assembler.php b/dev/tools/Magento/Tools/Webdev/file_assembler.php
index 72ec5b0458fdf12637221079aca0457872a60bb4..669ffa8d535856606b1a86ebbf5d0882aa99f353 100644
--- a/dev/tools/Magento/Tools/Webdev/file_assembler.php
+++ b/dev/tools/Magento/Tools/Webdev/file_assembler.php
@@ -35,15 +35,15 @@ try {
     $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
new file mode 100644
index 0000000000000000000000000000000000000000..88f6c27e9ee412d67f4c414f5165e449ed42fa14
--- /dev/null
+++ b/lib/internal/Magento/Framework/Less/Config.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\Less;
+
+use Magento\Framework\App\Filesystem\DirectoryList;
+
+class Config
+{
+    /**
+     * Temporary directory prefix
+     */
+    const TMP_LESS_DIR = 'less';
+
+    /**
+     * 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
new file mode 100644
index 0000000000000000000000000000000000000000..8da016ecde585d76b509d3e4f74e3ca9069de16a
--- /dev/null
+++ b/lib/internal/Magento/Framework/Less/File/Temporary.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\Less\File;
+
+use Magento\Framework\App\Filesystem\DirectoryList;
+use Magento\Framework\Filesystem;
+use Magento\Framework\Less\Config;
+
+class Temporary
+{
+    /**
+     * @var Config
+     */
+    private $config;
+
+    /**
+     * @var Filesystem\Directory\WriteInterface
+     */
+    private $tmpDirectory;
+
+    /**
+     * @param Filesystem $filesystem
+     * @param Config $config
+     */
+    public function __construct(
+        Filesystem $filesystem,
+        Config $config
+    ) {
+        $this->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->getLessMaterializationRelativePath() . '/' . $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 f45d462e7eaaeeff23b95633c658bf40d526f650..ab7141d29dcc196d32324778d6e8df1b114fc747 100644
--- a/lib/internal/Magento/Framework/Less/FileGenerator.php
+++ b/lib/internal/Magento/Framework/Less/FileGenerator.php
@@ -7,17 +7,16 @@
 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
+ * @package Magento\Framework\Less
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
+ */
 class FileGenerator implements SourceFileGeneratorInterface
 {
-    /**
-     * Temporary directory prefix
-     */
-    const TMP_LESS_DIR = 'less';
-
     /**
      * Max execution (locking) time for generation process (in seconds)
      */
@@ -28,11 +27,6 @@ class FileGenerator implements SourceFileGeneratorInterface
      */
     const LOCK_FILE = 'less.lock';
 
-    /**
-     * @var string
-     */
-    protected $lessDirectory;
-
     /**
      * @var \Magento\Framework\Filesystem\Directory\WriteInterface
      */
@@ -59,17 +53,29 @@ class FileGenerator implements SourceFileGeneratorInterface
     private $importProcessor;
 
     /**
-     * @var \Magento\Framework\App\View\Asset\Publisher
+     * @var FileGenerator\RelatedGenerator
+     */
+    private $relatedGenerator;
+
+    /**
+     * @var Config
      */
-    private $publisher;
+    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 +83,19 @@ class FileGenerator implements SourceFileGeneratorInterface
         \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 +117,14 @@ class FileGenerator implements SourceFileGeneratorInterface
         while ($this->isProcessLocked()) {
             sleep(1);
         }
-        $lockFilePath = $this->lessDirectory . '/' . self::LOCK_FILE;
+        $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE;
         $this->tmpDirectory->writeFile($lockFilePath, time());
 
         $this->magentoImportProcessor->process($chain);
         $this->importProcessor->process($chain);
-        $this->generateRelatedFiles();
+        $this->relatedGenerator->generate($this->importProcessor);
         $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 +137,7 @@ class FileGenerator implements SourceFileGeneratorInterface
      */
     protected function isProcessLocked()
     {
-        $lockFilePath = $this->lessDirectory . '/' . 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) {
@@ -142,69 +148,4 @@ class FileGenerator implements SourceFileGeneratorInterface
         }
         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 0000000000000000000000000000000000000000..64564ce4c0e9f3221710fe44a40bb316db4d7cf1
--- /dev/null
+++ b/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+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
+{
+    /**
+     * @var \Magento\Framework\Filesystem\Directory\WriteInterface
+     */
+    protected $tmpDirectory;
+
+    /**
+     * @var \Magento\Framework\View\Asset\Repository
+     */
+    private $assetRepo;
+
+    /**
+     * @var \Magento\Framework\Less\File\Temporary
+     */
+    private $temporaryFile;
+
+    /**
+     * @param \Magento\Framework\Filesystem $filesystem
+     * @param \Magento\Framework\View\Asset\Repository $assetRepo
+     * @param \Magento\Framework\Less\File\Temporary $temporaryFile
+     */
+    public function __construct(
+        \Magento\Framework\Filesystem $filesystem,
+        \Magento\Framework\View\Asset\Repository $assetRepo,
+        \Magento\Framework\Less\File\Temporary $temporaryFile
+    ) {
+        $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
+        $this->assetRepo = $assetRepo;
+
+        $this->temporaryFile = $temporaryFile;
+    }
+
+    /**
+     * Create all asset files, referenced from already processed ones
+     *
+     * @param Import $importGenerator
+     *
+     * @return void
+     */
+    public function generate(Import $importGenerator)
+    {
+        do {
+            $relatedFiles = $importGenerator->getRelatedFiles();
+            $importGenerator->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;
+    }
+}
diff --git a/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php b/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php
index 60293981b8f761c070b06930b9461640e90b450b..f5985fbd30f6042f10cc4bed359f95453521d678 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 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase
         $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));
     }
 }