You are here

public function PHPUnit_Framework_TestCase::run in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/TestCase.php \PHPUnit_Framework_TestCase::run()

Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created.

Parameters

PHPUnit_Framework_TestResult $result:

Return value

PHPUnit_Framework_TestResult

Throws

PHPUnit_Framework_Exception

Overrides PHPUnit_Framework_Test::run

File

vendor/phpunit/phpunit/src/Framework/TestCase.php, line 590

Class

PHPUnit_Framework_TestCase
A TestCase defines the fixture to run multiple tests.

Code

public function run(PHPUnit_Framework_TestResult $result = null) {
  if ($result === null) {
    $result = $this
      ->createResult();
  }
  if (!$this instanceof PHPUnit_Framework_Warning) {
    $this
      ->setTestResultObject($result);
    $this
      ->setUseErrorHandlerFromAnnotation();
  }
  if ($this->useErrorHandler !== null) {
    $oldErrorHandlerSetting = $result
      ->getConvertErrorsToExceptions();
    $result
      ->convertErrorsToExceptions($this->useErrorHandler);
  }
  if (!$this instanceof PHPUnit_Framework_Warning && !$this
    ->handleDependencies()) {
    return;
  }
  if ($this->runTestInSeparateProcess === true && $this->inIsolation !== true && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) {
    $class = new ReflectionClass($this);
    $template = new Text_Template(__DIR__ . '/../Util/PHP/Template/TestCaseMethod.tpl');
    if ($this->preserveGlobalState) {
      $constants = PHPUnit_Util_GlobalState::getConstantsAsString();
      $globals = PHPUnit_Util_GlobalState::getGlobalsAsString();
      $includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString();
      $iniSettings = PHPUnit_Util_GlobalState::getIniSettingsAsString();
    }
    else {
      $constants = '';
      if (!empty($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
        $globals = '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], true) . ";\n";
      }
      else {
        $globals = '';
      }
      $includedFiles = '';
      $iniSettings = '';
    }
    $coverage = $result
      ->getCollectCodeCoverageInformation() ? 'true' : 'false';
    $isStrictAboutTestsThatDoNotTestAnything = $result
      ->isStrictAboutTestsThatDoNotTestAnything() ? 'true' : 'false';
    $isStrictAboutOutputDuringTests = $result
      ->isStrictAboutOutputDuringTests() ? 'true' : 'false';
    $isStrictAboutTestSize = $result
      ->isStrictAboutTestSize() ? 'true' : 'false';
    $isStrictAboutTodoAnnotatedTests = $result
      ->isStrictAboutTodoAnnotatedTests() ? 'true' : 'false';
    if (defined('PHPUNIT_COMPOSER_INSTALL')) {
      $composerAutoload = var_export(PHPUNIT_COMPOSER_INSTALL, true);
    }
    else {
      $composerAutoload = '\'\'';
    }
    if (defined('__PHPUNIT_PHAR__')) {
      $phar = var_export(__PHPUNIT_PHAR__, true);
    }
    else {
      $phar = '\'\'';
    }
    if ($result
      ->getCodeCoverage()) {
      $codeCoverageFilter = $result
        ->getCodeCoverage()
        ->filter();
    }
    else {
      $codeCoverageFilter = null;
    }
    $data = var_export(serialize($this->data), true);
    $dataName = var_export($this->dataName, true);
    $dependencyInput = var_export(serialize($this->dependencyInput), true);
    $includePath = var_export(get_include_path(), true);
    $codeCoverageFilter = var_export(serialize($codeCoverageFilter), true);

    // must do these fixes because TestCaseMethod.tpl has unserialize('{data}') in it, and we can't break BC
    // the lines above used to use addcslashes() rather than var_export(), which breaks null byte escape sequences
    $data = "'." . $data . ".'";
    $dataName = "'.(" . $dataName . ").'";
    $dependencyInput = "'." . $dependencyInput . ".'";
    $includePath = "'." . $includePath . ".'";
    $codeCoverageFilter = "'." . $codeCoverageFilter . ".'";
    $configurationFilePath = isset($GLOBALS['__PHPUNIT_CONFIGURATION_FILE']) ? $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] : '';
    $template
      ->setVar(array(
      'composerAutoload' => $composerAutoload,
      'phar' => $phar,
      'filename' => $class
        ->getFileName(),
      'className' => $class
        ->getName(),
      'methodName' => $this->name,
      'collectCodeCoverageInformation' => $coverage,
      'data' => $data,
      'dataName' => $dataName,
      'dependencyInput' => $dependencyInput,
      'constants' => $constants,
      'globals' => $globals,
      'include_path' => $includePath,
      'included_files' => $includedFiles,
      'iniSettings' => $iniSettings,
      'isStrictAboutTestsThatDoNotTestAnything' => $isStrictAboutTestsThatDoNotTestAnything,
      'isStrictAboutOutputDuringTests' => $isStrictAboutOutputDuringTests,
      'isStrictAboutTestSize' => $isStrictAboutTestSize,
      'isStrictAboutTodoAnnotatedTests' => $isStrictAboutTodoAnnotatedTests,
      'codeCoverageFilter' => $codeCoverageFilter,
      'configurationFilePath' => $configurationFilePath,
    ));
    $this
      ->prepareTemplate($template);
    $php = PHPUnit_Util_PHP::factory();
    $php
      ->runTestJob($template
      ->render(), $this, $result);
  }
  else {
    $result
      ->run($this);
  }
  if ($this->useErrorHandler !== null) {
    $result
      ->convertErrorsToExceptions($oldErrorHandlerSetting);
  }
  $this->result = null;
  return $result;
}