public function doPhase($story)
{
// shorthand
$st = $this->st;
$storyResult = $story->getResult();
// keep track of what happens with the action
$phaseResult = $this->getNewPhaseResult();
// do we have anything to do?
if (!$story->hasTestCanRunCheck()) {
$phaseResult->setContinuePlaying($phaseResult::COMPLETED, "story can always run");
return $phaseResult;
}
// get the callback to call
$callbacks = $story->getTestCanRunCheck();
// make the call
try {
foreach ($callbacks as $callback) {
$canRun = call_user_func($callback, $st);
// what did the callback tell us?
//
// we treat TWO results as valid reports that the test
// should be skipped:
//
// 1: FALSE
// 2: an error message to write to the outputs
//
// ANYTHING else is treated as permission to continue
// and potentially run the rest of the story
if ($canRun === false || is_string($canRun)) {
$msg = "test reported that it cannot run";
if (is_string($canRun)) {
$msg = $canRun;
}
$phaseResult->setSkipPlaying($phaseResult::CANNOTRUN, $msg);
$storyResult->setStoryHasBeenSkipped($phaseResult);
return $phaseResult;
}
}
// if we get here, then all is well
$phaseResult->setContinuePlaying();
} catch (E5xx_ActionFailed $e) {
$phaseResult->setPlayingFailed($phaseResult::FAILED, $e->getMessage(), $e);
$storyResult->setStoryHasFailed($phaseResult);
} catch (E5xx_ExpectFailed $e) {
$phaseResult->setSkipPlaying($phaseResult::CANNOTRUN, $e->getMessage(), $e);
$storyResult->setStoryHasBeenSkipped($phaseResult);
} catch (E5xx_NotImplemented $e) {
$phaseResult->setPlayingFailed($phaseResult::INCOMPLETE, $e->getMessage(), $e);
$storyResult->setStoryIsIncomplete($phaseResult);
} catch (E5xx_StoryCannotRun $e) {
$phaseResult->setSkipPlaying($phaseResult::CANNOTRUN, $e->getMessage());
$storyResult->setStoryHasBeenSkipped($phaseResult);
} catch (Exception $e) {
// something went wrong ... the test cannot continue
$phaseResult->setPlayingFailed($phaseResult::ERROR, $e->getMessage(), $e);
$storyResult->setStoryHasFailed($phaseResult);
}
// all done
return $phaseResult;
}