Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 29, 2010
1 parent b487628 commit c41f8d6
Showing 1 changed file with 55 additions and 43 deletions.
98 changes: 55 additions & 43 deletions PHPUnit/Framework/TestCase.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ public function run(PHPUnit_Framework_TestResult $result = NULL)
$result = $this->createResult(); $result = $this->createResult();
} }


$this->result = $result;

$this->setExpectedExceptionFromAnnotation(); $this->setExpectedExceptionFromAnnotation();
$this->setUseErrorHandlerFromAnnotation(); $this->setUseErrorHandlerFromAnnotation();
$this->setUseOutputBufferingFromAnnotation(); $this->setUseOutputBufferingFromAnnotation();
Expand All @@ -500,49 +502,8 @@ public function run(PHPUnit_Framework_TestResult $result = NULL)
$result->convertErrorsToExceptions($this->useErrorHandler); $result->convertErrorsToExceptions($this->useErrorHandler);
} }


$this->result = $result; if (!$this->handleDependencies()) {

return;
if (!empty($this->dependencies) && !$this->inIsolation) {
$className = get_class($this);
$passed = $this->result->passed();
$passedKeys = array_keys($passed);
$numKeys = count($passedKeys);

for ($i = 0; $i < $numKeys; $i++) {
$pos = strpos($passedKeys[$i], ' with data set');

if ($pos !== FALSE) {
$passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
}
}

$passedKeys = array_flip(array_unique($passedKeys));

foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === FALSE) {
$dependency = $className . '::' . $dependency;
}

if (!isset($passedKeys[$dependency])) {
$result->addError(
$this,
new PHPUnit_Framework_SkippedTestError(
sprintf(
'This test depends on "%s" to pass.', $dependency
)
),
0
);

return;
} else {
if (isset($passed[$dependency])) {
$this->dependencyInput[] = $passed[$dependency];
} else {
$this->dependencyInput[] = NULL;
}
}
}
} }


if ($this->runTestInSeparateProcess === TRUE && if ($this->runTestInSeparateProcess === TRUE &&
Expand Down Expand Up @@ -1409,6 +1370,57 @@ protected function createResult()
return new PHPUnit_Framework_TestResult; return new PHPUnit_Framework_TestResult;
} }


/**
* @since Method available since Release 3.5.4
*/
protected function handleDependencies()
{
if (!empty($this->dependencies) && !$this->inIsolation) {
$className = get_class($this);
$passed = $this->result->passed();
$passedKeys = array_keys($passed);
$numKeys = count($passedKeys);

for ($i = 0; $i < $numKeys; $i++) {
$pos = strpos($passedKeys[$i], ' with data set');

if ($pos !== FALSE) {
$passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
}
}

$passedKeys = array_flip(array_unique($passedKeys));

foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === FALSE) {
$dependency = $className . '::' . $dependency;
}

if (!isset($passedKeys[$dependency])) {
$this->result->addError(
$this,
new PHPUnit_Framework_SkippedTestError(
sprintf(
'This test depends on "%s" to pass.', $dependency
)
),
0
);

return FALSE;
} else {
if (isset($passed[$dependency])) {
$this->dependencyInput[] = $passed[$dependency];
} else {
$this->dependencyInput[] = NULL;
}
}
}
}

return TRUE;
}

/** /**
* This method is called before the first test of this test class is run. * This method is called before the first test of this test class is run.
* *
Expand Down

0 comments on commit c41f8d6

Please sign in to comment.