From 19f92dd354534aed6afc48af2ff167eea4a0958d Mon Sep 17 00:00:00 2001 From: Oleh Posyniak <oposyniak@magento.com> Date: Wed, 28 Dec 2016 16:43:54 +0200 Subject: [PATCH] MAGETWO-62655: [GitHub] CLI won't work without write permissions #7933 --- .../Magento/Framework/Console/Cli.php | 60 ++++++++++--------- .../Framework/Console/Test/Unit/CliTest.php | 47 +++++++++++++++ 2 files changed, 80 insertions(+), 27 deletions(-) create mode 100644 lib/internal/Magento/Framework/Console/Test/Unit/CliTest.php diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php index 4da186fcf88..c42d7a2ea72 100644 --- a/lib/internal/Magento/Framework/Console/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -9,17 +9,18 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Composer\ComposerJsonFinder; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Application as SymfonyApplication; use Magento\Framework\App\Bootstrap; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Shell\ComplexParameter; use Magento\Setup\Console\CompilerPreparation; -use \Magento\Framework\App\ProductMetadata; +use Magento\Framework\App\ProductMetadata; +use Magento\Framework\ObjectManagerInterface; /** - * Magento 2 CLI Application. This is the hood for all command line tools supported by Magento + * Magento 2 CLI Application. + * This is the hood for all command line tools supported by Magento. * * {@inheritdoc} * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -27,50 +28,55 @@ use \Magento\Framework\App\ProductMetadata; class Cli extends SymfonyApplication { /** - * Name of input option + * Name of input option. */ const INPUT_KEY_BOOTSTRAP = 'bootstrap'; - /** - * Cli exit codes + /**#@+ + * Cli exit codes. */ const RETURN_SUCCESS = 0; const RETURN_FAILURE = 1; + /**#@-*/ - /** @var \Zend\ServiceManager\ServiceManager */ + /** + * Service Manager. + * + * @var \Zend\ServiceManager\ServiceManager + */ private $serviceManager; /** - * Initialization exception + * Initialization exception. * * @var \Exception */ private $initException; /** - * @param string $name application name - * @param string $version application version + * Constructor. + * + * @param string $name the application name + * @param string $version the application version + * * @SuppressWarnings(PHPMD.ExitExpression) */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') ->getServiceManager(); - $generationDirectoryAccess = new GenerationDirectoryAccess($this->serviceManager); - if (!$generationDirectoryAccess->check()) { - $output = new ConsoleOutput(); - $output->writeln( - '<error>Command line user does not have read and write permissions on var/generation directory. Please' - . ' address this issue before using Magento command line.</error>' - ); - exit(0); - } + /** * Temporary workaround until the compiler is able to clear the generation directory * @todo remove after MAGETWO-44493 resolved */ if (class_exists(CompilerPreparation::class)) { - $compilerPreparation = new CompilerPreparation($this->serviceManager, new ArgvInput(), new File()); + $compilerPreparation = new CompilerPreparation( + $this->serviceManager, + new ArgvInput(), + new File() + ); + $compilerPreparation->handleCompilerEnvironment(); } @@ -80,15 +86,13 @@ class Cli extends SymfonyApplication $productMetadata = new ProductMetadata($composerJsonFinder); $version = $productMetadata->getVersion(); } + parent::__construct($name, $version); } /** - * Process an error happened during initialization of commands, if any + * {@inheritdoc} * - * @param InputInterface $input - * @param OutputInterface $output - * @return int * @throws \Exception */ public function doRun(InputInterface $input, OutputInterface $output) @@ -149,10 +153,11 @@ class Cli extends SymfonyApplication } /** - * Gets vendor commands + * Retrieves vendor commands. * - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @return array + * @param ObjectManagerInterface $objectManager the object manager + * + * @return array an array with external commands */ protected function getVendorCommands($objectManager) { @@ -165,6 +170,7 @@ class Cli extends SymfonyApplication ); } } + return $commands; } } diff --git a/lib/internal/Magento/Framework/Console/Test/Unit/CliTest.php b/lib/internal/Magento/Framework/Console/Test/Unit/CliTest.php new file mode 100644 index 00000000000..8e2761f1716 --- /dev/null +++ b/lib/internal/Magento/Framework/Console/Test/Unit/CliTest.php @@ -0,0 +1,47 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Console\Test\Unit; + +use Magento\Framework\Console\Cli; +use PHPUnit_Framework_MockObject_MockObject as Mock; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class CliTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Cli + */ + private $model; + + /** + * @var InputInterface|Mock + */ + private $inputMock; + + /** + * @var OutputInterface|Mock + */ + private $outputMock; + + protected function setUp() + { + $this->inputMock = $this->getMockBuilder(InputInterface::class) + ->getMockForAbstractClass(); + $this->outputMock = $this->getMockBuilder(OutputInterface::class) + ->getMockForAbstractClass(); + + $this->model = new Cli(); + } + + public function testDoRun() + { + $this->model->doRun( + $this->inputMock, + $this->outputMock + ); + } +} -- GitLab