public function NativePhpunitTask::main

File

drupal/core/vendor/doctrine/common/tests/NativePhpunitTask.php, line 95

Class

NativePhpunitTask
A more flexible and powerful PHPUnit Task than the native Phing one.

Code

public function main() {
  if (!is_dir(realpath($this->testdirectory))) {
    throw new BuildException("NativePHPUnitTask requires a Test Directory path given, '" . $this->testdirectory . "' given.");
  }
  set_include_path(realpath($this->testdirectory) . PATH_SEPARATOR . get_include_path());
  $printer = new NativePhpunitPrinter();
  $arguments = array(
    'configuration' => $this->configuration,
    'coverageClover' => $this->coverageClover,
    'junitLogfile' => $this->junitlogfile,
    'printer' => $printer,
  );
  $runner = new PHPUnit_TextUI_TestRunner();
  $suite = $runner
    ->getTest($this->test, $this->testfile, true);
  try {
    $result = $runner
      ->doRun($suite, $arguments);

    /* @var $result PHPUnit_Framework_TestResult */
    if ($this->haltonfailure && $result
      ->failureCount() > 0 || $this->haltonerror && $result
      ->errorCount() > 0) {
      throw new BuildException("PHPUnit: " . $result
        ->failureCount() . " Failures and " . $result
        ->errorCount() . " Errors, " . "last failure message: " . $printer
        ->getMessages());
    }
    $this
      ->log("PHPUnit Success: " . count($result
      ->passed()) . " tests passed, no " . "failures (" . $result
      ->skippedCount() . " skipped, " . $result
      ->notImplementedCount() . " not implemented)");

    // Hudson for example doesn't like the backslash in class names
    if (file_exists($this->coverageClover)) {
      $this
        ->log("Generated Clover Coverage XML to: " . $this->coverageClover);
      $content = file_get_contents($this->coverageClover);
      $content = str_replace("\\", ".", $content);
      file_put_contents($this->coverageClover, $content);
      unset($content);
    }
  } catch (\Exception $e) {
    throw new BuildException("NativePhpunitTask failed: " . $e
      ->getMessage());
  }
}