newTempFilename() публичный Метод

public newTempFilename ( )
Пример #1
0
 public function commit($message, array $options = [])
 {
     $params = '';
     foreach ($options as $option => $value) {
         if (is_int($option)) {
             $params[] = '-' . $value;
         } else {
             $params[] = '-' . $option;
             $params[] = $value;
         }
     }
     $tmpName = $this->filesystemHelper->newTempFilename();
     file_put_contents($tmpName, $message);
     $this->processHelper->runCommand(array_merge(['git', 'commit', '-F', $tmpName], $params));
 }
Пример #2
0
 /**
  * @test
  */
 public function merges_remote_branch_in_clean_wc()
 {
     $base = 'master';
     $sourceBranch = 'amazing-feature';
     $tmpName = $this->realFsHelper->newTempFilename();
     $hash = '8ae59958a2632018275b8db9590e9a79331030cb';
     $message = "Black-box testing 123\n\n\nAah!";
     $processHelper = $this->prophesize('Gush\\Helper\\ProcessHelper');
     $this->unitGit = new GitHelper($processHelper->reveal(), $this->gitConfigHelper->reveal(), $this->filesystemHelper->reveal());
     $this->filesystemHelper->newTempFilename()->willReturn($tmpName);
     $processHelper->runCommand('git status --porcelain --untracked-files=no')->willReturn("\n");
     $processHelper->runCommand('git rev-parse --abbrev-ref HEAD')->willReturn('master');
     $processHelper->runCommand(['git', 'checkout', 'master'])->shouldBeCalled();
     $processHelper->runCommands([['line' => ['git', 'merge', '--no-ff', '--no-commit', '--no-log', 'amazing-feature'], 'allow_failures' => false], ['line' => ['git', 'commit', '-F', $tmpName], 'allow_failures' => false]])->shouldBeCalled();
     $processHelper->runCommand('git rev-parse HEAD')->willReturn($hash);
     $this->assertEquals($hash, $this->unitGit->mergeBranch($base, $sourceBranch, $message));
 }
Пример #3
0
 /**
  * Download a file from the URL to the destination.
  *
  * @param string $url      Fully qualified URL to the file.
  * @param bool   $progress Show the progressbar when downloading.
  */
 public function downloadFile($url, $progress = true)
 {
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use(&$progressBar) {
         // Don't initialize the progress bar for redirects as the size is much smaller.
         if ($response->getStatusCode() >= 300) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($this->output, $size);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($size / 1000)));
             $progressBar->setBarWidth(60);
             if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                 $progressBar->setEmptyBarCharacter('░');
                 // light shade character \u2591
                 $progressBar->setProgressCharacter('');
                 $progressBar->setBarCharacter('▓');
                 // dark shade character \u2593
             }
             $progressBar->start();
         }
         $progressBar->setProgress($downloaded);
     };
     $client = $this->getGuzzleClient();
     if ($progress) {
         $this->output->writeln(sprintf("\n Downloading %s...\n", $url));
         $client->getEmitter()->attach(new Progress(null, $downloadCallback));
     }
     $response = $client->get($url);
     $tmpFile = $this->filesystemHelper->newTempFilename();
     $this->fs->dumpFile($tmpFile, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $this->output->writeln("\n");
     }
     return $tmpFile;
 }