diff --git a/app/code/Magento/Deploy/Collector/Collector.php b/app/code/Magento/Deploy/Collector/Collector.php index c2e7a14572254..b02c8e478d639 100644 --- a/app/code/Magento/Deploy/Collector/Collector.php +++ b/app/code/Magento/Deploy/Collector/Collector.php @@ -11,11 +11,9 @@ use Magento\Framework\View\Asset\PreProcessor\FileNameResolver; /** - * Class Collector + * Deployable files collector * - * Default implementation uses Source Pool object which provides collection of static files sources - * - * @see SourcePool + * Default implementation uses Source Pool object (@see SourcePool) */ class Collector implements CollectorInterface { diff --git a/app/code/Magento/Deploy/Collector/CollectorInterface.php b/app/code/Magento/Deploy/Collector/CollectorInterface.php index f8afd3928ba99..ea9046e5af4c8 100644 --- a/app/code/Magento/Deploy/Collector/CollectorInterface.php +++ b/app/code/Magento/Deploy/Collector/CollectorInterface.php @@ -11,8 +11,6 @@ * Interface CollectorInterface * * Collector returns packages with files which share same properties (e.g. area, theme, locale, etc) - * - * @api */ interface CollectorInterface { diff --git a/app/code/Magento/Deploy/Config/BundleConfig.php b/app/code/Magento/Deploy/Config/BundleConfig.php index b175754a22d49..71a6a05dcbff9 100644 --- a/app/code/Magento/Deploy/Config/BundleConfig.php +++ b/app/code/Magento/Deploy/Config/BundleConfig.php @@ -9,11 +9,9 @@ use Magento\Framework\View\Design\Theme\ThemeProviderInterface; /** - * Class BundleConfig + * Static files bundling configuration * * Use this to get configuration settings related to JavaScript built-in bundling - * - * @api */ class BundleConfig { diff --git a/app/code/Magento/Deploy/Console/ConsoleLogger.php b/app/code/Magento/Deploy/Console/ConsoleLogger.php index 5b95315f8bb99..a7d3b48fde130 100644 --- a/app/code/Magento/Deploy/Console/ConsoleLogger.php +++ b/app/code/Magento/Deploy/Console/ConsoleLogger.php @@ -15,9 +15,7 @@ use Magento\Framework\Filesystem\Directory\ReadInterface; /** - * Class ConsoleLogger - * - * @api + * PSR logger implementation for CLI */ class ConsoleLogger extends AbstractLogger { diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticOptions.php b/app/code/Magento/Deploy/Console/DeployStaticOptions.php similarity index 92% rename from app/code/Magento/Deploy/Console/Command/DeployStaticOptions.php rename to app/code/Magento/Deploy/Console/DeployStaticOptions.php index 27bb65afbf7be..825ea19b67b97 100644 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticOptions.php +++ b/app/code/Magento/Deploy/Console/DeployStaticOptions.php @@ -4,18 +4,16 @@ * See COPYING.txt for license details. */ -namespace Magento\Deploy\Console\Command; +namespace Magento\Deploy\Console; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; /** - * Class DeployStaticOptions + * Static Content Deployment Options helper * * This class contains the list options and their related constants, - * which must be used to refer to static content deployment CLI commands arguments. - * - * @api + * which can be used for static content deployment CLI command */ class DeployStaticOptions { @@ -132,9 +130,18 @@ class DeployStaticOptions * Deploy static command options list * * @return array - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getOptionsList() + { + return array_merge($this->getBasicOptions(), $this->getSkipOptions()); + } + + /** + * Basic options + * + * @return array + */ + private function getBasicOptions() { return [ new InputOption( @@ -144,52 +151,25 @@ public function getOptionsList() 'Deploy files in any mode.' ), new InputOption( - self::NO_JAVASCRIPT, - null, - InputOption::VALUE_NONE, - 'Do not deploy JavaScript files.' - ), - new InputOption( - self::NO_CSS, - null, - InputOption::VALUE_NONE, - 'Do not deploy CSS files.' - ), - new InputOption( - self::NO_LESS, - null, - InputOption::VALUE_NONE, - 'Do not deploy LESS files.' - ), - new InputOption( - self::NO_IMAGES, - null, - InputOption::VALUE_NONE, - 'Do not deploy images.' - ), - new InputOption( - self::NO_FONTS, - null, - InputOption::VALUE_NONE, - 'Do not deploy font files.' - ), - new InputOption( - self::NO_HTML, - null, - InputOption::VALUE_NONE, - 'Do not deploy HTML files.' + self::STRATEGY, + '-s', + InputOption::VALUE_OPTIONAL, + 'Deploy files using specified strategy.', + 'quick' ), new InputOption( - self::NO_MISC, - null, - InputOption::VALUE_NONE, - 'Do not deploy files of other types (.md, .jbf, .csv, etc.).' + self::AREA, + '-a', + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'Generate files only for the specified areas.', + ['all'] ), new InputOption( - self::NO_HTML_MINIFY, + self::EXCLUDE_AREA, null, - InputOption::VALUE_NONE, - 'Do not minify HTML files.' + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'Do not generate files for the specified areas.', + ['none'] ), new InputOption( self::THEME, @@ -219,20 +199,6 @@ public function getOptionsList() 'Do not generate files for the specified languages.', ['none'] ), - new InputOption( - self::AREA, - '-a', - InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, - 'Generate files only for the specified areas.', - ['all'] - ), - new InputOption( - self::EXCLUDE_AREA, - null, - InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, - 'Do not generate files for the specified areas.', - ['none'] - ), new InputOption( self::JOBS_AMOUNT, '-j', @@ -247,13 +213,6 @@ public function getOptionsList() 'Create symlinks for the files of those locales, which are passed for deployment, ' . 'but have no customizations' ), - new InputOption( - self::STRATEGY, - '-s', - InputOption::VALUE_OPTIONAL, - 'Deploy files using specified strategy.', - 'quick' - ), new InputArgument( self::LANGUAGES_ARGUMENT, InputArgument::IS_ARRAY, @@ -261,4 +220,65 @@ public function getOptionsList() ), ]; } + + /** + * Additional options + * + * Used to re-deploy specific types of static files + * + * @return array + */ + private function getSkipOptions() + { + return [ + new InputOption( + self::NO_JAVASCRIPT, + null, + InputOption::VALUE_NONE, + 'Do not deploy JavaScript files.' + ), + new InputOption( + self::NO_CSS, + null, + InputOption::VALUE_NONE, + 'Do not deploy CSS files.' + ), + new InputOption( + self::NO_LESS, + null, + InputOption::VALUE_NONE, + 'Do not deploy LESS files.' + ), + new InputOption( + self::NO_IMAGES, + null, + InputOption::VALUE_NONE, + 'Do not deploy images.' + ), + new InputOption( + self::NO_FONTS, + null, + InputOption::VALUE_NONE, + 'Do not deploy font files.' + ), + new InputOption( + self::NO_HTML, + null, + InputOption::VALUE_NONE, + 'Do not deploy HTML files.' + ), + new InputOption( + self::NO_MISC, + null, + InputOption::VALUE_NONE, + 'Do not deploy files of other types (.md, .jbf, .csv, etc.).' + ), + new InputOption( + self::NO_HTML_MINIFY, + null, + InputOption::VALUE_NONE, + 'Do not minify HTML files.' + ) + ]; + } } diff --git a/app/code/Magento/Deploy/Console/InputValidator.php b/app/code/Magento/Deploy/Console/InputValidator.php index c6638bbc7bd80..b3301f60fec26 100644 --- a/app/code/Magento/Deploy/Console/InputValidator.php +++ b/app/code/Magento/Deploy/Console/InputValidator.php @@ -6,14 +6,12 @@ namespace Magento\Deploy\Console; use Magento\Setup\Console\Command\DeployStaticContentCommand; -use Magento\Deploy\Console\Command\DeployStaticOptions as Options; +use Magento\Deploy\Console\DeployStaticOptions as Options; use Magento\Framework\Validator\Locale; use Symfony\Component\Console\Input\InputInterface; /** - * Class InputValidator - * - * @api + * Command input arguments validator class */ class InputValidator { @@ -84,7 +82,7 @@ public function validate(InputInterface $input) $input->getOption(Options::EXCLUDE_THEME) ); $this->checkLanguagesInput( - $input->getArgument(DeployStaticContentCommand::LANGUAGES_ARGUMENT) ?: ['all'], + $input->getArgument(Options::LANGUAGES_ARGUMENT) ?: ['all'], $input->getOption(Options::EXCLUDE_LANGUAGE) ); } diff --git a/app/code/Magento/Deploy/Model/Deploy/DeployInterface.php b/app/code/Magento/Deploy/Model/Deploy/DeployInterface.php deleted file mode 100644 index d12cc18b2e968..0000000000000 --- a/app/code/Magento/Deploy/Model/Deploy/DeployInterface.php +++ /dev/null @@ -1,28 +0,0 @@ -assetRepo = $assetRepo; - $this->assetPublisher = $assetPublisher; - $this->translationJsConfig = $translationJsConfig; - $this->translator = $translator; - $this->output = $output; - } - - /** - * {@inheritdoc} - */ - public function deploy($area, $themePath, $locale) - { - $this->translator->setLocale($locale); - $this->translator->loadData($area, true); - - $asset = $this->assetRepo->createAsset( - $this->translationJsConfig->getDictionaryFileName(), - ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'publish' => true] - ); - if ($this->output->isVeryVerbose()) { - $this->output->writeln("\tDeploying the file to '{$asset->getPath()}'"); - } else { - $this->output->write('.'); - } - - $this->assetPublisher->publish($asset); - - return Cli::RETURN_SUCCESS; - } -} diff --git a/app/code/Magento/Deploy/Model/Deploy/LocaleDeploy.php b/app/code/Magento/Deploy/Model/Deploy/LocaleDeploy.php deleted file mode 100644 index 8b20ecd429ec9..0000000000000 --- a/app/code/Magento/Deploy/Model/Deploy/LocaleDeploy.php +++ /dev/null @@ -1,450 +0,0 @@ -output = $output; - $this->assetRepo = $assetRepo; - $this->assetPublisher = $assetPublisher; - $this->bundleManager = $bundleManager; - $this->filesUtil = $filesUtil; - $this->jsTranslationConfig = $jsTranslationConfig; - $this->minification = $minification; - $this->logger = $logger; - $this->assetRepoFactory = $assetRepoFactory; - $this->fileManagerFactory = $fileManagerFactory; - $this->requireJsConfigFactory = $requireJsConfigFactory; - $this->themeProvider = $themeProvider; - $this->alternativeSources = array_map( - function (AlternativeSourceInterface $alternativeSource) { - return $alternativeSource; - }, - $alternativeSources - ); - $this->designFactory = $designFactory; - $this->localeResolver = $localeResolver; - $this->options = $options; - } - - /** - * {@inheritdoc} - */ - public function deploy($area, $themePath, $locale) - { - $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); - - // emulate application locale needed for correct file path resolving - $this->localeResolver->setLocale($locale); - - $this->deployRequireJsConfig($area, $themePath); - $this->deployAppFiles($area, $themePath, $locale); - $this->deployLibFiles($area, $themePath, $locale); - - if (!$this->getOption(Options::NO_JAVASCRIPT)) { - if ($this->jsTranslationConfig->dictionaryEnabled()) { - $dictionaryFileName = $this->jsTranslationConfig->getDictionaryFileName(); - $this->deployFile($dictionaryFileName, $area, $themePath, $locale, null); - } - } - if (!$this->getOption(Options::NO_JAVASCRIPT)) { - $this->bundleManager->flush(); - } - $this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n"); - - return $this->errorCount ? Cli::RETURN_FAILURE : Cli::RETURN_SUCCESS; - } - - /** - * @param string $area - * @param string $themePath - * @return void - */ - private function deployRequireJsConfig($area, $themePath) - { - if (!$this->getOption(Options::DRY_RUN) && !$this->getOption(Options::NO_JAVASCRIPT)) { - - /** @var \Magento\Framework\View\Design\ThemeInterface $theme */ - $theme = $this->getThemeList()->getThemeByFullPath($area . '/' . $themePath); - $design = $this->designFactory->create()->setDesignTheme($theme, $area); - $assetRepo = $this->assetRepoFactory->create(['design' => $design]); - /** @var \Magento\RequireJs\Model\FileManager $fileManager */ - $fileManager = $this->fileManagerFactory->create( - [ - 'config' => $this->requireJsConfigFactory->create( - [ - 'assetRepo' => $assetRepo, - 'design' => $design, - ] - ), - 'assetRepo' => $assetRepo, - ] - ); - $fileManager->createRequireJsConfigAsset(); - if ($this->minification->isEnabled('js')) { - $fileManager->createMinResolverAsset(); - } - } - } - - /** - * @param string $area - * @param string $themePath - * @param string $locale - * @return void - */ - private function deployAppFiles($area, $themePath, $locale) - { - foreach ($this->filesUtil->getStaticPreProcessingFiles() as $info) { - list($fileArea, $fileTheme, , $module, $filePath, $fullPath) = $info; - - if ($this->checkSkip($filePath)) { - continue; - } - - if ($this->isCanBeDeployed($fileArea, $fileTheme, $area, $themePath)) { - $compiledFile = $this->deployFile( - $filePath, - $area, - $themePath, - $locale, - $module, - $fullPath - ); - if ($compiledFile !== '' && !$this->checkSkip($compiledFile)) { - $this->deployFile($compiledFile, $area, $themePath, $locale, $module, $fullPath); - } - } - } - } - - /** - * @param string $fileArea - * @param string $fileTheme - * @param string $area - * @param string $themePath - * @return bool - */ - private function isCanBeDeployed($fileArea, $fileTheme, $area, $themePath) - { - return ($fileArea == $area || $fileArea == Package::BASE_AREA) - && ($fileTheme == '' || $fileTheme == $themePath - || in_array( - $fileArea . Theme::THEME_PATH_SEPARATOR . $fileTheme, - $this->findAncestors($area . Theme::THEME_PATH_SEPARATOR . $themePath) - ) - ); - } - - /** - * @param string $area - * @param string $themePath - * @param string $locale - * @return void - */ - private function deployLibFiles($area, $themePath, $locale) - { - foreach ($this->filesUtil->getStaticLibraryFiles() as $filePath) { - if ($this->checkSkip($filePath)) { - continue; - } - - $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, null); - - if ($compiledFile !== '' && !$this->checkSkip($compiledFile)) { - $this->deployFile($compiledFile, $area, $themePath, $locale, null); - } - } - } - - /** - * Deploy a static view file - * - * @param string $filePath - * @param string $area - * @param string $themePath - * @param string $locale - * @param string $module - * @param string|null $fullPath - * @return string - * - * @SuppressWarnings(PHPMD.NPathComplexity) - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - */ - private function deployFile($filePath, $area, $themePath, $locale, $module, $fullPath = null) - { - $compiledFile = ''; - $extension = pathinfo($filePath, PATHINFO_EXTENSION); - - foreach ($this->alternativeSources as $name => $alternative) { - if (in_array($extension, $alternative->getAlternativesExtensionsNames(), true) - && strpos(basename($filePath), '_') !== 0 - ) { - $compiledFile = substr($filePath, 0, strlen($filePath) - strlen($extension) - 1); - $compiledFile = $compiledFile . '.' . $name; - } - } - - if ($this->output->isVeryVerbose()) { - $logMessage = "Processing file '$filePath' for area '$area', theme '$themePath', locale '$locale'"; - if ($module) { - $logMessage .= ", module '$module'"; - } - $this->output->writeln($logMessage); - } - - try { - $asset = $this->assetRepo->createAsset( - $filePath, - ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module, 'publish' => true] - ); - if ($this->output->isVeryVerbose()) { - $this->output->writeln("\tDeploying the file to '{$asset->getPath()}'"); - } else { - $this->output->write('.'); - } - if ($this->getOption(Options::DRY_RUN)) { - $asset->getContent(); - } else { - $this->assetPublisher->publish($asset); - if (!$this->getOption(Options::NO_JAVASCRIPT)) { - $this->bundleManager->addAsset($asset); - } - } - $this->count++; - } catch (ContentProcessorException $exception) { - $pathInfo = $fullPath ?: $filePath; - $errorMessage = __('Compilation from source: ') . $pathInfo . PHP_EOL . $exception->getMessage(); - $this->errorCount++; - $this->output->write(PHP_EOL . PHP_EOL . $errorMessage . PHP_EOL, true); - - $this->logger->critical($errorMessage); - } catch (\Exception $exception) { - $this->output->write('.'); - if ($this->output->isVerbose()) { - $this->output->writeln($exception->getTraceAsString()); - } - $this->errorCount++; - } - - return $compiledFile; - } - - /** - * @param string $name - * @return mixed|null - */ - private function getOption($name) - { - return isset($this->options[$name]) ? $this->options[$name] : null; - } - - /** - * Check if skip flag is affecting file by extension - * - * @param string $filePath - * @return boolean - */ - private function checkSkip($filePath) - { - if ($filePath != '.') { - $ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); - $option = isset(InputValidator::$fileExtensionOptionMap[$ext]) - ? InputValidator::$fileExtensionOptionMap[$ext] - : null; - - return $option ? $this->getOption($option) : false; - } - - return false; - } - - /** - * Find ancestor themes' full paths - * - * @param string $themeFullPath - * @return string[] - */ - private function findAncestors($themeFullPath) - { - $theme = $this->themeProvider->getThemeByFullPath($themeFullPath); - $ancestors = $theme->getInheritedThemes(); - $ancestorThemeFullPath = []; - foreach ($ancestors as $ancestor) { - $ancestorThemeFullPath[] = $ancestor->getFullPath(); - } - return $ancestorThemeFullPath; - } - - /** - * @deprecated - * @return ListInterface - */ - private function getThemeList() - { - if ($this->themeList === null) { - $this->themeList = ObjectManager::getInstance()->get(ListInterface::class); - } - return $this->themeList; - } -} diff --git a/app/code/Magento/Deploy/Model/Deploy/LocaleQuickDeploy.php b/app/code/Magento/Deploy/Model/Deploy/LocaleQuickDeploy.php deleted file mode 100644 index b61d3e3ae0702..0000000000000 --- a/app/code/Magento/Deploy/Model/Deploy/LocaleQuickDeploy.php +++ /dev/null @@ -1,218 +0,0 @@ -filesystem = $filesystem; - $this->output = $output; - $this->options = $options; - $this->translationJsConfig = $translationJsConfig - ?: ObjectManager::getInstance()->get(TranslationJsConfig::class); - $this->deployStrategyFactory = $deployStrategyFactory - ?: ObjectManager::getInstance()->get(DeployStrategyFactory::class); - } - - /** - * @return WriteInterface - */ - private function getStaticDirectory() - { - if ($this->staticDirectory === null) { - $this->staticDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); - } - - return $this->staticDirectory; - } - - /** - * {@inheritdoc} - */ - public function deploy($area, $themePath, $locale) - { - if (!empty($this->options[Options::DRY_RUN])) { - return Cli::RETURN_SUCCESS; - } - - $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); - - if (empty($this->options[self::DEPLOY_BASE_LOCALE])) { - throw new \InvalidArgumentException('Deploy base locale must be set for Quick Deploy'); - } - $processedFiles = 0; - $errorAmount = 0; - - $baseLocale = $this->options[self::DEPLOY_BASE_LOCALE]; - $newLocalePath = $this->getLocalePath($area, $themePath, $locale); - $baseLocalePath = $this->getLocalePath($area, $themePath, $baseLocale); - - $this->deleteLocaleResource($newLocalePath); - - if (!empty($this->options[Options::SYMLINK_LOCALE])) { - $this->getStaticDirectory()->createSymlink($baseLocalePath, $newLocalePath); - $this->output->writeln("\nSuccessful symlinked\n---\n"); - } else { - $localeFiles = $this->getStaticDirectory()->readRecursively($baseLocalePath); - $jsDictionaryEnabled = $this->translationJsConfig->dictionaryEnabled(); - foreach ($localeFiles as $path) { - if ($this->getStaticDirectory()->isFile($path)) { - if (!$jsDictionaryEnabled || !$this->isJsDictionary($path)) { - $destination = $this->replaceLocaleInPath($path, $baseLocale, $locale); - $this->getStaticDirectory()->copyFile($path, $destination); - $processedFiles++; - } - } - } - - if ($jsDictionaryEnabled) { - $this->getDeploy( - DeployStrategyFactory::DEPLOY_STRATEGY_JS_DICTIONARY, - [ - 'output' => $this->output, - 'translationJsConfig' => $this->translationJsConfig - ] - ) - ->deploy($area, $themePath, $locale); - $processedFiles++; - } - - $this->output->writeln("\nSuccessful copied: {$processedFiles} files; errors: {$errorAmount}\n---\n"); - } - - return Cli::RETURN_SUCCESS; - } - - /** - * Get deploy strategy according to required strategy - * - * @param string $strategy - * @param array $params - * @return DeployInterface - */ - private function getDeploy($strategy, $params) - { - if (empty($this->deploys[$strategy])) { - $this->deploys[$strategy] = $this->deployStrategyFactory->create($strategy, $params); - } - return $this->deploys[$strategy]; - } - - /** - * Define if provided path is js dictionary - * - * @param string $path - * @return bool - */ - private function isJsDictionary($path) - { - return strpos($path, $this->translationJsConfig->getDictionaryFileName()) !== false; - } - - /** - * @param string $path - * @return void - */ - private function deleteLocaleResource($path) - { - if ($this->getStaticDirectory()->isExist($path)) { - $absolutePath = $this->getStaticDirectory()->getAbsolutePath($path); - if (is_link($absolutePath)) { - $this->getStaticDirectory()->getDriver()->deleteFile($absolutePath); - } else { - $this->getStaticDirectory()->getDriver()->deleteDirectory($absolutePath); - } - } - } - - /** - * @param string $path - * @param string $search - * @param string $replace - * @return string - */ - private function replaceLocaleInPath($path, $search, $replace) - { - return preg_replace('~' . $search . '~', $replace, $path, 1); - } - - /** - * @param string $area - * @param string $themePath - * @param string $locale - * @return string - */ - private function getLocalePath($area, $themePath, $locale) - { - return $area . DIRECTORY_SEPARATOR . $themePath . DIRECTORY_SEPARATOR . $locale; - } -} diff --git a/app/code/Magento/Deploy/Model/Deploy/TemplateMinifier.php b/app/code/Magento/Deploy/Model/Deploy/TemplateMinifier.php deleted file mode 100644 index e5c4a790304a6..0000000000000 --- a/app/code/Magento/Deploy/Model/Deploy/TemplateMinifier.php +++ /dev/null @@ -1,54 +0,0 @@ -filesUtils = $filesUtils; - $this->htmlMinifier = $htmlMinifier; - } - - /** - * Minify template files - * @return int - */ - public function minifyTemplates() - { - $minified = 0; - foreach ($this->filesUtils->getPhtmlFiles(false, false) as $template) { - $this->htmlMinifier->minify($template); - $minified++; - } - return $minified; - } -} diff --git a/app/code/Magento/Deploy/Model/DeployManager.php b/app/code/Magento/Deploy/Model/DeployManager.php deleted file mode 100644 index d9b317e54d5a9..0000000000000 --- a/app/code/Magento/Deploy/Model/DeployManager.php +++ /dev/null @@ -1,208 +0,0 @@ -output = $output; - $this->options = $options; - $this->versionStorage = $versionStorage; - $this->deployStrategyProviderFactory = $deployStrategyProviderFactory; - $this->processQueueManagerFactory = $processQueueManagerFactory; - $this->templateMinifier = $templateMinifier; - $this->state = $state; - $this->idDryRun = !empty($this->options[Options::DRY_RUN]); - } - - /** - * Add package tie to area and theme - * - * @param string $area - * @param string $themePath - * @param string $locale - * @return void - */ - public function addPack($area, $themePath, $locale) - { - $this->packages[$area . '-' . $themePath][$locale] = [$area, $themePath]; - } - - /** - * Deploy local packages with chosen deploy strategy - * @return int - */ - public function deploy() - { - if ($this->idDryRun) { - $this->output->writeln('Dry run. Nothing will be recorded to the target directory.'); - } else { - $version = (new \DateTime())->getTimestamp(); - $this->versionStorage->save($version); - } - - /** @var DeployStrategyProvider $strategyProvider */ - $strategyProvider = $this->deployStrategyProviderFactory->create( - ['output' => $this->output, 'options' => $this->options] - ); - - if ($this->isCanBeParalleled()) { - $result = $this->runInParallel($strategyProvider); - } else { - $result = 0; - foreach ($this->packages as $package) { - $locales = array_keys($package); - list($area, $themePath) = current($package); - foreach ($strategyProvider->getDeployStrategies($area, $themePath, $locales) as $locale => $strategy) { - $result |= $this->state->emulateAreaCode( - $area, - [$strategy, 'deploy'], - [$area, $themePath, $locale] - ); - } - } - } - - $this->minifyTemplates(); - if (!$this->idDryRun) { - $this->output->writeln("New version of deployed files: {$version}"); - } - - return $result; - } - - /** - * @return void - */ - private function minifyTemplates() - { - $noHtmlMinify = isset($this->options[Options::NO_HTML_MINIFY]) ? $this->options[Options::NO_HTML_MINIFY] : null; - if (!$noHtmlMinify && !$this->idDryRun) { - $this->output->writeln('=== Minify templates ==='); - $minified = $this->templateMinifier->minifyTemplates(); - $this->output->writeln("\nSuccessful: {$minified} files modified\n---\n"); - } - } - - /** - * @param DeployStrategyProvider $strategyProvider - * @return int - */ - private function runInParallel(DeployStrategyProvider $strategyProvider) - { - $processQueueManager = $this->processQueueManagerFactory->create( - ['maxProcesses' => $this->getProcessesAmount()] - ); - foreach ($this->packages as $package) { - $locales = array_keys($package); - list($area, $themePath) = current($package); - $baseStrategy = null; - $dependentStrategy = []; - foreach ($strategyProvider->getDeployStrategies($area, $themePath, $locales) as $locale => $strategy) { - $deploymentFunc = function () use ($area, $themePath, $locale, $strategy) { - return $this->state->emulateAreaCode($area, [$strategy, 'deploy'], [$area, $themePath, $locale]); - }; - if (null === $baseStrategy) { - $baseStrategy = $deploymentFunc; - } else { - $dependentStrategy[] = $deploymentFunc; - } - } - $processQueueManager->addTaskToQueue($baseStrategy, $dependentStrategy); - } - - return $processQueueManager->process(); - } - - /** - * @return bool - */ - private function isCanBeParalleled() - { - return function_exists('pcntl_fork') && $this->getProcessesAmount() > 1; - } - - /** - * @return int - */ - private function getProcessesAmount() - { - return isset($this->options[Options::JOBS_AMOUNT]) ? (int)$this->options[Options::JOBS_AMOUNT] : 0; - } -} diff --git a/app/code/Magento/Deploy/Model/DeployStrategyFactory.php b/app/code/Magento/Deploy/Model/DeployStrategyFactory.php deleted file mode 100644 index 57a2934965637..0000000000000 --- a/app/code/Magento/Deploy/Model/DeployStrategyFactory.php +++ /dev/null @@ -1,63 +0,0 @@ -objectManager = $objectManager; - } - - /** - * @param string $type - * @param array $arguments - * @return DeployInterface - * @throws InputException - */ - public function create($type, array $arguments = []) - { - $strategyMap = [ - self::DEPLOY_STRATEGY_STANDARD => Deploy\LocaleDeploy::class, - self::DEPLOY_STRATEGY_QUICK => Deploy\LocaleQuickDeploy::class, - self::DEPLOY_STRATEGY_JS_DICTIONARY => Deploy\JsDictionaryDeploy::class - ]; - - if (!isset($strategyMap[$type])) { - throw new InputException(__('Wrong deploy strategy type: %1', $type)); - } - - return $this->objectManager->create($strategyMap[$type], $arguments); - } -} diff --git a/app/code/Magento/Deploy/Model/DeployStrategyProvider.php b/app/code/Magento/Deploy/Model/DeployStrategyProvider.php deleted file mode 100644 index 5bb1549c00b37..0000000000000 --- a/app/code/Magento/Deploy/Model/DeployStrategyProvider.php +++ /dev/null @@ -1,198 +0,0 @@ -rulePool = $rulePool; - $this->design = $design; - $this->output = $output; - $this->options = $options; - $this->deployStrategyFactory = $deployStrategyFactory; - } - - /** - * @param string $area - * @param string $themePath - * @param array $locales - * @return DeployInterface[] - */ - public function getDeployStrategies($area, $themePath, array $locales) - { - if (count($locales) == 1) { - $locale = current($locales); - return [$locale => $this->getDeployStrategy(DeployStrategyFactory::DEPLOY_STRATEGY_STANDARD)]; - } - - $baseLocale = null; - $deployStrategies = []; - - foreach ($locales as $locale) { - $hasCustomization = false; - foreach ($this->getCustomizationDirectories($area, $themePath, $locale) as $directory) { - if (glob($directory . DIRECTORY_SEPARATOR . '*', GLOB_NOSORT)) { - $hasCustomization = true; - break; - } - } - if ($baseLocale === null && !$hasCustomization) { - $baseLocale = $locale; - } else { - $deployStrategies[$locale] = $hasCustomization - ? DeployStrategyFactory::DEPLOY_STRATEGY_STANDARD - : DeployStrategyFactory::DEPLOY_STRATEGY_QUICK; - } - } - $deployStrategies = array_merge( - [$baseLocale => DeployStrategyFactory::DEPLOY_STRATEGY_STANDARD], - $deployStrategies - ); - - return array_map(function ($strategyType) use ($area, $baseLocale) { - return $this->getDeployStrategy($strategyType, $baseLocale); - }, $deployStrategies); - } - - /** - * @param array $params - * @return array - */ - private function getLocaleDirectories($params) - { - $dirs = $this->getFallbackRule()->getPatternDirs($params); - - return array_filter($dirs, function ($dir) { - return strpos($dir, Dir::MODULE_I18N_DIR); - }); - } - - /** - * Get directories which can contains theme customization - * @param string $area - * @param string $themePath - * @param string $locale - * @return array - */ - private function getCustomizationDirectories($area, $themePath, $locale) - { - $customizationDirectories = []; - $this->design->setDesignTheme($themePath, $area); - - $params = ['area' => $area, 'theme' => $this->design->getDesignTheme(), 'locale' => $locale]; - foreach ($this->getLocaleDirectories($params) as $patternDir) { - $customizationDirectories[] = $patternDir; - } - - if ($this->moduleDirectories === null) { - $this->moduleDirectories = []; - $componentRegistrar = new ComponentRegistrar(); - $this->moduleDirectories = array_keys($componentRegistrar->getPaths(ComponentRegistrar::MODULE)); - } - - foreach ($this->moduleDirectories as $moduleDir) { - $params['module_name'] = $moduleDir; - $patternDirs = $this->getLocaleDirectories($params); - foreach ($patternDirs as $patternDir) { - $customizationDirectories[] = $patternDir; - } - } - - return $customizationDirectories; - } - - /** - * @return \Magento\Framework\View\Design\Fallback\Rule\RuleInterface - */ - private function getFallbackRule() - { - if (null === $this->fallBackRule) { - $this->fallBackRule = $this->rulePool->getRule(RulePool::TYPE_STATIC_FILE); - } - - return $this->fallBackRule; - } - - /** - * @param string $type - * @param null|string $baseLocale - * @return DeployInterface - */ - private function getDeployStrategy($type, $baseLocale = null) - { - $options = $this->options; - if ($baseLocale) { - $options[DeployInterface::DEPLOY_BASE_LOCALE] = $baseLocale; - } - - return $this->deployStrategyFactory->create( - $type, - ['output' => $this->output, 'options' => $options] - ); - } -} diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php deleted file mode 100644 index 981a21f7777a8..0000000000000 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ /dev/null @@ -1,127 +0,0 @@ -output = $output; - $this->deployManagerFactory = $deployManagerFactory; - if (is_array($options)) { - $this->options = $options; - } else { - // backward compatibility support - $this->options = [DeployStaticOptions::DRY_RUN => (bool)$options]; - } - } - - /** - * @return \Magento\Deploy\Model\DeployManagerFactory - */ - private function getDeployManagerFactory() - { - if (null === $this->deployManagerFactory) { - $this->deployManagerFactory = ObjectManager::getInstance()->get(DeployManagerFactory::class); - } - - return $this->deployManagerFactory; - } - - /** - * Populate all static view files for specified root path and list of languages - * - * @param ObjectManagerFactory $omFactory - * @param array $locales - * @param array $deployableAreaThemeMap - * @return int - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @deprecated - */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, array $deployableAreaThemeMap = []) - { - /** @var DeployManager $deployerManager */ - $deployerManager = $this->getDeployManagerFactory()->create( - ['options' => $this->options, 'output' => $this->output] - ); - - foreach ($deployableAreaThemeMap as $area => $themes) { - foreach ($locales as $locale) { - foreach ($themes as $themePath) { - $deployerManager->addPack($area, $themePath, $locale); - } - } - } - return $deployerManager->deploy(); - } - - /** - * Set application locale and load translation for area - * - * @param string $locale - * @param string $area - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @deprecated - */ - protected function emulateApplicationLocale($locale, $area) - { - } -} diff --git a/app/code/Magento/Deploy/Model/Process.php b/app/code/Magento/Deploy/Model/Process.php deleted file mode 100644 index 700c6cf87cbf7..0000000000000 --- a/app/code/Magento/Deploy/Model/Process.php +++ /dev/null @@ -1,84 +0,0 @@ -pid = 0; - $this->status = null; - $this->handler = $handler; - } - - /** - * @return int - */ - public function getPid() - { - return $this->pid; - } - - /** - * @param int $pid - * @return void - */ - public function setPid($pid) - { - $this->pid = $pid; - } - - /** - * @return void - * @SuppressWarnings(PHPMD.ExitExpression) - */ - public function run() - { - $status = call_user_func($this->handler, $this); - - $status = is_integer($status) ? $status : 0; - exit($status); - } - - /** - * @return bool - */ - public function isCompleted() - { - $pid = pcntl_waitpid($this->getPid(), $status, WNOHANG); - if ($pid == -1 || $pid === $this->getPid()) { - $this->status = pcntl_wexitstatus($status); - return true; - } - return false; - } - - /** - * @return int|null - */ - public function getStatus() - { - return $this->status; - } -} diff --git a/app/code/Magento/Deploy/Model/ProcessManager.php b/app/code/Magento/Deploy/Model/ProcessManager.php deleted file mode 100644 index c24c44a3afa33..0000000000000 --- a/app/code/Magento/Deploy/Model/ProcessManager.php +++ /dev/null @@ -1,112 +0,0 @@ -processFactory = $processFactory; - } - - /** - * Forks the currently running process. - * - * @param callable $handler - * - * @return Process - * @throws \RuntimeException - * @SuppressWarnings(PHPMD.ExitExpression) - */ - public function fork(callable $handler) - { - $process = $this->createProcess($handler); - $pid = pcntl_fork(); - - if ($pid === -1) { - throw new \RuntimeException('Unable to fork a new process'); - } - - if ($pid) { - $process->setPid($pid); - $this->processes[$pid] = $process; - return $process; - } - - // process child process - $this->processes = []; - $process->setPid(getmypid()); - $process->run(); - - exit(0); - } - - /** - * @return Process[] - */ - public function getProcesses() - { - return $this->processes; - } - - /** - * @param Process $process - * @return void - */ - public function delete(Process $process) - { - unset($this->processes[$process->getPid()]); - } - - /** - * @param callable $handler - * @return Process - */ - private function createProcess(callable $handler) - { - return $this->processFactory->create(['handler' => $handler]); - } - - /** - * Protect against zombie process - * @return void - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - */ - private function freeResources() - { - foreach ($this->processes as $process) { - if (pcntl_waitpid($process->getPid(), $status) === -1) { - throw new \RuntimeException('Error while waiting for process '. $process->getPid()); - } - } - } - - /** - * Free resources - */ - public function __destruct() - { - $this->freeResources(); - } -} diff --git a/app/code/Magento/Deploy/Model/ProcessQueueManager.php b/app/code/Magento/Deploy/Model/ProcessQueueManager.php deleted file mode 100644 index f909728a8d934..0000000000000 --- a/app/code/Magento/Deploy/Model/ProcessQueueManager.php +++ /dev/null @@ -1,165 +0,0 @@ -processManager = $processManager; - $this->resourceConnection = $resourceConnection; - $this->processTaskFactory = $processTaskFactory; - $this->maxProcesses = $maxProcesses; - } - - /** - * @param callable $task - * @param callable[] $dependentTasks - * @return void - */ - public function addTaskToQueue(callable $task, $dependentTasks = []) - { - $dependentTasks = array_map(function (callable $task) { - return $this->createTask($task); - }, $dependentTasks); - - $task = $this->createTask($task, $dependentTasks); - $this->tasksQueue[$task->getId()] = $task; - } - - /** - * Process tasks queue - * @return int - */ - public function process() - { - $processQueue = []; - $this->internalQueueProcess($this->tasksQueue, $processQueue); - - $returnStatus = 0; - while (count($this->processManager->getProcesses()) > 0) { - foreach ($this->processManager->getProcesses() as $process) { - if ($process->isCompleted()) { - $dependedTasks = isset($this->processTaskMap[$process->getPid()]) - ? $this->processTaskMap[$process->getPid()] - : []; - - $this->processManager->delete($process); - $returnStatus |= $process->getStatus(); - - $this->internalQueueProcess(array_merge($processQueue, $dependedTasks), $processQueue); - - if (count($this->processManager->getProcesses()) >= $this->maxProcesses) { - break 1; - } - } - } - usleep(5000); - } - $this->resourceConnection->closeConnection(); - - return $returnStatus; - } - - /** - * @param ProcessTask[] $taskQueue - * @param ProcessTask[] $processQueue - * @return void - */ - private function internalQueueProcess($taskQueue, &$processQueue) - { - $processNumber = count($this->processManager->getProcesses()); - foreach ($taskQueue as $task) { - if ($processNumber >= $this->maxProcesses) { - if (!isset($processQueue[$task->getId()])) { - $processQueue[$task->getId()] = $task; - } - } else { - unset($processQueue[$task->getId()]); - $this->fork($task); - $processNumber++; - } - } - } - - /** - * @param callable $handler - * @param array $dependentTasks - * @return ProcessTask - */ - private function createTask($handler, $dependentTasks = []) - { - return $this->processTaskFactory->create(['handler' => $handler, 'dependentTasks' => $dependentTasks]); - } - - /** - * @param ProcessTask $task - * @return void - */ - private function fork(ProcessTask $task) - { - $process = $this->processManager->fork($task->getHandler()); - if ($task->getDependentTasks()) { - $pid = $process->getPid(); - foreach ($task->getDependentTasks() as $dependentTask) { - $this->processTaskMap[$pid][$dependentTask->getId()] = $dependentTask; - } - } - } -} diff --git a/app/code/Magento/Deploy/Model/ProcessTask.php b/app/code/Magento/Deploy/Model/ProcessTask.php deleted file mode 100644 index 612de0fc398ff..0000000000000 --- a/app/code/Magento/Deploy/Model/ProcessTask.php +++ /dev/null @@ -1,65 +0,0 @@ -taskId = uniqid('', true); - $this->handler = $handler; - $this->dependentTasks = $dependentTasks; - } - - /** - * @return callable - */ - public function getHandler() - { - return $this->handler; - } - - /** - * @return string - */ - public function getId() - { - return $this->taskId; - } - - /** - * @return ProcessTask[] - */ - public function getDependentTasks() - { - return $this->dependentTasks; - } -} diff --git a/app/code/Magento/Deploy/Package/Bundle/RequireJs.php b/app/code/Magento/Deploy/Package/Bundle/RequireJs.php index 8fa207853522e..73a15554f8b78 100644 --- a/app/code/Magento/Deploy/Package/Bundle/RequireJs.php +++ b/app/code/Magento/Deploy/Package/Bundle/RequireJs.php @@ -13,11 +13,9 @@ use Magento\Framework\View\Asset\Minification; /** - * RequireJs Bundle class + * RequireJs static files bundle object * - * All files added will be bundled to multiple bundle files using RequireJS AMD architecture - * - * @api + * All files added will be bundled to multiple bundle files compatible with RequireJS AMD format */ class RequireJs implements BundleInterface { diff --git a/app/code/Magento/Deploy/Package/BundleInterface.php b/app/code/Magento/Deploy/Package/BundleInterface.php index 96d0b68682421..34b5e2ec983e1 100644 --- a/app/code/Magento/Deploy/Package/BundleInterface.php +++ b/app/code/Magento/Deploy/Package/BundleInterface.php @@ -6,9 +6,7 @@ namespace Magento\Deploy\Package; /** - * Interface BundleInterface - * - * @api + * Bundle Interface */ interface BundleInterface { diff --git a/app/code/Magento/Deploy/Package/BundleInterfaceFactory.php b/app/code/Magento/Deploy/Package/BundleInterfaceFactory.php index 2acf2868d6b81..da691e7e25590 100644 --- a/app/code/Magento/Deploy/Package/BundleInterfaceFactory.php +++ b/app/code/Magento/Deploy/Package/BundleInterfaceFactory.php @@ -13,7 +13,6 @@ * Factory class for Package Bundle Interface * * @see Bundle - * @api */ class BundleInterfaceFactory { diff --git a/app/code/Magento/Deploy/Package/Package.php b/app/code/Magento/Deploy/Package/Package.php index 17f802eb277cd..ef50a7f47073d 100644 --- a/app/code/Magento/Deploy/Package/Package.php +++ b/app/code/Magento/Deploy/Package/Package.php @@ -10,9 +10,7 @@ use Magento\Framework\View\Asset\PreProcessor\FileNameResolver; /** - * Package class - * - * @api + * Deployment Package */ class Package { diff --git a/app/code/Magento/Deploy/Package/PackageFactory.php b/app/code/Magento/Deploy/Package/PackageFactory.php index 4f8011dceaa24..2d251a0a3eff4 100644 --- a/app/code/Magento/Deploy/Package/PackageFactory.php +++ b/app/code/Magento/Deploy/Package/PackageFactory.php @@ -13,7 +13,6 @@ * Factory class for Package object * * @see Package - * @api */ class PackageFactory { diff --git a/app/code/Magento/Deploy/Package/PackageFile.php b/app/code/Magento/Deploy/Package/PackageFile.php index 3f1bb1e3ef35b..e126a40d6961c 100644 --- a/app/code/Magento/Deploy/Package/PackageFile.php +++ b/app/code/Magento/Deploy/Package/PackageFile.php @@ -9,9 +9,7 @@ use Magento\Framework\View\Asset\Repository; /** - * Class PackageFile - * - * @api + * Deployment Package File class */ class PackageFile extends Asset { diff --git a/app/code/Magento/Deploy/Package/PackagePool.php b/app/code/Magento/Deploy/Package/PackagePool.php index b1901a06357d9..c3dbe0dafba92 100644 --- a/app/code/Magento/Deploy/Package/PackagePool.php +++ b/app/code/Magento/Deploy/Package/PackagePool.php @@ -6,15 +6,13 @@ namespace Magento\Deploy\Package; use Magento\Deploy\Collector\Collector; -use Magento\Deploy\Console\Command\DeployStaticOptions as Options; +use Magento\Deploy\Console\DeployStaticOptions as Options; use Magento\Framework\AppInterface; use Magento\Framework\View\Design\ThemeInterface; use Magento\Framework\View\Design\Theme\ListInterface; /** - * Class PackagePool - * - * @api + * Deployment Packages Pool class */ class PackagePool { diff --git a/app/code/Magento/Deploy/Package/Processor/PostProcessor/CssUrls.php b/app/code/Magento/Deploy/Package/Processor/PostProcessor/CssUrls.php index a03deb2aebe99..1c139d5682df1 100644 --- a/app/code/Magento/Deploy/Package/Processor/PostProcessor/CssUrls.php +++ b/app/code/Magento/Deploy/Package/Processor/PostProcessor/CssUrls.php @@ -5,7 +5,7 @@ */ namespace Magento\Deploy\Package\Processor\PostProcessor; -use Magento\Deploy\Console\Command\DeployStaticOptions; +use Magento\Deploy\Console\DeployStaticOptions; use Magento\Deploy\Package\Package; use Magento\Deploy\Package\PackageFile; use Magento\Deploy\Package\Processor\ProcessorInterface; diff --git a/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php b/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php index c7da82369844b..b3461e3ab4a22 100644 --- a/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php +++ b/app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php @@ -5,7 +5,7 @@ */ namespace Magento\Deploy\Package\Processor\PreProcessor; -use Magento\Deploy\Console\Command\DeployStaticOptions; +use Magento\Deploy\Console\DeployStaticOptions; use Magento\Deploy\Package\Package; use Magento\Deploy\Package\PackageFile; use Magento\Deploy\Package\Processor\ProcessorInterface; diff --git a/app/code/Magento/Deploy/Package/Processor/PreProcessor/Less.php b/app/code/Magento/Deploy/Package/Processor/PreProcessor/Less.php index 5fd0f1df92f31..d9f231c4cee3d 100644 --- a/app/code/Magento/Deploy/Package/Processor/PreProcessor/Less.php +++ b/app/code/Magento/Deploy/Package/Processor/PreProcessor/Less.php @@ -5,7 +5,7 @@ */ namespace Magento\Deploy\Package\Processor\PreProcessor; -use Magento\Deploy\Console\Command\DeployStaticOptions; +use Magento\Deploy\Console\DeployStaticOptions; use Magento\Deploy\Package\Package; use Magento\Deploy\Package\PackageFile; use Magento\Deploy\Package\Processor\ProcessorInterface; diff --git a/app/code/Magento/Deploy/Package/Processor/ProcessorInterface.php b/app/code/Magento/Deploy/Package/Processor/ProcessorInterface.php index d8b1abf602189..06f94b87dd845 100644 --- a/app/code/Magento/Deploy/Package/Processor/ProcessorInterface.php +++ b/app/code/Magento/Deploy/Package/Processor/ProcessorInterface.php @@ -8,7 +8,7 @@ use Magento\Deploy\Package\Package; /** - * Interface ProcessorInterface + * Deploy packages processor interface */ interface ProcessorInterface { diff --git a/app/code/Magento/Deploy/Process/Queue.php b/app/code/Magento/Deploy/Process/Queue.php index aee3438d2d8fb..31d662c874acb 100644 --- a/app/code/Magento/Deploy/Process/Queue.php +++ b/app/code/Magento/Deploy/Process/Queue.php @@ -13,9 +13,9 @@ use Magento\Framework\Locale\ResolverInterface as LocaleResolver; /** - * Class Queue + * Deployment Queue * - * @api + * Deploy packages in parallel forks (if available) */ class Queue { diff --git a/app/code/Magento/Deploy/Process/QueueFactory.php b/app/code/Magento/Deploy/Process/QueueFactory.php index fb9a865f259ef..1f1a614277c26 100644 --- a/app/code/Magento/Deploy/Process/QueueFactory.php +++ b/app/code/Magento/Deploy/Process/QueueFactory.php @@ -11,8 +11,6 @@ /** * Factory class for @see \Magento\Deploy\Process\Queue - * - * @api */ class QueueFactory { diff --git a/app/code/Magento/Deploy/Service/Bundle.php b/app/code/Magento/Deploy/Service/Bundle.php index cb1c21cd54229..cf0d7a551f4c3 100644 --- a/app/code/Magento/Deploy/Service/Bundle.php +++ b/app/code/Magento/Deploy/Service/Bundle.php @@ -15,12 +15,10 @@ use Magento\Framework\View\Asset\RepositoryMap; /** - * Bundle Service + * Deploy bundled static files service * * Read all static files from deployed packages and generate bundles. Bundle Factory can be configured to use * bundle format different from RequireJS used out of the box - * - * @api */ class Bundle { diff --git a/app/code/Magento/Deploy/Service/DeployPackage.php b/app/code/Magento/Deploy/Service/DeployPackage.php index f35499a063e06..0522702cbdc2b 100644 --- a/app/code/Magento/Deploy/Service/DeployPackage.php +++ b/app/code/Magento/Deploy/Service/DeployPackage.php @@ -14,9 +14,7 @@ use Psr\Log\LoggerInterface; /** - * Class DeployPackage - * - * @api + * Deploy package service */ class DeployPackage { diff --git a/app/code/Magento/Deploy/Service/DeployRequireJsConfig.php b/app/code/Magento/Deploy/Service/DeployRequireJsConfig.php index c71983f6c1129..c54f972485eff 100644 --- a/app/code/Magento/Deploy/Service/DeployRequireJsConfig.php +++ b/app/code/Magento/Deploy/Service/DeployRequireJsConfig.php @@ -12,9 +12,7 @@ use Magento\Framework\RequireJs\ConfigFactory; /** - * Deploy RequireJS configuration - * - * @api + * Deploy RequireJS configuration service */ class DeployRequireJsConfig { diff --git a/app/code/Magento/Deploy/Service/DeployStaticContent.php b/app/code/Magento/Deploy/Service/DeployStaticContent.php index 054249dd19a28..bcf318202fdc3 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticContent.php +++ b/app/code/Magento/Deploy/Service/DeployStaticContent.php @@ -7,15 +7,15 @@ use Magento\Deploy\Strategy\DeployStrategyFactory; use Magento\Deploy\Process\QueueFactory; -use Magento\Deploy\Console\Command\DeployStaticOptions as Options; +use Magento\Deploy\Console\DeployStaticOptions as Options; use Magento\Framework\App\View\Deployment\Version\StorageInterface; use Magento\Framework\ObjectManagerInterface; use Psr\Log\LoggerInterface; /** - * Class DeployStaticContent + * Main service for static content deployment * - * @api + * Aggregates services to deploy static files, static files bundles, translations and minified templates */ class DeployStaticContent { diff --git a/app/code/Magento/Deploy/Service/DeployStaticFile.php b/app/code/Magento/Deploy/Service/DeployStaticFile.php index fbd46d21d9d55..40986087c405e 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticFile.php +++ b/app/code/Magento/Deploy/Service/DeployStaticFile.php @@ -15,9 +15,7 @@ use Magento\Framework\Filesystem\Directory\ReadInterface; /** - * Class DeployStaticFile - * - * @api + * Deploy static file service */ class DeployStaticFile { diff --git a/app/code/Magento/Deploy/Service/DeployTranslationsDictionary.php b/app/code/Magento/Deploy/Service/DeployTranslationsDictionary.php index e105002a7149b..f58cf105e7050 100644 --- a/app/code/Magento/Deploy/Service/DeployTranslationsDictionary.php +++ b/app/code/Magento/Deploy/Service/DeployTranslationsDictionary.php @@ -10,9 +10,7 @@ use Psr\Log\LoggerInterface; /** - * Service to deploy translations dictionary file for JavaScript - * - * @api + * Deploy translation dictionaries service */ class DeployTranslationsDictionary { diff --git a/app/code/Magento/Deploy/Service/MinifyTemplates.php b/app/code/Magento/Deploy/Service/MinifyTemplates.php index e547ad79fd54c..9be2d5281364d 100644 --- a/app/code/Magento/Deploy/Service/MinifyTemplates.php +++ b/app/code/Magento/Deploy/Service/MinifyTemplates.php @@ -9,9 +9,7 @@ use Magento\Framework\App\Utility\Files; /** - * Minify Templates - * - * @api + * Minify PHTML templates service */ class MinifyTemplates { diff --git a/app/code/Magento/Deploy/Source/Lib.php b/app/code/Magento/Deploy/Source/Lib.php index 8ac85ccec1e83..d1e7cdaea6c9d 100644 --- a/app/code/Magento/Deploy/Source/Lib.php +++ b/app/code/Magento/Deploy/Source/Lib.php @@ -12,11 +12,9 @@ use Magento\Deploy\Package\PackageFileFactory; /** - * Class Lib + * Collect files eligible for deployment from library * * Provides files collected from web library - * - * @api */ class Lib implements SourceInterface { diff --git a/app/code/Magento/Deploy/Source/Modules.php b/app/code/Magento/Deploy/Source/Modules.php index 71b8ab51c6dda..a852ace2735a6 100644 --- a/app/code/Magento/Deploy/Source/Modules.php +++ b/app/code/Magento/Deploy/Source/Modules.php @@ -9,11 +9,7 @@ use Magento\Deploy\Package\PackageFileFactory; /** - * Class Modules - * - * Provides files collected from all modules - * - * @api + * Collect files eligible for deployment from modules */ class Modules implements SourceInterface { diff --git a/app/code/Magento/Deploy/Source/SourceInterface.php b/app/code/Magento/Deploy/Source/SourceInterface.php index 445b9f56a718a..14740e8f164a3 100644 --- a/app/code/Magento/Deploy/Source/SourceInterface.php +++ b/app/code/Magento/Deploy/Source/SourceInterface.php @@ -8,11 +8,7 @@ use Magento\Deploy\Package\PackageFile; /** - * Interface SourceInterface - * * Provide list of files located in some source location (e.g. modules directories, library, themes, else) - * - * @api */ interface SourceInterface { diff --git a/app/code/Magento/Deploy/Source/SourcePool.php b/app/code/Magento/Deploy/Source/SourcePool.php index 4ae6c4229dc40..3179a0a5c0aa3 100644 --- a/app/code/Magento/Deploy/Source/SourcePool.php +++ b/app/code/Magento/Deploy/Source/SourcePool.php @@ -6,7 +6,7 @@ namespace Magento\Deploy\Source; /** - * Class SourcePool + * Configurable (via di.xml) pool of available sources of static files eligible for deployment */ class SourcePool { diff --git a/app/code/Magento/Deploy/Source/Themes.php b/app/code/Magento/Deploy/Source/Themes.php index 38c0949530244..2ca599b12e2cc 100644 --- a/app/code/Magento/Deploy/Source/Themes.php +++ b/app/code/Magento/Deploy/Source/Themes.php @@ -9,11 +9,7 @@ use Magento\Deploy\Package\PackageFileFactory; /** - * Class Themes - * - * Provides files collected from all themes - * - * @api + * Collect files eligible for deployment from themes */ class Themes implements SourceInterface { diff --git a/app/code/Magento/Deploy/Strategy/CompactDeploy.php b/app/code/Magento/Deploy/Strategy/CompactDeploy.php index de5efb4550293..72f8893dde145 100644 --- a/app/code/Magento/Deploy/Strategy/CompactDeploy.php +++ b/app/code/Magento/Deploy/Strategy/CompactDeploy.php @@ -5,16 +5,12 @@ */ namespace Magento\Deploy\Strategy; -use Magento\Deploy\Console\Command\DeployStaticOptions; -use Magento\Deploy\Package\Package; use Magento\Deploy\Package\PackagePool; +use Magento\Deploy\Package\Package; use Magento\Deploy\Process\Queue; -use Magento\Framework\Exception\LocalizedException; /** - * Class CompactDeploy - * - * @api + * Compact deployment strategy implementation */ class CompactDeploy implements StrategyInterface { diff --git a/app/code/Magento/Deploy/Strategy/DeployStrategyFactory.php b/app/code/Magento/Deploy/Strategy/DeployStrategyFactory.php index 2fb705507f68d..1a9c0a79b02dd 100644 --- a/app/code/Magento/Deploy/Strategy/DeployStrategyFactory.php +++ b/app/code/Magento/Deploy/Strategy/DeployStrategyFactory.php @@ -10,8 +10,6 @@ /** * Abstract factory class for instances of @see \Magento\Deploy\Strategy\StrategyInterface - * - * @api */ class DeployStrategyFactory { diff --git a/app/code/Magento/Deploy/Strategy/QuickDeploy.php b/app/code/Magento/Deploy/Strategy/QuickDeploy.php index 01ed3b89af3f3..a211d8d9709b0 100644 --- a/app/code/Magento/Deploy/Strategy/QuickDeploy.php +++ b/app/code/Magento/Deploy/Strategy/QuickDeploy.php @@ -10,9 +10,7 @@ use Magento\Deploy\Process\Queue; /** - * Class QuickDeploy - * - * @api + * Quick deployment strategy implementation */ class QuickDeploy implements StrategyInterface { diff --git a/app/code/Magento/Deploy/Strategy/StandardDeploy.php b/app/code/Magento/Deploy/Strategy/StandardDeploy.php index cbc9d064818dd..8a5ec462d3f4f 100644 --- a/app/code/Magento/Deploy/Strategy/StandardDeploy.php +++ b/app/code/Magento/Deploy/Strategy/StandardDeploy.php @@ -6,13 +6,11 @@ namespace Magento\Deploy\Strategy; use Magento\Deploy\Package\PackagePool; -use Magento\Deploy\Process\Queue; use Magento\Deploy\Package\Package; +use Magento\Deploy\Process\Queue; /** - * Class StandardDeploy - * - * @api + * Standard deployment strategy implementation */ class StandardDeploy implements StrategyInterface { diff --git a/app/code/Magento/Deploy/Strategy/StrategyInterface.php b/app/code/Magento/Deploy/Strategy/StrategyInterface.php index 45c620420da0e..29ce317af6610 100644 --- a/app/code/Magento/Deploy/Strategy/StrategyInterface.php +++ b/app/code/Magento/Deploy/Strategy/StrategyInterface.php @@ -8,9 +8,7 @@ use Magento\Deploy\Package\Package; /** - * Interface StrategyInterface - * - * @api + * Deployment strategy interface */ interface StrategyInterface { diff --git a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/JsDictionaryDeployTest.php b/app/code/Magento/Deploy/Test/Unit/Model/Deploy/JsDictionaryDeployTest.php deleted file mode 100644 index 4880616f2e7f6..0000000000000 --- a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/JsDictionaryDeployTest.php +++ /dev/null @@ -1,103 +0,0 @@ -output = $this->getMockBuilder(OutputInterface::class) - ->setMethods(['writeln', 'isVeryVerbose']) - ->getMockForAbstractClass(); - - $this->translationJsConfig = $this->getMock(TranslationJsConfig::class, [], [], '', false); - $this->translator = $this->getMockForAbstractClass(TranslateInterface::class, [], '', false, false, true); - $this->assetRepo = $this->getMock(Repository::class, [], [], '', false); - $this->asset = $this->getMockForAbstractClass(Asset::class, [], '', false, false, true); - $this->assetPublisher = $this->getMock(Publisher::class, [], [], '', false); - - $this->model = (new ObjectManager($this))->getObject( - JsDictionaryDeploy::class, - [ - 'translationJsConfig' => $this->translationJsConfig, - 'translator' => $this->translator, - 'assetRepo' => $this->assetRepo, - 'assetPublisher' => $this->assetPublisher, - 'output' => $this->output - ] - ); - } - - public function testDeploy() - { - $area = 'adminhtml'; - $themePath = 'Magento/backend'; - $locale = 'uk_UA'; - - $dictionary = 'js-translation.json'; - - $this->translationJsConfig->expects(self::once())->method('getDictionaryFileName') - ->willReturn($dictionary); - - $this->translator->expects($this->once())->method('setLocale')->with($locale); - $this->translator->expects($this->once())->method('loadData')->with($area, true); - - $this->assetRepo->expects($this->once())->method('createAsset') - ->with( - $dictionary, - ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'publish' => true] - ) - ->willReturn($this->asset); - - $this->assetPublisher->expects($this->once())->method('publish'); - - $this->model->deploy($area, $themePath, $locale); - } -} diff --git a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/LocaleDeployTest.php b/app/code/Magento/Deploy/Test/Unit/Model/Deploy/LocaleDeployTest.php deleted file mode 100644 index 0e930fb3c0ce6..0000000000000 --- a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/LocaleDeployTest.php +++ /dev/null @@ -1,138 +0,0 @@ -area = 'adminhtml'; - $this->themePath = '/theme/path'; - $this->locale = 'en_US'; - - $outputMock = $this->getMock(OutputInterface::class, [], [], '', false); - $jsTranslationMock = $this->getMock(Config::class, [], [], '', false); - $jsTranslationMock->expects($this->once())->method('dictionaryEnabled')->willReturn(false); - $minificationMock = $this->getMock(Minification::class, [], [], '', false); - $minificationMock->expects($this->once())->method('isEnabled')->with('js')->willReturn(true); - - $themeMock = $this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $designMock = $this->getMock(\Magento\Framework\View\DesignInterface::class, [], [], '', false); - $designMock->expects($this->once())->method('setDesignTheme')->with($themeMock, $this->area)->willReturnSelf(); - $assetRepoMock = $this->getMock(Repository::class, [], [], '', false); - $assetRepoFactoryMock = $this->getMock(RepositoryFactory::class, ['create'], [], '', false); - $assetRepoFactoryMock->expects($this->once()) - ->method('create') - ->with(['design' => $designMock]) - ->willReturn($assetRepoMock); - - $fileManagerMock = $this->getMock(\Magento\RequireJs\Model\FileManager::class, [], [], '', false); - $fileManagerMock->expects($this->once())->method('createRequireJsConfigAsset')->willReturnSelf(); - $fileManagerMock->expects($this->once())->method('createMinResolverAsset')->willReturnSelf(); - $fileManagerFactoryMock = $this->getMock(FileManagerFactory::class, ['create'], [], '', false); - $fileManagerFactoryMock->expects($this->once())->method('create')->willReturn($fileManagerMock); - - $requireJsConfigMock = $this->getMock(\Magento\Framework\RequireJs\Config::class, [], [], '', false); - $configFactoryMock = $this->getMock(ConfigFactory::class, ['create'], [], '', false); - $configFactoryMock->expects($this->once())->method('create')->willReturn($requireJsConfigMock); - - $assetPublisherMock = $this->getMock(Publisher::class, [], [], '', false); - - $bundleManagerMock = $this->getMock(Manager::class, [], [], '', false); - $bundleManagerMock->expects($this->once())->method('flush'); - - $themeProviderMock = $this->getMock(ThemeProviderInterface::class, [], [], '', false); - $loggerMock = $this->getMock(LoggerInterface::class, [], [], '', false); - - $filesUtilMock = $this->getMock(Files::class, [], [], '', false); - $filesUtilMock->expects($this->once())->method('getStaticPreProcessingFiles')->willReturn([]); - $filesUtilMock->expects($this->once())->method('getStaticLibraryFiles')->willReturn([]); - - $designFactoryMock = $this->getMock(DesignInterfaceFactory::class, ['create'], [], '', false); - $designFactoryMock->expects($this->once())->method('create')->willReturn($designMock); - - $localeResolverMock = $this->getMock(ResolverInterface::class, [], [], '', false); - $localeResolverMock->expects($this->once())->method('setLocale')->with($this->locale); - - $themeList = $this->getMock(ListInterface::class, [], [], '', false); - $themeList->expects($this->once())->method('getThemeByFullPath') - ->with($this->area . '/' . $this->themePath) - ->willReturn($themeMock); - - $this->model = new LocaleDeploy( - $outputMock, - $jsTranslationMock, - $minificationMock, - $assetRepoMock, - $assetRepoFactoryMock, - $fileManagerFactoryMock, - $configFactoryMock, - $assetPublisherMock, - $bundleManagerMock, - $themeProviderMock, - $loggerMock, - $filesUtilMock, - $designFactoryMock, - $localeResolverMock, - [], - [\Magento\Deploy\Console\Command\DeployStaticOptions::NO_JAVASCRIPT => 0] - ); - $property = new \ReflectionProperty(get_class($this->model), 'themeList'); - $property->setAccessible(true); - $property->setValue($this->model, $themeList); - } - - public function testDeploy() - { - $this->assertEquals( - \Magento\Framework\Console\Cli::RETURN_SUCCESS, - $this->model->deploy($this->area, $this->themePath, $this->locale) - ); - } -} diff --git a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/LocaleQuickDeployTest.php b/app/code/Magento/Deploy/Test/Unit/Model/Deploy/LocaleQuickDeployTest.php deleted file mode 100644 index ce55e7ae28f8a..0000000000000 --- a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/LocaleQuickDeployTest.php +++ /dev/null @@ -1,157 +0,0 @@ -outputMock = $this->getMockBuilder(OutputInterface::class) - ->setMethods(['writeln', 'isVeryVerbose']) - ->getMockForAbstractClass(); - $this->staticDirectoryMock = $this->getMockBuilder(WriteInterface::class) - ->setMethods(['createSymlink', 'getAbsolutePath', 'getRelativePath', 'copyFile', 'readRecursively']) - ->getMockForAbstractClass(); - $this->translationJsConfig = $this->getMock(TranslationJsConfig::class, [], [], '', false); - $this->deployStrategyFactory = $this->getMock(DeployStrategyFactory::class, [], [], '', false); - $this->jsDictionaryDeploy = $this->getMock(JsDictionaryDeploy::class, [], [], '', false); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Deploy base locale must be set for Quick Deploy - */ - public function testDeployWithoutBaseLocale() - { - $this->getModel()->deploy('adminhtml', 'Magento/backend', 'en_US'); - } - - public function testDeployWithSymlinkStrategy() - { - $area = 'adminhtml'; - $themePath = 'Magento/backend'; - $locale = 'uk_UA'; - $baseLocal = 'en_US'; - - $this->staticDirectoryMock->expects(self::exactly(1)) - ->method('createSymlink') - ->withConsecutive( - ['adminhtml/Magento/backend/en_US', 'adminhtml/Magento/backend/uk_UA'] - ); - - $model = $this->getModel([ - DeployInterface::DEPLOY_BASE_LOCALE => $baseLocal, - Options::SYMLINK_LOCALE => 1, - ]); - $model->deploy($area, $themePath, $locale); - } - - public function testDeployWithCopyStrategy() - { - $area = 'adminhtml'; - $themePath = 'Magento/backend'; - $baseLocale = 'en_US'; - $locale = 'uk_UA'; - $baseDir = $baseLocale . '/dir'; - $file1 = 'file1'; - $file2 = 'file2'; - $baseFile1 = $baseLocale . '/' . $file1; - $baseFile2 = $baseLocale . '/' . $file2; - - $dictionary = 'js-translation.json'; - $baseDictionary = $baseLocale . '/' . $dictionary; - - $this->staticDirectoryMock->expects(self::never())->method('createSymlink'); - $this->staticDirectoryMock->expects(self::exactly(1))->method('readRecursively')->willReturnMap( - [ - ['adminhtml/Magento/backend/en_US', [$baseFile1, $baseDir]] - ] - ); - $this->staticDirectoryMock->expects(self::exactly(2))->method('isFile')->willReturnMap([ - [$baseFile1, true], - [$baseDir, false], - [$baseFile2, true], - [$baseDictionary, true] - ]); - $this->staticDirectoryMock->expects(self::exactly(1))->method('copyFile')->withConsecutive( - [$baseFile1, $locale . '/' . $file1, null], - [$baseFile2, $locale . '/' . $file2, null] - ); - - $this->translationJsConfig->expects(self::exactly(1))->method('getDictionaryFileName') - ->willReturn($dictionary); - - $this->translationJsConfig->expects($this->once())->method('dictionaryEnabled')->willReturn(true); - - $this->deployStrategyFactory->expects($this->once())->method('create') - ->with( - DeployStrategyFactory::DEPLOY_STRATEGY_JS_DICTIONARY, - ['output' => $this->outputMock, 'translationJsConfig' => $this->translationJsConfig] - ) - ->willReturn($this->jsDictionaryDeploy); - - $this->jsDictionaryDeploy->expects($this->once())->method('deploy')->with($area, $themePath, $locale); - - $model = $this->getModel([ - DeployInterface::DEPLOY_BASE_LOCALE => $baseLocale, - Options::SYMLINK_LOCALE => 0, - ]); - $model->deploy($area, $themePath, $locale); - } - - /** - * @param array $options - * @return LocaleQuickDeploy - */ - private function getModel($options = []) - { - return (new ObjectManager($this))->getObject( - LocaleQuickDeploy::class, - [ - 'output' => $this->outputMock, - 'staticDirectory' => $this->staticDirectoryMock, - 'options' => $options, - 'translationJsConfig' => $this->translationJsConfig, - 'deployStrategyFactory' => $this->deployStrategyFactory - ] - ); - } -} diff --git a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/TemplateMinifierTest.php b/app/code/Magento/Deploy/Test/Unit/Model/Deploy/TemplateMinifierTest.php deleted file mode 100644 index 2f74e1db96ca9..0000000000000 --- a/app/code/Magento/Deploy/Test/Unit/Model/Deploy/TemplateMinifierTest.php +++ /dev/null @@ -1,56 +0,0 @@ -minifierMock = $this->getMock( - \Magento\Framework\View\Template\Html\MinifierInterface::class, - [], - [], - '', - false - ); - $this->filesUtilsMock = $this->getMock(\Magento\Framework\App\Utility\Files::class, [], [], '', false); - - $this->model = new \Magento\Deploy\Model\Deploy\TemplateMinifier( - $this->filesUtilsMock, - $this->minifierMock - ); - } - - public function testMinifyTemplates() - { - $templateMock = "template.phtml"; - $templatesMock = [$templateMock]; - - $this->filesUtilsMock->expects($this->once())->method('getPhtmlFiles')->with(false, false) - ->willReturn($templatesMock); - $this->minifierMock->expects($this->once())->method('minify')->with($templateMock); - - self::assertEquals(1, $this->model->minifyTemplates()); - } -} diff --git a/app/code/Magento/Deploy/Test/Unit/Model/DeployManagerTest.php b/app/code/Magento/Deploy/Test/Unit/Model/DeployManagerTest.php deleted file mode 100644 index d1e5a81bf5b1d..0000000000000 --- a/app/code/Magento/Deploy/Test/Unit/Model/DeployManagerTest.php +++ /dev/null @@ -1,168 +0,0 @@ -deployStrategyProviderFactoryMock = $this->getMock( - \Magento\Deploy\Model\DeployStrategyProviderFactory::class, - ['create'], - [], - '', - false - ); - $this->versionStorageMock = $this->getMock( - \Magento\Framework\App\View\Deployment\Version\StorageInterface::class, - [], - [], - '', - false - ); - $this->minifierTemplateMock = $this->getMock( - \Magento\Deploy\Model\Deploy\TemplateMinifier::class, - [], - [], - '', - false - ); - $this->processQueueManagerFactoryMock = $this->getMock( - \Magento\Deploy\Model\ProcessQueueManagerFactory::class, - [], - [], - '', - false - ); - $this->stateMock = $this->getMockBuilder(\Magento\Framework\App\State::class) - ->disableOriginalConstructor() - ->getMock(); - $this->outputMock = $this->getMock(\Symfony\Component\Console\Output\OutputInterface::class, [], [], '', false); - } - - public function testSaveDeployedVersion() - { - $version = (new \DateTime())->getTimestamp(); - $this->outputMock->expects($this->once())->method('writeln')->with("New version of deployed files: {$version}"); - $this->versionStorageMock->expects($this->once())->method('save')->with($version); - - $this->assertEquals( - \Magento\Framework\Console\Cli::RETURN_SUCCESS, - $this->getModel([Options::NO_HTML_MINIFY => true])->deploy() - ); - } - - public function testSaveDeployedVersionDryRun() - { - $options = [Options::DRY_RUN => true, Options::NO_HTML_MINIFY => true]; - - $this->outputMock->expects(self::once())->method('writeln')->with( - 'Dry run. Nothing will be recorded to the target directory.' - ); - $this->versionStorageMock->expects($this->never())->method('save'); - - $this->getModel($options)->deploy(); - } - - public function testMinifyTemplates() - { - $this->minifierTemplateMock->expects($this->once())->method('minifyTemplates')->willReturn(2); - $this->outputMock->expects($this->atLeastOnce())->method('writeln')->withConsecutive( - ["=== Minify templates ==="], - ["\nSuccessful: 2 files modified\n---\n"] - ); - - $this->getModel([Options::NO_HTML_MINIFY => false])->deploy(); - } - - public function testMinifyTemplatesNoHtmlMinify() - { - $version = (new \DateTime())->getTimestamp(); - $this->outputMock->expects($this->once())->method('writeln')->with("New version of deployed files: {$version}"); - $this->versionStorageMock->expects($this->once())->method('save')->with($version); - - $this->getModel([Options::NO_HTML_MINIFY => true])->deploy(); - } - - public function testDeploy() - { - $area = 'frontend'; - $themePath = 'themepath'; - $locale = 'en_US'; - $options = [Options::NO_HTML_MINIFY => true]; - $strategyProviderMock = $this->getMock(\Magento\Deploy\Model\DeployStrategyProvider::class, [], [], '', false); - $deployStrategyMock = $this->getMock(\Magento\Deploy\Model\Deploy\DeployInterface::class, [], [], '', false); - - $model = $this->getModel($options); - $model->addPack($area, $themePath, $locale); - $this->deployStrategyProviderFactoryMock->expects($this->once())->method('create')->with( - ['output' => $this->outputMock, 'options' => $options] - )->willReturn($strategyProviderMock); - $strategyProviderMock->expects($this->once())->method('getDeployStrategies')->with($area, $themePath, [$locale]) - ->willReturn([$locale => $deployStrategyMock]); - $this->stateMock->expects(self::once())->method('emulateAreaCode') - ->with($area, [$deployStrategyMock, 'deploy'], [$area, $themePath, $locale]) - ->willReturn(\Magento\Framework\Console\Cli::RETURN_SUCCESS); - - $version = (new \DateTime())->getTimestamp(); - $this->outputMock->expects(self::once())->method('writeln')->with("New version of deployed files: {$version}"); - $this->versionStorageMock->expects($this->once())->method('save')->with($version); - - $this->assertEquals(\Magento\Framework\Console\Cli::RETURN_SUCCESS, $model->deploy()); - } - - /** - * @param array $options - * @return \Magento\Deploy\Model\DeployManager - */ - private function getModel(array $options) - { - return new \Magento\Deploy\Model\DeployManager( - $this->outputMock, - $this->versionStorageMock, - $this->deployStrategyProviderFactoryMock, - $this->processQueueManagerFactoryMock, - $this->minifierTemplateMock, - $this->stateMock, - $options - ); - } -} diff --git a/app/code/Magento/Deploy/Test/Unit/Model/DeployStrategyFactoryTest.php b/app/code/Magento/Deploy/Test/Unit/Model/DeployStrategyFactoryTest.php deleted file mode 100644 index d45b25e939e1f..0000000000000 --- a/app/code/Magento/Deploy/Test/Unit/Model/DeployStrategyFactoryTest.php +++ /dev/null @@ -1,53 +0,0 @@ -objectManagerMock = $this->getMock(ObjectManagerInterface::class); - - $this->unit = (new ObjectManager($this))->getObject( - DeployStrategyFactory::class, - [ - 'objectManager' => $this->objectManagerMock, - ] - ); - } - - /** - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Wrong deploy strategy type: wrong-type - */ - public function testCreateWithWrongStrategyType() - { - $this->unit->create('wrong-type'); - } - - public function testCreate() - { - $this->objectManagerMock->expects(self::once())->method('create') - ->with(LocaleDeploy::class, ['arg1' => 1]); - - $this->unit->create(DeployStrategyFactory::DEPLOY_STRATEGY_STANDARD, ['arg1' => 1]); - } -} diff --git a/app/code/Magento/Deploy/Test/Unit/Model/ProcessQueueManagerTest.php b/app/code/Magento/Deploy/Test/Unit/Model/ProcessQueueManagerTest.php deleted file mode 100644 index 4ee9493a9ad56..0000000000000 --- a/app/code/Magento/Deploy/Test/Unit/Model/ProcessQueueManagerTest.php +++ /dev/null @@ -1,85 +0,0 @@ -processManagerMock = $this->getMock(ProcessManager::class, [], [], '', false); - $this->resourceConnectionMock = $this->getMock(ResourceConnection::class, [], [], '', false); - $this->processTaskFactoryMock = $this->getMock(ProcessTaskFactory::class, ['create'], [], '', false); - $this->processTaskMock = $this->getMock(ProcessTask::class, [], [], '', false); - $this->processTaskFactoryMock->expects($this->any())->method('create')->willReturn($this->processTaskMock); - $this->model = (new ObjectManager($this))->getObject( - \Magento\Deploy\Model\ProcessQueueManager::class, - [ - 'processManager' => $this->processManagerMock, - 'resourceConnection' => $this->resourceConnectionMock, - 'processTaskFactory' => $this->processTaskFactoryMock - ] - ); - } - - public function testProcess() - { - $callableMock = function () { - return true; - }; - $this->processTaskMock->expects($this->any())->method('getHandler')->willReturn($callableMock); - - $processMock = $this->getMock(\Magento\Deploy\Model\Process::class, [], [], '', false); - - $this->model->addTaskToQueue($callableMock, []); - $this->processManagerMock->expects($this->atLeastOnce())->method('getProcesses')->willReturnOnConsecutiveCalls( - [$processMock], - [$processMock], - [$processMock], - [$processMock], - [$processMock], - [] - ); - $processMock->expects($this->once())->method('isCompleted')->willReturn(true); - $processMock->expects($this->atLeastOnce())->method('getPid')->willReturn(42); - $processMock->expects($this->once())->method('getStatus')->willReturn(0); - $this->processManagerMock->expects($this->once())->method('delete')->with($processMock); - - $this->resourceConnectionMock->expects(self::once())->method('closeConnection'); - - $this->assertEquals(0, $this->model->process()); - } -} diff --git a/app/code/Magento/Deploy/Test/Unit/Process/QueueTest.php b/app/code/Magento/Deploy/Test/Unit/Process/QueueTest.php new file mode 100644 index 0000000000000..a657a3a058a85 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Process/QueueTest.php @@ -0,0 +1,130 @@ +appState = $this->getMock(AppState::class, [], [], '', false); + $this->localeResolver = $this->getMockForAbstractClass( + LocaleResolver::class, + ['setLocale'], + '', + false + ); + $this->resourceConnection = $this->getMock( + ResourceConnection::class, + [], + [], + '', + false + ); + $this->logger = $this->getMockForAbstractClass( + LoggerInterface::class, + ['notice', 'info'], + '', + false + ); + $this->deployPackageService = $this->getMock(DeployPackage::class, ['deploy'], [], '', false); + + $this->queue = new Queue( + $this->appState, + $this->localeResolver, + $this->resourceConnection, + $this->logger, + $this->deployPackageService, + [], + 1 + ); + } + + /** + * @see Queue:add() + */ + public function testAdd() + { + $package = $this->getMock(Package::class, [], [], '', false); + $package->expects($this->once())->method('getPath')->willReturn('path'); + + $this->assertEquals(true, $this->queue->add($package)); + $packages = $this->queue->getPackages(); + $this->assertEquals( + $package, + isset($packages['path']['package']) ? $packages['path']['package'] : null + ); + } + + /** + * @see Queue::process() + */ + public function testProcess() + { + $package = $this->getMock(Package::class, [], [], '', false); + $package->expects($this->any())->method('getState')->willReturn(1); + $package->expects($this->once())->method('getParent')->willReturn(null); + $package->expects($this->any())->method('getArea')->willReturn('area'); + $package->expects($this->any())->method('getPath')->willReturn('path'); + $package->expects($this->any())->method('getFiles')->willReturn([]); + + $this->appState->expects($this->once())->method('emulateAreaCode'); + + $this->queue->add($package, []); + + $this->resourceConnection->expects(self::never())->method('closeConnection'); + + $this->assertEquals(0, $this->queue->process()); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php new file mode 100644 index 0000000000000..eecc185b2b27e --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php @@ -0,0 +1,196 @@ +deployStrategyFactory = $this->getMock( + DeployStrategyFactory::class, + ['create'], + [], + '', + false + ); + $this->queueFactory = $this->getMock( + QueueFactory::class, + ['create'], + [], + '', + false + ); + $this->logger = $this->getMockForAbstractClass( + LoggerInterface::class, + [], + '', + false + ); + $this->objectManager = $this->getMock( + ObjectManagerInterface::class, + ['create', 'get', 'configure'], + [], + '', + false + ); + $this->versionStorage = $this->getMockForAbstractClass( + StorageInterface::class, + ['save'], + '', + false + ); + $this->versionStorage->expects($this->once())->method('save'); + + $this->service = new DeployStaticContent( + $this->objectManager, + $this->logger, + $this->versionStorage, + $this->deployStrategyFactory, + $this->queueFactory + ); + } + + public function testDeploy() + { + $options = [ + 'strategy' => 'compact', + 'no-javascript' => false, + 'no-html-minify' => false + ]; + + $package = $this->getMock(Package::class, [], [], '', false); + $package->expects($this->exactly(1))->method('isVirtual')->willReturn(false); + $package->expects($this->exactly(3))->method('getArea')->willReturn('area'); + $package->expects($this->exactly(3))->method('getTheme')->willReturn('theme'); + $package->expects($this->exactly(2))->method('getLocale')->willReturn('locale'); + + $packages = [ + 'package' => $package + ]; + + $this->versionStorage->expects($this->once())->method('save'); + + $queue = $this->getMockBuilder(Queue::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->queueFactory->expects($this->once())->method('create')->willReturn($queue); + + $strategy = $this->getMockBuilder(CompactDeploy::class) + ->setMethods(['deploy']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $strategy->expects($this->once())->method('deploy') + ->with($options) + ->willReturn($packages); + $this->deployStrategyFactory->expects($this->once()) + ->method('create') + ->with('compact', ['queue' => $queue]) + ->willReturn($strategy); + + $deployPackageService = $this->getMockBuilder(DeployPackage::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $deployRjsConfig = $this->getMockBuilder(DeployRequireJsConfig::class) + ->setMethods(['deploy']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $deployI18n = $this->getMockBuilder(DeployTranslationsDictionary::class) + ->setMethods(['deploy']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $deployBundle = $this->getMockBuilder(Bundle::class) + ->setMethods(['deploy']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $minifyTemplates = $this->getMockBuilder(MinifyTemplates::class) + ->setMethods(['minifyTemplates']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->objectManager->expects($this->exactly(4)) + ->method('create') + ->withConsecutive( + [DeployPackage::class, ['logger' => $this->logger]], + [DeployRequireJsConfig::class, ['logger' => $this->logger]], + [DeployTranslationsDictionary::class, ['logger' => $this->logger]], + [Bundle::class, ['logger' => $this->logger]] + ) + ->willReturnOnConsecutiveCalls( + $deployPackageService, + $deployRjsConfig, + $deployI18n, + $deployBundle + ); + + $this->objectManager->expects($this->exactly(1)) + ->method('get') + ->withConsecutive( + [MinifyTemplates::class] + ) + ->willReturnOnConsecutiveCalls( + $minifyTemplates + ); + + $this->assertEquals( + null, + $this->service->deploy($options) + ); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Service/DeployTranslationsDictionaryTest.php b/app/code/Magento/Deploy/Test/Unit/Service/DeployTranslationsDictionaryTest.php new file mode 100644 index 0000000000000..df78ddc5ac281 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Service/DeployTranslationsDictionaryTest.php @@ -0,0 +1,122 @@ +jsTranslationConfig = $this->getMock( + JsTranslationConfig::class, + ['getDictionaryFileName'], + [], + '', + false + ); + $this->jsTranslationConfig + ->expects($this->exactly(2)) + ->method('getDictionaryFileName') + ->willReturn($dictionary); + + $this->deployStaticFile = $this->getMockBuilder(DeployStaticFile::class) + ->disableOriginalConstructor() + ->setMethods(['deployFile']) + ->getMock(); + $this->deployStaticFile->expects($this->exactly(1))->method('deployFile') + ->willReturnCallback( + function ($checkDictionary, $params) use ($dictionary, $area, $theme, $locale) { + $this->assertEquals($dictionary, $checkDictionary); + $this->assertEquals($dictionary, $params['fileName']); + $this->assertEquals($area, $params['area']); + $this->assertEquals($theme, $params['theme']); + $this->assertEquals($locale, $params['locale']); + } + ); + + $this->state = $this->getMockBuilder(State::class) + ->disableOriginalConstructor() + ->setMethods(['emulateAreaCode']) + ->getMock(); + $this->state->expects($this->exactly(1))->method('emulateAreaCode') + ->willReturnCallback( + function ($area, $callback) { + $this->assertEquals('adminhtml', $area); + $callback(); + } + ); + + $this->logger = $this->getMockForAbstractClass( + LoggerInterface::class, + [], + '', + false + ); + + $this->service = new DeployTranslationsDictionary( + $this->jsTranslationConfig, + $this->deployStaticFile, + $this->state, + $this->logger + ); + } + + /** + * @see DeployTranslationsDictionary::deploy() + */ + public function testDeploy() + { + $area = 'adminhtml'; + $theme = 'Magento/backend'; + $locale = 'uk_UA'; + $this->service->deploy($area, $theme, $locale); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Service/MinifyTemplatesTest.php b/app/code/Magento/Deploy/Test/Unit/Service/MinifyTemplatesTest.php new file mode 100644 index 0000000000000..2670ab7c06983 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Service/MinifyTemplatesTest.php @@ -0,0 +1,78 @@ +filesUtils = $this->getMock( + Files::class, + ['getPhtmlFiles'], + [], + '', + false + ); + + $this->htmlMinifier = $this->getMockForAbstractClass( + MinifierInterface::class, + ['minify'], + '', + false + ); + + $this->service = new MinifyTemplates( + $this->filesUtils, + $this->htmlMinifier + ); + } + + /** + * @see MinifyTemplates::minifyTemplates() + */ + public function testMinifyTemplates() + { + $templateMock = "template.phtml"; + $templatesMock = [$templateMock]; + + $this->filesUtils->expects($this->once()) + ->method('getPhtmlFiles') + ->with(false, false) + ->willReturn($templatesMock); + + $this->htmlMinifier->expects($this->once())->method('minify')->with($templateMock); + + $this->assertEquals(1, $this->service->minifyTemplates()); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Strategy/CompactDeployTest.php b/app/code/Magento/Deploy/Test/Unit/Strategy/CompactDeployTest.php new file mode 100644 index 0000000000000..c894d91867aa2 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Strategy/CompactDeployTest.php @@ -0,0 +1,125 @@ +options = [ + 'opt1' => '', + 'opt2' => '' + ]; + + $virtualPackage = $this->getMock(Package::class, [], [], '', false); + $virtualPackage->expects($this->exactly(1)) + ->method('isVirtual') + ->willReturn(true); + $virtualPackage->expects($this->atLeastOnce()) + ->method('getParentPackages') + ->willReturn([]); + $virtualPackage->expects($this->never()) + ->method('setParam') + ->willReturn('virtual'); + + $realPackage = $this->getMock(Package::class, [], [], '', false); + $realPackage->expects($this->exactly(1)) + ->method('isVirtual') + ->willReturn(false); + $realPackage->expects($this->atLeastOnce()) + ->method('getParentPackages') + ->willReturn([]); + $realPackage->expects($this->exactly(1)) + ->method('setParam') + ->willReturn('virtual'); + + $this->packages = [ + 'virtual' => $virtualPackage, + 'real' => $realPackage + ]; + $this->packagePool = $this->getMock( + PackagePool::class, + ['getPackagesForDeployment'], + [], + '', + false + ); + $this->packagePool->expects($this->once()) + ->method('getPackagesForDeployment') + ->with($this->options) + ->willReturn($this->packages); + + $this->queue = $this->getMock( + Queue::class, + ['add', 'process'], + [], + '', + false + ); + $this->queue->expects($this->exactly(2))->method('add'); + $this->queue->expects($this->exactly(1))->method('process'); + + $this->strategy = new CompactDeploy( + $this->packagePool, + $this->queue + ); + } + + /** + * @see CompactDeploy::deploy() + */ + public function testDeploy() + { + $this->assertEquals( + $this->packages, + $this->strategy->deploy($this->options) + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php index 418bdaf4bcc23..b4d09fe6eaaab 100644 --- a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php +++ b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php @@ -13,7 +13,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\Directory\ReadInterface; -use Magento\Deploy\Console\Command\DeployStaticOptions as Options; +use Magento\Deploy\Console\DeployStaticOptions as Options; use Magento\Framework\Config\View; use Magento\Deploy\Config\BundleConfig; use Magento\Framework\Filesystem\Directory\WriteInterface; diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php index 7ae4f04ace7b8..d568037248a6b 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php @@ -5,9 +5,12 @@ */ namespace Magento\Framework\View\Asset; +use Magento\Deploy\Console\ConsoleLogger; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\App\State as AppState; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\State as AppState; +use Magento\Deploy\Console\DeployStaticOptions as Options; +use Magento\Deploy\Strategy\DeployStrategyFactory; /** * Tests for minifier @@ -214,10 +217,6 @@ public function testDeploymentWithMinifierEnabled() ->method('create') ->will($this->returnValue($this->objectManager)); - $output = $this->objectManager->create( - \Symfony\Component\Console\Output\ConsoleOutput::class - ); - $filesUtil = $this->getMock(\Magento\Framework\App\Utility\Files::class, [], [], '', false); $filesUtil->expects($this->any()) ->method('getStaticLibraryFiles') @@ -235,13 +234,57 @@ public function testDeploymentWithMinifierEnabled() ] )); - /** @var \Magento\Deploy\Model\Deploy\LocaleDeploy $deployer */ - $deployer = $this->objectManager->create( - \Magento\Deploy\Model\Deploy\LocaleDeploy::class, - ['filesUtil' => $filesUtil, 'output' => $output] + $this->objectManager->addSharedInstance($filesUtil, \Magento\Framework\App\Utility\Files::class); + + $output = $this->objectManager->create( + \Symfony\Component\Console\Output\ConsoleOutput::class + ); + + $logger = $this->objectManager->create( + ConsoleLogger::class, + ['output' => $output] + ); + + $versionStorage = $this->getMock( + \Magento\Framework\App\View\Deployment\Version\StorageInterface::class, + ['save', 'load'], + [], + '', + false + ); + + /** @var \Magento\Deploy\Service\DeployStaticContent $deployService */ + $deployService = $this->objectManager->create( + \Magento\Deploy\Service\DeployStaticContent::class, + [ + 'objectManager' => $this->objectManager, + 'logger' => $logger, + 'versionStorage' => $versionStorage, + ] ); - $deployer->deploy('frontend', 'FrameworkViewMinifier/default', 'en_US', []); + $deployService->deploy( + [ + Options::DRY_RUN => false, + Options::NO_JAVASCRIPT => true, + Options::NO_CSS => false, + Options::NO_LESS => false, + Options::NO_IMAGES => true, + Options::NO_FONTS => true, + Options::NO_HTML => true, + Options::NO_MISC => true, + Options::NO_HTML_MINIFY => true, + Options::AREA => ['frontend'], + Options::EXCLUDE_AREA => ['none'], + Options::THEME => ['FrameworkViewMinifier/default'], + Options::EXCLUDE_THEME => ['none'], + Options::LANGUAGE => ['en_US'], + Options::EXCLUDE_LANGUAGE => ['none'], + Options::JOBS_AMOUNT => 0, + Options::SYMLINK_LOCALE => false, + Options::STRATEGY => DeployStrategyFactory::DEPLOY_STRATEGY_QUICK + ] + ); $this->assertFileExists($fileToBePublished); $this->assertEquals( diff --git a/setup/src/Magento/Setup/Console/Command/Deploy/StaticContentCommand.php b/setup/src/Magento/Setup/Console/Command/Deploy/StaticContentCommand.php deleted file mode 100644 index d24d1b4eaa35c..0000000000000 --- a/setup/src/Magento/Setup/Console/Command/Deploy/StaticContentCommand.php +++ /dev/null @@ -1,167 +0,0 @@ -inputValidator = $inputValidator; - $this->consoleLoggerFactory = $consoleLoggerFactory; - $this->options = $options; - $this->objectManager = $objectManagerProvider->get(); - - parent::__construct(); - } - - /** - * {@inheritdoc} - * @throws \InvalidArgumentException - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - protected function configure() - { - $this->setName('setup:static-content:deploy') - ->setDescription('Deploys static view files') - ->setDefinition($this->options->getOptionsList()); - - parent::configure(); - } - - /** - * {@inheritdoc} - * @throws \InvalidArgumentException - * @throws LocalizedException - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $time = microtime(true); - - if (!$input->getOption(Options::FORCE_RUN) && $this->getAppState()->getMode() !== State::MODE_PRODUCTION) { - throw new LocalizedException( - __( - 'NOTE: Manual static content deployment is not required in "default" and "developer" modes.' - . PHP_EOL . 'In "default" and "developer" modes static contents are being deployed ' - . 'automatically on demand.' - . PHP_EOL . 'If you still want to deploy in these modes, use -f option: ' - . "'bin/magento setup:deploy:static-content -f'" - ) - ); - } - - $this->inputValidator->validate($input); - - $options = $input->getOptions(); - $options[Options::LANGUAGE] = $input->getArgument(Options::LANGUAGES_ARGUMENT) ?: ['all']; - - $verbose = $output->getVerbosity() > 1 ? $output->getVerbosity() : OutputInterface::VERBOSITY_VERBOSE; - - $logger = $this->consoleLoggerFactory->getLogger($output, $verbose); - $logger->alert(PHP_EOL . "Deploy using {$options[Options::STRATEGY]} strategy"); - - $this->mockCache(); - - /** @var DeployStaticContent $deployService */ - $deployService = $this->objectManager->create(DeployStaticContent::class, [ - 'logger' => $logger - ]); - - $deployService->deploy($options); - - $logger->alert(PHP_EOL . "Execution time: " . (microtime(true) - $time)); - - return \Magento\Framework\Console\Cli::RETURN_SUCCESS; - } - - /** - * Mock Cache class with dummy implementation - * - * @return void - */ - private function mockCache() - { - $this->objectManager->configure([ - 'preferences' => [ - Cache::class => DummyCache::class - ] - ]); - } - - /** - * @return State - */ - private function getAppState() - { - if (null === $this->appState) { - $this->appState = $this->objectManager->get(State::class); - } - return $this->appState; - } -} diff --git a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php index 8a195f432d2f0..017051133195f 100644 --- a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php @@ -5,54 +5,41 @@ */ namespace Magento\Setup\Console\Command; -use Magento\Deploy\Console\Command\DeployStaticOptions as Options; -use Magento\Deploy\Model\DeployManager; -use Magento\Setup\Model\ObjectManagerProvider; -use Magento\Framework\App\Utility\Files; -use Magento\Framework\ObjectManagerInterface; -use Magento\Framework\Validator\Locale; -use Magento\Framework\Exception\LocalizedException; +use Magento\Deploy\Console\InputValidator; +use Magento\Deploy\Console\ConsoleLoggerFactory; +use Magento\Deploy\Console\DeployStaticOptions as Options; use Magento\Framework\App\State; -use Magento\Framework\App\Cache; -use Magento\Framework\App\Cache\Type\Dummy as DummyCache; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Magento\Setup\Model\ObjectManagerProvider; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\App\Cache; +use Magento\Framework\App\Cache\Type\Dummy as DummyCache; +use Magento\Framework\Exception\LocalizedException; +use Magento\Deploy\Service\DeployStaticContent; /** * Deploy static content command + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @deprecated since 2.2.0 @see \Magento\Setup\Console\Command\Deploy\StaticContentCommand */ class DeployStaticContentCommand extends Command { - /** - * Key for dry-run option - * - * @deprecated - * @see \Magento\Deploy\Console\Command\DeployStaticOptions::DRY_RUN - */ - const DRY_RUN_OPTION = 'dry-run'; - /** * Default language value */ const DEFAULT_LANGUAGE_VALUE = 'en_US'; /** - * Key for languages parameter - */ - const LANGUAGES_ARGUMENT = 'languages'; - - /** - * @var InputInterface + * @var InputValidator */ - private $input; + private $inputValidator; /** - * @var Locale + * @var ConsoleLoggerFactory */ - private $validator; + private $consoleLoggerFactory; /** * @var Options @@ -73,19 +60,21 @@ class DeployStaticContentCommand extends Command private $appState; /** - * Inject dependencies + * StaticContentCommand constructor * - * @param Locale $validator + * @param InputValidator $inputValidator + * @param ConsoleLoggerFactory $consoleLoggerFactory * @param Options $options * @param ObjectManagerProvider $objectManagerProvider - * @throws \LogicException When the command name is empty */ public function __construct( - Locale $validator, + InputValidator $inputValidator, + ConsoleLoggerFactory $consoleLoggerFactory, Options $options, ObjectManagerProvider $objectManagerProvider ) { - $this->validator = $validator; + $this->inputValidator = $inputValidator; + $this->consoleLoggerFactory = $consoleLoggerFactory; $this->options = $options; $this->objectManager = $objectManagerProvider->get(); @@ -95,151 +84,17 @@ public function __construct( /** * {@inheritdoc} * @throws \InvalidArgumentException + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function configure() { - $this->setName('setup:static-content:deploy:old') + $this->setName('setup:static-content:deploy') ->setDescription('Deploys static view files') ->setDefinition($this->options->getOptionsList()); parent::configure(); } - /** - * @return \Magento\Framework\App\State - * @deprecated - */ - private function getAppState() - { - if (null === $this->appState) { - $this->appState = $this->objectManager->get(State::class); - } - return $this->appState; - } - - /** - * {@inheritdoc} - * @param $magentoAreas array - * @param $areasInclude array - * @param $areasExclude array - * @throws \InvalidArgumentException - */ - private function checkAreasInput($magentoAreas, $areasInclude, $areasExclude) - { - if ($areasInclude[0] != 'all' && $areasExclude[0] != 'none') { - throw new \InvalidArgumentException( - '--area (-a) and --exclude-area cannot be used at the same time' - ); - } - - if ($areasInclude[0] != 'all') { - foreach ($areasInclude as $area) { - if (!in_array($area, $magentoAreas)) { - throw new \InvalidArgumentException( - $area . - ' argument has invalid value, available areas are: ' . implode(', ', $magentoAreas) - ); - } - } - } - - if ($areasExclude[0] != 'none') { - foreach ($areasExclude as $area) { - if (!in_array($area, $magentoAreas)) { - throw new \InvalidArgumentException( - $area . - ' argument has invalid value, available areas are: ' . implode(', ', $magentoAreas) - ); - } - } - } - } - - /** - * {@inheritdoc} - * @param $languagesInclude array - * @param $languagesExclude array - * @throws \InvalidArgumentException - */ - private function checkLanguagesInput($languagesInclude, $languagesExclude) - { - if ($languagesInclude[0] != 'all') { - foreach ($languagesInclude as $lang) { - if (!$this->validator->isValid($lang)) { - throw new \InvalidArgumentException( - $lang . - ' argument has invalid value, please run info:language:list for list of available locales' - ); - } - } - } - - if ($languagesInclude[0] != 'all' && $languagesExclude[0] != 'none') { - throw new \InvalidArgumentException( - '--language (-l) and --exclude-language cannot be used at the same time' - ); - } - } - - /** - * {@inheritdoc} - * @param $magentoThemes array - * @param $themesInclude array - * @param $themesExclude array - * @throws \InvalidArgumentException - */ - private function checkThemesInput($magentoThemes, $themesInclude, $themesExclude) - { - if ($themesInclude[0] != 'all' && $themesExclude[0] != 'none') { - throw new \InvalidArgumentException( - '--theme (-t) and --exclude-theme cannot be used at the same time' - ); - } - - if ($themesInclude[0] != 'all') { - foreach ($themesInclude as $theme) { - if (!in_array($theme, $magentoThemes)) { - throw new \InvalidArgumentException( - $theme . - ' argument has invalid value, available themes are: ' . implode(', ', $magentoThemes) - ); - } - } - } - - if ($themesExclude[0] != 'none') { - foreach ($themesExclude as $theme) { - if (!in_array($theme, $magentoThemes)) { - throw new \InvalidArgumentException( - $theme . - ' argument has invalid value, available themes are: ' . implode(', ', $magentoThemes) - ); - } - } - } - } - - /** - * {@inheritdoc} - * @param $entities array - * @param $includedEntities array - * @param $excludedEntities array - * @return array - */ - private function getDeployableEntities($entities, $includedEntities, $excludedEntities) - { - $deployableEntities = []; - if ($includedEntities[0] === 'all' && $excludedEntities[0] === 'none') { - $deployableEntities = $entities; - } elseif ($excludedEntities[0] !== 'none') { - $deployableEntities = array_diff($entities, $excludedEntities); - } elseif ($includedEntities[0] !== 'all') { - $deployableEntities = array_intersect($entities, $includedEntities); - } - - return $deployableEntities; - } - /** * {@inheritdoc} * @throws \InvalidArgumentException @@ -247,6 +102,8 @@ private function getDeployableEntities($entities, $includedEntities, $excludedEn */ protected function execute(InputInterface $input, OutputInterface $output) { + $time = microtime(true); + if (!$input->getOption(Options::FORCE_RUN) && $this->getAppState()->getMode() !== State::MODE_PRODUCTION) { throw new LocalizedException( __( @@ -254,100 +111,33 @@ protected function execute(InputInterface $input, OutputInterface $output) . PHP_EOL . 'In "default" and "developer" modes static contents are being deployed ' . 'automatically on demand.' . PHP_EOL . 'If you still want to deploy in these modes, use -f option: ' - . "'bin/magento setup:static-content:deploy -f'" + . "'bin/magento setup:deploy:static-content -f'" ) ); } - $this->input = $input; - $filesUtil = $this->objectManager->create(Files::class); - - list ($deployableLanguages, $deployableAreaThemeMap, $requestedThemes) - = $this->prepareDeployableEntities($filesUtil); + $this->inputValidator->validate($input); - $output->writeln('Requested languages: ' . implode(', ', $deployableLanguages)); - $output->writeln('Requested areas: ' . implode(', ', array_keys($deployableAreaThemeMap))); - $output->writeln('Requested themes: ' . implode(', ', $requestedThemes)); + $options = $input->getOptions(); + $options[Options::LANGUAGE] = $input->getArgument(Options::LANGUAGES_ARGUMENT) ?: ['all']; - /** @var $deployManager DeployManager */ - $deployManager = $this->objectManager->create( - DeployManager::class, - [ - 'output' => $output, - 'options' => $this->input->getOptions(), - ] - ); + $verbose = $output->getVerbosity() > 1 ? $output->getVerbosity() : OutputInterface::VERBOSITY_VERBOSE; - foreach ($deployableAreaThemeMap as $area => $themes) { - foreach ($deployableLanguages as $locale) { - foreach ($themes as $themePath) { - $deployManager->addPack($area, $themePath, $locale); - } - } - } + $logger = $this->consoleLoggerFactory->getLogger($output, $verbose); + $logger->alert(PHP_EOL . "Deploy using {$options[Options::STRATEGY]} strategy"); $this->mockCache(); - return $deployManager->deploy(); - } - - /** - * @param Files $filesUtil - * @throws \InvalidArgumentException - * @return array - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - private function prepareDeployableEntities($filesUtil) - { - $magentoAreas = []; - $magentoThemes = []; - $magentoLanguages = [self::DEFAULT_LANGUAGE_VALUE]; - $areaThemeMap = []; - $files = $filesUtil->getStaticPreProcessingFiles(); - foreach ($files as $info) { - list($area, $themePath, $locale) = $info; - if ($themePath) { - $areaThemeMap[$area][$themePath] = $themePath; - } - if ($themePath && $area && !in_array($area, $magentoAreas)) { - $magentoAreas[] = $area; - } - if ($locale && !in_array($locale, $magentoLanguages)) { - $magentoLanguages[] = $locale; - } - if ($themePath && !in_array($themePath, $magentoThemes)) { - $magentoThemes[] = $themePath; - } - } - - $areasInclude = $this->input->getOption(Options::AREA); - $areasExclude = $this->input->getOption(Options::EXCLUDE_AREA); - $this->checkAreasInput($magentoAreas, $areasInclude, $areasExclude); - $deployableAreas = $this->getDeployableEntities($magentoAreas, $areasInclude, $areasExclude); - $languagesInclude = $this->input->getArgument(self::LANGUAGES_ARGUMENT) - ?: $this->input->getOption(Options::LANGUAGE); - $languagesExclude = $this->input->getOption(Options::EXCLUDE_LANGUAGE); - $this->checkLanguagesInput($languagesInclude, $languagesExclude); - $deployableLanguages = $languagesInclude[0] == 'all' - ? $this->getDeployableEntities($magentoLanguages, $languagesInclude, $languagesExclude) - : $languagesInclude; + /** @var DeployStaticContent $deployService */ + $deployService = $this->objectManager->create(DeployStaticContent::class, [ + 'logger' => $logger + ]); - $themesInclude = $this->input->getOption(Options::THEME); - $themesExclude = $this->input->getOption(Options::EXCLUDE_THEME); - $this->checkThemesInput($magentoThemes, $themesInclude, $themesExclude); - $deployableThemes = $this->getDeployableEntities($magentoThemes, $themesInclude, $themesExclude); + $deployService->deploy($options); - $deployableAreaThemeMap = []; - $requestedThemes = []; - foreach ($areaThemeMap as $area => $themes) { - if (in_array($area, $deployableAreas) && $themes = array_intersect($themes, $deployableThemes)) { - $deployableAreaThemeMap[$area] = $themes; - $requestedThemes += $themes; - } - } + $logger->alert(PHP_EOL . "Execution time: " . (microtime(true) - $time)); - return [$deployableLanguages, $deployableAreaThemeMap, $requestedThemes]; + return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } /** @@ -363,4 +153,15 @@ private function mockCache() ] ]); } + + /** + * @return State + */ + private function getAppState() + { + if (null === $this->appState) { + $this->appState = $this->objectManager->get(State::class); + } + return $this->appState; + } } diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index 15477d647e63a..469a66bf5d798 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -73,7 +73,6 @@ protected function getCommandsClasses() \Magento\Setup\Console\Command\UpgradeCommand::class, \Magento\Setup\Console\Command\UninstallCommand::class, \Magento\Setup\Console\Command\DeployStaticContentCommand::class, - \Magento\Setup\Console\Command\Deploy\StaticContentCommand::class, ]; } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DeployStaticContentCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DeployStaticContentCommandTest.php index 2017d7c1650ca..53e9629103645 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DeployStaticContentCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DeployStaticContentCommandTest.php @@ -5,168 +5,120 @@ */ namespace Magento\Setup\Test\Unit\Console\Command; -use Magento\Deploy\Console\Command\DeployStaticOptions; -use Magento\Deploy\Model\DeployManager; -use Magento\Framework\App\Utility\Files; use Magento\Setup\Console\Command\DeployStaticContentCommand; use Magento\Setup\Model\ObjectManagerProvider; -use Symfony\Component\Console\Tester\CommandTester; -use Magento\Framework\Validator\Locale; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + +use Magento\Deploy\Console\ConsoleLogger; +use Magento\Deploy\Console\InputValidator; +use Magento\Deploy\Console\ConsoleLoggerFactory; +use Magento\Deploy\Console\DeployStaticOptions; +use Magento\Deploy\Service\DeployStaticContent; + use Magento\Framework\App\State; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + +use Symfony\Component\Console\Tester\CommandTester; -require 'FunctionExistMock.php'; +use PHPUnit_Framework_MockObject_MockObject as Mock; class DeployStaticContentCommandTest extends \PHPUnit_Framework_TestCase { /** - * @var DeployManager|\PHPUnit_Framework_MockObject_MockObject + * @var DeployStaticContentCommand */ - private $deployer; + private $command; /** - * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var InputValidator|Mock */ - private $objectManager; + private $inputValidator; /** - * @var \Magento\Framework\App\Utility\Files|\PHPUnit_Framework_MockObject_MockObject + * @var ConsoleLogger|Mock */ - private $filesUtil; + private $logger; /** - * @var DeployStaticContentCommand + * @var ConsoleLoggerFactory|Mock */ - private $command; + private $consoleLoggerFactory; + + /** + * @var DeployStaticContent|Mock + */ + private $deployService; /** - * @var Locale|\PHPUnit_Framework_MockObject_MockObject + * @var DeployStaticOptions|Mock */ - private $validator; + private $options; /** - * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject + * Object manager to create various objects + * + * @var ObjectManagerInterface|Mock + * + */ + private $objectManager; + + /** + * @var State|Mock */ private $appState; + /** + * @inheritdoc + */ protected function setUp() { - $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class); - $this->deployer = $this->getMock(DeployManager::class, [], [], '', false); - $this->filesUtil = $this->getMock(\Magento\Framework\App\Utility\Files::class, [], [], '', false); - $this->appState = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false); - - $objectManagerProviderMock = $this->getMock( + $this->inputValidator = $this->getMock(InputValidator::class, [], [], '', false); + $this->consoleLoggerFactory = $this->getMock(ConsoleLoggerFactory::class, [], [], '', false); + $this->logger = $this->getMock(ConsoleLogger::class, [], [], '', false); + $this->options = $this->getMock(DeployStaticOptions::class, [], [], '', false); + $this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); + $this->appState = $this->getMock(State::class, [], [], '', false); + $this->deployService = $this->getMock(DeployStaticContent::class, [], [], '', false); + + $objectManagerProvider = $this->getMock( ObjectManagerProvider::class, [], [], '', false ); - $objectManagerProviderMock->method('get')->willReturn($this->objectManager); - - $this->objectManager->method('get')->with(State::class)->willReturn($this->appState); + $objectManagerProvider->method('get')->willReturn($this->objectManager); - $this->validator = $this->getMock(\Magento\Framework\Validator\Locale::class, [], [], '', false); $this->command = (new ObjectManager($this))->getObject(DeployStaticContentCommand::class, [ - 'validator' => $this->validator, + 'inputValidator' => $this->inputValidator, + 'consoleLoggerFactory' => $this->consoleLoggerFactory, 'options' => new DeployStaticOptions(), - 'objectManagerProvider' => $objectManagerProviderMock - ]); - } - - public function testExecute() - { - $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->filesUtil); - $this->objectManager->expects($this->at(2))->method('create')->willReturn($this->deployer); - - $this->appState->expects($this->once())->method('getMode')->willReturn(State::MODE_PRODUCTION); - $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]); - $this->deployer->expects($this->once())->method('deploy'); - - $tester = new CommandTester($this->command); - $tester->execute([]); - } - - public function testExecuteValidateLanguages() - { - $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->filesUtil); - $this->objectManager->expects($this->at(2))->method('create')->willReturn($this->deployer); - - $this->appState->expects($this->once())->method('getMode')->willReturn(State::MODE_PRODUCTION); - $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]); - $this->deployer->expects($this->once())->method('deploy'); - $this->validator->expects(self::exactly(2))->method('isValid')->willReturnMap([ - ['en_US', true], - ['uk_UA', true], + 'appState' => $this->appState, + 'objectManagerProvider' => $objectManagerProvider ]); - - $tester = new CommandTester($this->command); - $tester->execute(['languages' => ['en_US', 'uk_UA']]); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage --language (-l) and --exclude-language cannot be used at the same tim - */ - public function testExecuteIncludedExcludedLanguages() - { - $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->filesUtil); - - $this->appState->expects($this->once())->method('getMode')->willReturn(State::MODE_PRODUCTION); - $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]); - $this->validator->expects(self::exactly(2))->method('isValid')->willReturnMap([ - ['en_US', true], - ['uk_UA', true], - ]); - - $tester = new CommandTester($this->command); - $tester->execute(['--language' => ['en_US', 'uk_UA'], '--exclude-language' => 'ru_RU']); } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage --area (-a) and --exclude-area cannot be used at the same tim + * @see DeployStaticContentCommand::execute() */ - public function testExecuteIncludedExcludedAreas() + public function testExecute() { - $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->filesUtil); + $this->appState->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_PRODUCTION); - $this->appState->expects($this->once())->method('getMode')->willReturn(State::MODE_PRODUCTION); - $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]); - - $tester = new CommandTester($this->command); - $tester->execute(['--area' => ['a1', 'a2'], '--exclude-area' => 'a3']); - } + $this->inputValidator->expects($this->once()) + ->method('validate'); - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage --theme (-t) and --exclude-theme cannot be used at the same tim - */ - public function testExecuteIncludedExcludedThemes() - { - $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->filesUtil); + $this->consoleLoggerFactory->expects($this->once()) + ->method('getLogger')->willReturn($this->logger); + $this->logger->expects($this->exactly(2))->method('alert'); - $this->appState->expects($this->once())->method('getMode')->willReturn(State::MODE_PRODUCTION); - $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]); + $this->objectManager->expects($this->once())->method('create')->willReturn($this->deployService); + $this->deployService->expects($this->once())->method('deploy'); $tester = new CommandTester($this->command); - $tester->execute(['--theme' => ['t1', 't2'], '--exclude-theme' => 't3']); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage ARG_IS_WRONG argument has invalid value, please run info:language:list - */ - public function testExecuteInvalidLanguageArgument() - { - $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->filesUtil); - - $this->appState->expects($this->once())->method('getMode')->willReturn(State::MODE_PRODUCTION); - $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]); - $wrongParam = ['languages' => ['ARG_IS_WRONG']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($wrongParam); + $tester->execute([]); } /**