public function CommandUnishTestCase::run

8.0.x CommandUnishTestCase.php public CommandUnishTestCase::run(\PHPUnit_Framework_TestResult $result = NULL)
7.x CommandUnishTestCase.php public CommandUnishTestCase::run(\PHPUnit_Framework_TestResult $result = NULL)
master CommandUnishTestCase.php public CommandUnishTestCase::run(\PHPUnit_Framework_TestResult $result = NULL)

Override the run method, so we can add in our code coverage data after the test has run.

We have to collect all coverage data, merge them and append them as one, to avoid having phpUnit duplicating the test function as many times as drush has been invoked.

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

File

tests/Unish/CommandUnishTestCase.php, line 331

Namespace

Unish

Class

CommandUnishTestCase

Code

public function run(\PHPUnit_Framework_TestResult $result = NULL) {
  $result = parent::run($result);
  $data = array();
  foreach ($this->coverage_data as $merge_data) {
    foreach ($merge_data as $file => $lines) {
      if (!isset($data[$file])) {
        $data[$file] = $lines;
      }
      else {
        foreach ($lines as $num => $executed) {
          if (!isset($data[$file][$num])) {
            $data[$file][$num] = $executed;
          }
          else {
            $data[$file][$num] = ($executed == 1 ? $executed : $data[$file][$num]);
          }
        }
      }
    }
  }

  // Reset coverage data.
  $this->coverage_data = array();
  if (!empty($data)) {
    $result->getCodeCoverage()->append($data, $this);
  }
  return $result;
}