/**
  * Run passed jobs
  *
  * @param string[]  $jobNames
  * @param string    $gitlabCiPath
  * @param string    $refName
  * @param null|int  $sleep
  * @param array     $volumes
  *
  * @throws PrivateRunnerException
  */
 public function runJobs(array $jobNames, $gitlabCiPath, $refName, $sleep = null, array $volumes = [])
 {
     /** @var Process[] $runningProcesses */
     $runningProcesses = [];
     $projectRootPath = dirname($gitlabCiPath);
     $gitlabCIConfiguration = $this->gitlabCIConfigurationFactory->createFromYaml($gitlabCiPath);
     foreach ($jobNames as $jobName) {
         $job = $gitlabCIConfiguration->getJob($jobName);
         $command = $this->consoleCommandFactory->createDockerRunCommand($job, $gitlabCIConfiguration->variables(), $projectRootPath, $refName, $sleep, $volumes);
         $process = $this->processRunner->runProcess($job, $command);
         $runningProcesses[$jobName] = $process;
     }
     $errorProcesses = [];
     foreach ($runningProcesses as $jobName => $process) {
         while ($process->isRunning()) {
         }
         if (!$process->isSuccessful()) {
             $errorProcesses[] = $jobName;
         }
     }
     if ($errorProcesses) {
         $jobNamesToString = implode(", ", $errorProcesses);
         throw new PrivateRunnerException("Failed jobs: {$jobNamesToString}");
     }
 }
 function it_should_run_stage(Job $phpspecJob, Job $phpunitJob, Process $phpspecProcess, Process $phpunitProcess)
 {
     $stageName = 'dev-publish-stage';
     $projectDir = vfsStream::url('root/project');
     $gitlabYamlPath = $projectDir . '/.gitlab-ci.yml';
     $refName = 'develop';
     $sleep = 20;
     $volumes = ['/artifact_repository:/artifact_repository'];
     $this->gitlabCIConfigurationFactory->createFromYaml($gitlabYamlPath)->willReturn($this->gitlabCIConfiguration);
     $this->gitlabCIConfiguration->getJobsForStage('dev-publish-stage')->willReturn(['phpspec_php_5_6', 'phpunit_php_5_6']);
     $phpspecCommand = 'phpspec some docker run command';
     $phpunitCommand = 'phpunit some docker run command';
     $variables = [new Variable('some', 'value')];
     $this->gitlabCIConfiguration->variables()->willReturn($variables);
     $this->gitlabCIConfiguration->getJob('phpspec_php_5_6')->willReturn($phpspecJob);
     $this->gitlabCIConfiguration->getJob('phpunit_php_5_6')->willReturn($phpunitJob);
     $this->consoleCommandFactory->createDockerRunCommand($phpspecJob, $variables, $projectDir, $refName, $sleep, $volumes)->willReturn($phpspecCommand);
     $this->consoleCommandFactory->createDockerRunCommand($phpunitJob, $variables, $projectDir, $refName, $sleep, $volumes)->willReturn($phpunitCommand);
     $this->processRunner->runProcess($phpspecJob, $phpspecCommand)->willReturn($phpspecProcess);
     $this->processRunner->runProcess($phpunitJob, $phpunitCommand)->willReturn($phpunitProcess);
     $phpspecProcess->isRunning()->willReturn(false);
     $phpunitProcess->isRunning()->willReturn(false);
     $phpspecProcess->isSuccessful()->shouldBeCalledTimes(1)->willReturn(true);
     $phpunitProcess->isSuccessful()->shouldBeCalledTimes(1)->willReturn(true);
     $this->runStage($stageName, $gitlabYamlPath, $refName, $sleep, $volumes);
 }