/**
  * @param Job                   $job
  * @param Variable[]            $variables
  * @param string                $projectRootPath
  * @param string|null           $gitRefName
  * @param int|null              $sleep
  * @param string[]|null         $volumes
  *
  * @return string
  */
 public function createDockerRunCommand(Job $job, array $variables, $projectRootPath, $gitRefName = null, $sleep = null, $volumes = null)
 {
     $projectId = md5($projectRootPath);
     $gitRefName = $gitRefName ? $gitRefName : 'develop';
     $volumes = $volumes ? $this->getVolumesFromString($volumes) : [];
     $dockerRunCommandBuilder = $this->dockerRunCommandBuilder->image($job->imageName());
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->workDir(self::CONTAINER_PROJECT_COPY);
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->rm(true);
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->entrypoint('/bin/sh');
     foreach ($variables as $variable) {
         $dockerRunCommandBuilder = $dockerRunCommandBuilder->environment($variable->key(), $variable->value());
     }
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->environment('CI_PROJECT_ID', $projectId);
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->environment('CI_PROJECT_DIR', self::CONTAINER_PROJECT_COPY);
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->environment('CI_BUILD_REF_NAME', $gitRefName);
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->volume(self::CONTAINER_PROJECT, $projectRootPath, 'ro');
     foreach ($volumes as $volume) {
         $dockerRunCommandBuilder = $dockerRunCommandBuilder->volume($volume->hostVolume(), $volume->containerVolume());
     }
     $containerProject = self::CONTAINER_PROJECT;
     $containerProjectCopy = self::CONTAINER_PROJECT_COPY;
     $command = "\"-c\" \"cp -R {$containerProject}/. {$containerProjectCopy}/";
     foreach ($job->scripts() as $script) {
         $command .= " && {$script}";
     }
     $command .= $sleep ? " && sleep {$sleep}" : '';
     $command .= "\"";
     $dockerRunCommandBuilder = $dockerRunCommandBuilder->cmd($command);
     return $dockerRunCommandBuilder->toString();
 }
 /**
  * @inheritDoc
  */
 public function isSuccessful()
 {
     if ($this->symfonyProcess->isSuccessful()) {
         echo "{$this->job->jobName()}: Has finished without errors.\n";
     }
     return $this->symfonyProcess->isSuccessful();
 }
 function let(Job $job, Cache $cache, Variable $variable, Stage $stage)
 {
     $job->jobName()->willReturn('phpspec_php_5_6');
     $this->jobs = [$job];
     $this->stages = [$stage];
     $this->variables = [$variable];
     $this->cache = $cache;
     $this->beConstructedWith($this->stages, $cache, $this->variables, $this->jobs);
 }
 /**
  * @inheritdoc
  */
 public function runProcess(Job $job, $processCommand)
 {
     $process = new Process($processCommand);
     $process->setTimeout(720);
     $process->start(function ($type, $buffer) use($job) {
         if (\Symfony\Component\Process\Process::ERR === $type) {
             echo "{$job->jobName()}: STDERR > " . $buffer;
         } else {
             echo "{$job->jobName()}: STDOUT > " . $buffer;
         }
     });
     return new SymfonyProcess($job, $process);
 }