Example #1
0
 /**
  * Runs a test case.
  *
  * @param Streamwide_PHPUnit_Runner_TestCase  $testCase     test case
  * @param boolean                    $codeCoverage (optional) whether to collect code coverage or not
  * @param array                      $options      (optional) additional options to pass to the runner
  * @return Streamwide_PHPUnit_Runner_TestCaseResult
  */
 public function run(Streamwide_PHPUnit_Runner_TestCase $testCase, $codeCoverage = false, array $options = null)
 {
     // set arguments for the script
     $args = array('file' => $testCase->getFile(), 'class' => $testCase->getClass(), 'test' => $testCase->getTest(), 'codeCoverage' => $codeCoverage, 'includePath' => get_include_path(), 'XDEBUG_SESSION_START' => uniqid());
     // prepare arguments for url
     $parts = array();
     foreach ($args as $key => $value) {
         $parts[] = $key . '=' . urlencode($value);
     }
     $argsLine = join('&', $parts);
     // prepare the command
     $uri = sprintf('%s?%s', $this->_remoteScriptUrl, $argsLine);
     // set user agent and create stream context
     $userAgent = $_SERVER['HTTP_USER_AGENT'];
     $opts = array('http' => array('method' => "GET", 'header' => "User-Agent: {$userAgent}\r\n"));
     $context = stream_context_create($opts);
     // enter into a safe error reporting level
     $oldErrorReportingLevel = error_reporting(E_ERROR);
     // execute the http request
     $response = file_get_contents($uri, false, $context);
     // check if an error has occured in the request
     $result = null;
     if ($response) {
         // the result should be a serialized representation of the suite report
         $result = unserialize($response);
     }
     // restore previous error reporting level
     error_reporting($oldErrorReportingLevel);
     // check if an error occured
     if (!$response || !$result instanceof Streamwide_PHPUnit_Runner_TestCaseResult) {
         $error = error_get_last();
         $message = sprintf('%s<br />in %s at line %s', $error['message'], $error['file'], $error['line']);
         // if unserialize has failed (fatal error) add the response to the details
         $message .= $response;
         $message = sprintf('<div class="fatalError">%s</div>', $message);
         $result = new Streamwide_PHPUnit_Runner_TestCaseResult($testCase, Streamwide_PHPUnit_Runner_TestCaseResult::ERROR, $message);
     }
     global $http_response_header;
     // propagate headers
     $result->setHttpHeaders($http_response_header);
     return $result;
 }
Example #2
0
 /**
  * Run a test suite and return the results.
  *
  * @param Streamwide_PHPUnit_Runner_TestCase $testCase     test case
  * @param boolean                            $codeCoverage (optional) whether to collect code coverage
  * @return PHPUnit_Framework_TestResult phunit test result
  */
 private function _runTestCase($testCase, $codeCoverage = false)
 {
     require_once $testCase->getFile();
     $result = new PHPUnit_Framework_TestResult();
     $result->collectCodeCoverageInformation($codeCoverage);
     $class = $testCase->getClass();
     $testCase = new $class($testCase->getTest());
     $testCase->setInIsolation(true);
     // run the test case
     $testCase->run($result);
     return $result;
 }