<commit_before><?php

/**
 * PHPUnit Result Parsing utility
 *
 * Intended to enable custom unit engines derived
 * from phpunit to reuse common business logic related
 * to parsing phpunit test results and reports
 *
 * For an example on how to integrate with your test
 * engine, see PhpunitTestEngine.
 *
 */
final class PhpunitResultParser {

  private $enableCoverage;
  private $projectRoot;

  public function setEnableCoverage($enable_coverage) {
    $this->enableCoverage = $enable_coverage;

    return $this;
  }

  public function setProjectRoot($project_root) {
    $this->projectRoot = $project_root;

    return $this;
  }

  /**
   * Parse test results from phpunit json report
   *
   * @param string $path Path to test
   * @param string $json_path Path to phpunit json report
   * @param string $clover_tmp Path to phpunit clover report
   * @param array $affected_tests Array of the tests affected by this run
   * @param bool $enable_coverage Option to enable coverage in results
   *
   * @return array
   */
  public function parseTestResults(
    $path,
    $json_tmp,
    $clover_tmp,
    $affected_tests) {

      $test_results = Filesystem::readFile($json_tmp);

      $report = $this->getJsonReport($json_tmp);

      // coverage is for all testcases in the executed $path
      $coverage = array();
      if ($this->enableCoverage !== false) {
        $coverage = $this->readCoverage($clover_tmp, $affected_tests);
      }

      $results = array();
      foreach ($report as $event) {
        if ('test' != $event->event) {
          continue;
        }

        $status = ArcanistUnitTestResult::RESULT_PASS;
        $user_data = '';

        if ('fail' == $event->status) {
          $status = ArcanistUnitTestResult::RESULT_FAIL;
          $user_data  .= $event->message . "\n";
          foreach ($event->trace as $trace) {
            $user_data .= sprintf("\n%s:%s", $trace->file, $trace->line);
          }
        } else if ('error' == $event->status) {
          if ('Skipped Test' == $event->message) {
            $status = ArcanistUnitTestResult::RESULT_SKIP;
            $user_data .= $event->message;
          } else if ('Incomplete Test' == $event->message) {
            $status = ArcanistUnitTestResult::RESULT_SKIP;
            $user_data .= $event->message;
          } else {<commit_msg>Support PHPUnit 3.7 message changes<commit_after><?php

/**
 * PHPUnit Result Parsing utility
 *
 * Intended to enable custom unit engines derived
 * from phpunit to reuse common business logic related
 * to parsing phpunit test results and reports
 *
 * For an example on how to integrate with your test
 * engine, see PhpunitTestEngine.
 *
 */
final class PhpunitResultParser {

  private $enableCoverage;
  private $projectRoot;

  public function setEnableCoverage($enable_coverage) {
    $this->enableCoverage = $enable_coverage;

    return $this;
  }

  public function setProjectRoot($project_root) {
    $this->projectRoot = $project_root;

    return $this;
  }

  /**
   * Parse test results from phpunit json report
   *
   * @param string $path Path to test
   * @param string $json_path Path to phpunit json report
   * @param string $clover_tmp Path to phpunit clover report
   * @param array $affected_tests Array of the tests affected by this run
   * @param bool $enable_coverage Option to enable coverage in results
   *
   * @return array
   */
  public function parseTestResults(
    $path,
    $json_tmp,
    $clover_tmp,
    $affected_tests) {

      $test_results = Filesystem::readFile($json_tmp);

      $report = $this->getJsonReport($json_tmp);

      // coverage is for all testcases in the executed $path
      $coverage = array();
      if ($this->enableCoverage !== false) {
        $coverage = $this->readCoverage($clover_tmp, $affected_tests);
      }

      $results = array();
      foreach ($report as $event) {
        if ('test' != $event->event) {
          continue;
        }

        $status = ArcanistUnitTestResult::RESULT_PASS;
        $user_data = '';

        if ('fail' == $event->status) {
          $status = ArcanistUnitTestResult::RESULT_FAIL;
          $user_data  .= $event->message . "\n";
          foreach ($event->trace as $trace) {
            $user_data .= sprintf("\n%s:%s", $trace->file, $trace->line);
          }
        } else if ('error' == $event->status) {
          if (strpos($event->message, 'Skipped Test') !== false) {
            $status = ArcanistUnitTestResult::RESULT_SKIP;
            $user_data .= $event->message;
          } else if (strpos($event->message, 'Incomplete Test') !== false) {
            $status = ArcanistUnitTestResult::RESULT_SKIP;
            $user_data .= $event->message;
          } else {
{'fraction_non_alphanumeric': 0.11902748414376321, 'fraction_numerical': 0.00042283298097251583, 'mean_word_length': 2.707680250783699, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1546161', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1373, 'n_words': 388}