コード例 #1
0
ファイル: DownloaderTest.php プロジェクト: mhujer/steward
 public function testShouldCheckIfFileWasAlreadyDownloaded()
 {
     $downloader = new Downloader(__DIR__ . '/Fixtures');
     $downloader->setVersion('2.45.0');
     $this->assertTrue($downloader->isAlreadyDownloaded());
     $downloader->setVersion('2.66.6');
     $this->assertFalse($downloader->isAlreadyDownloaded());
 }
コード例 #2
0
ファイル: InstallCommand.php プロジェクト: mhujer/steward
 /**
  * In interactive or very verbose (-vv) mode provide more output, otherwise only output full path to selenium
  * server jar file (so it could be parsed and run).
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $verboseOutput = false;
     if ($input->isInteractive() || $output->isVerbose()) {
         $verboseOutput = true;
     }
     $version = $input->getArgument('version');
     // exact version could be specified as argument
     if (!$version) {
         $latestVersion = Downloader::getLatestVersion();
         /** @var QuestionHelper $questionHelper */
         $questionHelper = $this->getHelper('question');
         $questionText = '<question>Enter Selenium server version to install:</question> ';
         if ($latestVersion) {
             $question = new Question($questionText . "[{$latestVersion}] ", $latestVersion);
         } else {
             // Error auto-detecting latest version
             $latestVersionErrorMsg = 'Please provide version to download (latest version auto-detect failed)';
             if ($input->isInteractive()) {
                 // in interactive mode require version to be specified
                 $question = new Question($questionText);
                 $question->setValidator(function ($answer) use($latestVersionErrorMsg) {
                     if (empty($answer)) {
                         throw new \RuntimeException($latestVersionErrorMsg);
                     }
                     return $answer;
                 });
             } else {
                 // in non-interactive mode fail, as we have nowhere to get the version number
                 $output->writeln('<error>' . $latestVersionErrorMsg . '</error>');
                 return 1;
             }
         }
         $version = $questionHelper->ask($input, $output, $question);
     }
     if ($verboseOutput) {
         $output->writeln(sprintf('<info>Steward</info> <comment>%s</comment> is now downloading the Selenium standalone server...%s', $this->getApplication()->getVersion(), !$this->isCi() ? ' Just for you <fg=red><3</fg=red>!' : ''));
     }
     $downloader = $this->getDownloader();
     $downloader->setVersion($version);
     if ($output->isVerbose()) {
         $output->writeln(sprintf('Version: %s', $version));
         $output->writeln(sprintf('File URL: %s', $downloader->getFileUrl()));
         $output->writeln(sprintf('Target file path: %s', $downloader->getFilePath()));
     }
     if ($downloader->isAlreadyDownloaded()) {
         $targetPath = realpath($downloader->getFilePath());
         if ($verboseOutput) {
             $output->writeln(sprintf('File "%s" already exists in directory "%s" - won\'t be downloaded again.', basename($targetPath), dirname($targetPath)));
         } else {
             $output->writeln($targetPath);
             // In non-verbose mode only output path to the file
         }
         return 0;
     }
     if ($verboseOutput) {
         $output->writeln('Downloading (may take a while - its over 30 MB)...');
     }
     $downloadedSize = $downloader->download();
     if (!$downloadedSize) {
         $output->writeln('<error>Error downloading file :-(</error>');
         return 1;
     }
     if ($verboseOutput) {
         $output->writeln('Downloaded ' . $downloadedSize . ' bytes, file saved successfully.');
     } else {
         $targetPath = realpath($downloader->getFilePath());
         $output->writeln($targetPath);
         // In non-verbose mode only output path to the file
     }
     return 0;
 }