public function PHPUnit_Util_PHP::runJob

Runs a single job (PHP code) using a separate PHP process.

Parameters

string $job:

PHPUnit_Framework_TestCase $test:

PHPUnit_Framework_TestResult $result:

Return value

array|null

Throws

PHPUnit_Framework_Exception

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Util/PHP.php, line 159

Class

PHPUnit_Util_PHP
Utility methods for PHP sub-processes.

Code

public function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit_Framework_TestResult $result = NULL) {
  $process = proc_open($this
    ->getPhpBinary(), array(
    0 => array(
      'pipe',
      'r',
    ),
    1 => array(
      'pipe',
      'w',
    ),
    2 => array(
      'pipe',
      'w',
    ),
  ), $pipes);
  if (!is_resource($process)) {
    throw new PHPUnit_Framework_Exception('Unable to create process for process isolation.');
  }
  if ($result !== NULL) {
    $result
      ->startTest($test);
  }
  $this
    ->process($pipes[0], $job);
  fclose($pipes[0]);
  $stdout = stream_get_contents($pipes[1]);
  fclose($pipes[1]);
  $stderr = stream_get_contents($pipes[2]);
  fclose($pipes[2]);
  proc_close($process);
  $this
    ->cleanup();
  if ($result !== NULL) {
    $this
      ->processChildResult($test, $result, $stdout, $stderr);
  }
  else {
    return array(
      'stdout' => $stdout,
      'stderr' => $stderr,
    );
  }
}