Ejemplo n.º 1
0
 /**
  * @param string $name  application name
  * @param string $version 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->handleCompilerEnvironment();
     }
     if ($version == 'UNKNOWN') {
         $directoryList = new DirectoryList(BP);
         $composerJsonFinder = new ComposerJsonFinder($directoryList);
         $productMetadata = new ProductMetadata($composerJsonFinder);
         $version = $productMetadata->getVersion();
     }
     parent::__construct($name, $version);
 }
 public function testGenerationDirectoryFromCliOption()
 {
     $customGenerationDirectory = '/custom/generated/code/directory';
     $customDiDirectory = '/custom/di/directory';
     $this->inputMock->expects($this->once())->method('getFirstArgument')->willReturn(DiCompileCommand::NAME);
     $dirResultMap = [[$this->logicalNot($this->equalTo($customGenerationDirectory)), $this->logicalNot($this->equalTo($customDiDirectory))], [true, true]];
     $this->filesystemDriverMock->expects($this->exactly(2))->method('isExists')->willReturn(true);
     $this->filesystemDriverMock->expects($this->exactly(2))->method('deleteDirectory')->will($this->returnValueMap($dirResultMap));
     $this->model->handleCompilerEnvironment();
 }
 /**
  * @dataProvider compilerCommandDataProvider
  */
 public function testGenerationDirectoryFromCliOption($commandName)
 {
     $customGenerationDirectory = '/custom/generated/code/directory';
     $useCliOption = $commandName === DiCompileMultiTenantCommand::NAME;
     $this->inputMock->expects($this->once())->method('getFirstArgument')->willReturn($commandName);
     $this->inputMock->expects($this->exactly((int) $useCliOption))->method('getParameterOption')->with(DiCompileMultiTenantCommand::INPUT_KEY_GENERATION)->willReturn($customGenerationDirectory);
     // Filesystem mock
     $directoryArgConstraint = $useCliOption ? $this->equalTo($customGenerationDirectory) : $this->logicalNot($this->equalTo($customGenerationDirectory));
     $this->filesystemDriverMock->expects($this->once())->method('isExists')->willReturn(true);
     $this->filesystemDriverMock->expects($this->once())->method('deleteDirectory')->with($directoryArgConstraint);
     $this->model->handleCompilerEnvironment();
 }