public function testExecute() { $file = 'css/styles-m' . '.less'; $this->configLoader->expects($this->once())->method('load')->with('frontend')->willReturn([]); $this->objectManager->expects($this->once())->method('configure'); $this->sourceFileGeneratorPool->expects($this->once())->method('create')->with('less')->willReturn($this->getMock('Magento\\Framework\\Less\\FileGenerator', [], [], '', false)); $this->assetRepo->expects($this->once())->method('createAsset')->with($file, ['area' => 'frontend', 'theme' => 'Magento/blank', 'locale' => 'en_US'])->willReturn($this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\LocalInterface')); $this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null'); $this->chainFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false)); $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface', [], [], '', false)); $this->validator->expects($this->once())->method('isValid')->with('en_US')->willReturn(true); $commandTester = new CommandTester($this->command); $commandTester->execute(['type' => 'less']); $this->assertContains('Successfully processed LESS and/or SASS files', $commandTester->getDisplay()); }
/** * {@inheritdoc} * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $locale = $input->getOption(self::LOCALE_OPTION); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } $area = $input->getOption(self::AREA_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getArgument(self::TYPE_ARGUMENT); $this->state->setAreaCode($area); $this->objectManager->configure($this->configLoader->load($area)); $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type); foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) { $file .= '.' . $type; $output->writeln("<info>Gathering {$file} sources.</info>"); $asset = $this->assetRepo->createAsset($file, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); $sourceFile = $this->assetSource->findSource($asset); $relativePath = $rootDir->getRelativePath($sourceFile); $content = $rootDir->readFile($relativePath); $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType(), 'origAssetPath' => $relativePath]); $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); $source = $rootDir->getRelativePath($processedCoreFile); $destination = $asset->getPath(); $rootDir->copyFile($source, $destination, $targetDir); $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>"); } }