/** * @covers DataSift\Storyplayer\PlayerLib\Story_Loader::loadStory */ public function testThrowsExceptionIfStoryVariableDefinedWithWrongType() { // ---------------------------------------------------------------- // setup the test $filename = __DIR__ . '/test-stories/DeclaresStoryOfWrongType.php'; $expectedCode = 500; $expectedMessage = "Story file '{$filename}' did create a \$story variable, but it is of type 'stdClass' instead of type 'DataSift\\Storyplayer\\PlayerLib\\Story'"; // ---------------------------------------------------------------- // perform the change // this should throw an exception $caughtException = false; try { Story_Loader::loadStory($filename); } catch (Exception $e) { $caughtException = $e; } // ---------------------------------------------------------------- // test the results $this->assertTrue($caughtException instanceof E5xx_InvalidStoryFile); $this->assertEquals($expectedCode, $caughtException->getCode()); $this->assertEquals($expectedMessage, $caughtException->getMessage()); }
public function play(StoryTeller $st, Injectables $injectables) { // shorthand $output = $st->getOutput(); // we're going to use this to play our setup and teardown phases $phasesPlayer = new PhaseGroup_Player(); // load our story $story = Story_Loader::loadStory($this->storyFilename); $st->setStory($story); // does our story want to keep the test device open between // phases? if ($story->getPersistDevice()) { $st->setPersistDevice(); } // set default callbacks up $story->setDefaultCallbacks(); // make sure we start with a brand new checkpoint $st->setCheckpoint(new Story_Checkpoint($st)); // tell the outside world what we're doing $activity = "Running story"; $name = $story->getCategory() . ' > ' . $story->getGroupAsString() . ' > ' . $story->getName(); $output->startPhaseGroup($activity, $name); // run the phases before the story truly starts $phasesPlayer->playPhases($activity, $st, $injectables, $this->startupPhases, $story); // what happened? $result = $story->getResult(); if (!$result->getPhaseGroupSucceeded()) { // make sure the result has the story's filename in $result->filename = $this->storyFilename; // announce the results $output->endPhaseGroup($result); // all done return; } // run the phases in the 'story' section $phasesPlayer->playPhases($activity, $st, $injectables, $this->storyPhases, $story); // grab the result at this point $result = clone $story->getResult(); // run the shutdown phase $phasesPlayer->playPhases($activity, $st, $injectables, $this->shutdownPhases, $story); // do we also need to look at any failures that happened during // the shutdown phase? if ($result->getPhaseGroupSucceeded()) { $result = $story->getResult(); } // make sure the result has the story's filename in $result->filename = $this->storyFilename; // announce the results $output->endPhaseGroup($result); // all done }