You are here

public function PHPUnit_Extensions_PhptTestCase::run in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Extensions/PhptTestCase.php \PHPUnit_Extensions_PhptTestCase::run()

Runs a test and collects its result in a TestResult instance.

Parameters

PHPUnit_Framework_TestResult $result:

Return value

PHPUnit_Framework_TestResult

Overrides PHPUnit_Framework_Test::run

File

vendor/phpunit/phpunit/src/Extensions/PhptTestCase.php, line 90

Class

PHPUnit_Extensions_PhptTestCase
Runner for PHPT test cases.

Code

public function run(PHPUnit_Framework_TestResult $result = null) {
  $sections = $this
    ->parse();
  $code = $this
    ->render($sections['FILE']);
  if ($result === null) {
    $result = new PHPUnit_Framework_TestResult();
  }
  $php = PHPUnit_Util_PHP::factory();
  $skip = false;
  $time = 0;
  $settings = $this->settings;
  $result
    ->startTest($this);
  if (isset($sections['INI'])) {
    $settings = array_merge($settings, $this
      ->parseIniSection($sections['INI']));
  }
  if (isset($sections['SKIPIF'])) {
    $jobResult = $php
      ->runJob($sections['SKIPIF'], $settings);
    if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
      if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $jobResult['stdout'], $message)) {
        $message = substr($message[1], 2);
      }
      else {
        $message = '';
      }
      $result
        ->addFailure($this, new PHPUnit_Framework_SkippedTestError($message), 0);
      $skip = true;
    }
  }
  if (!$skip) {
    PHP_Timer::start();
    $jobResult = $php
      ->runJob($code, $settings);
    $time = PHP_Timer::stop();
    if (isset($sections['EXPECT'])) {
      $assertion = 'assertEquals';
      $expected = $sections['EXPECT'];
    }
    else {
      $assertion = 'assertStringMatchesFormat';
      $expected = $sections['EXPECTF'];
    }
    $output = preg_replace('/\\r\\n/', "\n", trim($jobResult['stdout']));
    $expected = preg_replace('/\\r\\n/', "\n", trim($expected));
    try {
      PHPUnit_Framework_Assert::$assertion($expected, $output);
    } catch (PHPUnit_Framework_AssertionFailedError $e) {
      $result
        ->addFailure($this, $e, $time);
    } catch (Throwable $t) {
      $result
        ->addError($this, $t, $time);
    } catch (Exception $e) {
      $result
        ->addError($this, $e, $time);
    }
  }
  $result
    ->endTest($this, $time);
  return $result;
}