Пример #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;
 }
Пример #2
0
 /**
  * Get all test case results that match selected criteria.
  *
  * If both class and status are null all results are returned.
  * If class name or status is given test results are
  * returned as an associative array indexed by status or class name.
  *
  * @param string $class  class name
  * @param string $status test case result status
  * @return array array of test case results
  * @throws Streamwide_PHPUnit_Runner_Exception when unknown status is given
  */
 public function results($class = null, $status = null)
 {
     if (!is_null($status) && !in_array($status, Streamwide_PHPUnit_Runner_TestCaseResult::getAllStatusConstants())) {
         require_once 'Streamwide/PHPUnit/Runner/Exception.php';
         throw new Streamwide_PHPUnit_Runner_Exception('Unknown status ' . $status);
     }
     if (is_null($class) && is_null($status)) {
         return $this->_results;
     } else {
         if (!is_null($class) && !is_null($status)) {
             return $this->_classIndex[$class][$status];
         } else {
             if (!is_null($class)) {
                 return $this->_classIndex[$class];
             } else {
                 if (!is_null($status)) {
                     return $this->_statusIndex[$status];
                 }
             }
         }
     }
 }