Esempio n. 1
0
 /**
  * Executes the command.
  *
  * @param InputInterface  $input  An input stream
  * @param OutputInterface $output An output stream
  *
  * @return int null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dryRun = $input->getOption('dry-run');
     $checkOnly = $input->getOption('check-only');
     $mode = Licenser::MODE_NORMAL;
     if ($checkOnly) {
         $mode = Licenser::MODE_CHECK_ONLY;
     } elseif ($dryRun) {
         $mode = Licenser::MODE_DRY_RUN;
     }
     $logger = new ProcessLogger($output);
     $logger->startProcess($mode);
     if ($configFile = $this->extractConfigFile($input)) {
         foreach (ConfigFactory::createFromConfigFile($configFile, $input) as $config) {
             $this->buildLicenser($config, $logger)->process($mode);
         }
     } else {
         $config = ConfigFactory::createFromCommandLine($input);
         $this->buildLicenser($config, $logger)->process($mode);
     }
     $logger->finishProcess();
     if ($mode === Licenser::MODE_CHECK_ONLY && $logger->countAdditions() + $logger->countUpdates() > 0) {
         return 1;
     }
     return 0;
 }
 public function setUp()
 {
     $fileSystem = new Filesystem();
     $temp = sys_get_temp_dir();
     $this->tempDir = $temp . DIRECTORY_SEPARATOR . 'licenser';
     $fileSystem->remove($this->tempDir);
     $fileSystem->mkdir($this->tempDir);
     $this->fixturesDir = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures';
     $fileSystem->mirror($this->fixturesDir . DIRECTORY_SEPARATOR . 'origin', $this->tempDir, null, ['override' => true]);
     $fileSystem->copy($this->fixturesDir . DIRECTORY_SEPARATOR . 'license', $this->tempDir . DIRECTORY_SEPARATOR . 'license', true);
     $finder = FinderBuilder::create()->in($this->tempDir)->name('*.php');
     $this->config = Config::create()->setFinderBuilder($finder);
     $this->config->setLicense(file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'src', 'licenses', 'default'])));
     $this->output = new DummyOutput();
     $this->logger = new ProcessLogger($this->output);
     $this->logger->startProcess();
 }