DataSift\Storyplayer\Phases\PreTestPredictionPhase::doPhase PHP Method

doPhase() public method

public doPhase ( $story )
    public function doPhase($story)
    {
        // shorthand
        $st = $this->st;
        $storyResult = $story->getResult();
        // our return value
        $phaseResult = $this->getNewPhaseResult();
        try {
            // do we have anything to do?
            if (!$story->hasPreTestPrediction()) {
                $phaseResult->setContinuePlaying($phaseResult::HASNOACTIONS, "story has no pre-test prediction instructions; skipping");
                return $phaseResult;
            }
            // setup the phase
            $this->doPerPhaseSetup();
            // make the call
            $callbacks = $story->getPreTestPrediction();
            foreach ($callbacks as $callback) {
                if (is_callable($callback)) {
                    call_user_func($callback, $st);
                }
            }
            // if we get here, the PreTestPrediction worked with
            // no problems at all
            $phaseResult->setContinuePlaying();
        } catch (E5xx_ActionFailed $e) {
            $phaseResult->setContinuePlaying($phaseResult::FAILED, $e->getMessage(), $e);
            $storyResult->setStoryShouldFail();
        } catch (E5xx_ExpectFailed $e) {
            $phaseResult->setContinuePlaying($phaseResult::FAILED, $e->getMessage(), $e);
            $storyResult->setStoryShouldFail();
        } catch (E4xx_StoryShouldFail $e) {
            $phaseResult->setContinuePlaying($phaseResult::FAILED, $e->getMessage(), $e);
            $storyResult->setStoryShouldFail();
        } catch (E5xx_NotImplemented $e) {
            $phaseResult->setPlayingFailed($phaseResult::INCOMPLETE, $e->getMessage(), $e);
            $storyResult->setStoryIsIncomplete($phaseResult);
        } catch (Exception $e) {
            $phaseResult->setPlayingFailed($phaseResult::ERROR, $e->getMessage(), $e);
            $storyResult->setStoryHasError($phaseResult);
        }
        // close off any open log actions
        $st->closeAllOpenActions();
        // tidy up after ourselves
        $this->doPerPhaseTeardown();
        // all done
        return $phaseResult;
    }
PreTestPredictionPhase