// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $actualData = 2.0; $expectedData1 = 1; assertsDouble($actualData)->isGreaterThan($expectedData1); // and these should fail try { $expectedData2 = 2; assertsDouble($actualData)->isGreaterThan($expectedData2); } catch (Exception $e) { $checkpoint->test2Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Passed"); assertsBoolean($checkpoint->test2Passed)->isTrue(); });
try { $stringData = ""; assertsDouble($stringData)->isDouble(); } catch (Exception $e) { $checkpoint->stringTestPassed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("nullTestPassed"); assertsBoolean($checkpoint->nullTestPassed)->isTrue(); assertsObject($checkpoint)->hasAttribute("arrayTestPassed"); assertsBoolean($checkpoint->arrayTestPassed)->isTrue(); assertsObject($checkpoint)->hasAttribute("booleanTest1Passed"); assertsBoolean($checkpoint->booleanTest1Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("booleanTest2Passed"); assertsBoolean($checkpoint->booleanTest2Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("intTest1Passed"); assertsBoolean($checkpoint->intTest1Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("intTest2Passed"); assertsBoolean($checkpoint->intTest2Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("objectTestPassed"); assertsBoolean($checkpoint->objectTestPassed)->isTrue(); assertsObject($checkpoint)->hasAttribute("stringTestPassed"); assertsBoolean($checkpoint->stringTestPassed)->isTrue(); });
// // ------------------------------------------------------------------------ $story = newStoryFor('Storyplayer')->inGroup('Stories > Checkpoint')->called('Each story starts with empty checkpoint (pt 1)'); $story->requiresStoryplayerVersion(2); // ======================================================================== // // TEST SETUP / TEARDOWN // // ------------------------------------------------------------------------ $story->addTestSetup(function () { // do nothing }); // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); $checkpoint->thisDataShouldDisappearInPt2 = true; }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function ($st) { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute('thisDataShouldDisappearInPt2'); assertsBoolean($checkpoint->thisDataShouldDisappearInPt2)->isTrue(); });
// ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $testData1 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d", "echo" => [1, 2, 3, 4, 5]]; $testData2 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d", "echo" => [1, 2, 3, 4, 5]]; assertsArray($testData1)->equals($testData2); // and this should fail $testData3 = [1]; $checkpoint->test2Exception = false; try { assertsArray($testData3)->equals($testData1); } catch (Exception $e) { $checkpoint->test2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); });
assertsObject($actualData)->isNotEmpty(); $actualData = new stdClass(); $actualData->attribute1 = 99; assertsObject($actualData)->isNotEmpty(); $actualData = new stdClass(); $actualData->attribute1 = $checkpoint; assertsObject($actualData)->isNotEmpty(); $actualData = new stdClass(); $actualData->attribute1 = ""; assertsObject($actualData)->isNotEmpty(); $actualData = new stdClass(); $actualData->attribute1 = "hello, Storyplayer"; assertsObject($actualData)->isNotEmpty(); // and this should fail $actualData = new stdClass(); try { assertsObject($actualData)->isNotEmpty(); } catch (Exception $e) { $checkpoint->test1Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test1Passed"); assertsBoolean($checkpoint->test1Passed)->equals(true); });
$checkpoint->test108Passed = true; } try { assertsObject($actualData)->hasAttributeWithValue('attribute11', 99); } catch (Exception $e) { $checkpoint->test109Passed = true; } try { assertsObject($actualData)->hasAttributeWithValue('attribute11', $checkpoint); } catch (Exception $e) { $checkpoint->test110Passed = true; } try { assertsObject($actualData)->hasAttributeWithValue('attribute11', ""); } catch (Exception $e) { $checkpoint->test111Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); for ($x = 1; $x <= 111; $x++) { $attributeName = "test{$x}Passed"; assertsObject($checkpoint)->hasAttribute($attributeName); assertsBoolean($checkpoint->{$attributeName})->equals(true); } });
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $data1 = []; assertsArray($data1)->isArray(); // and this should fail $checkpoint->data2Exception = false; try { $data2 = ""; assertsArray($data2)->isArray(); } catch (Exception $e) { $checkpoint->data2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("data2Exception"); assertsBoolean($checkpoint->data2Exception)->isTrue(); });
assertsString($objectData)->isString(); } catch (Exception $e) { $checkpoint->objectTestPassed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("nullTestPassed"); assertsBoolean($checkpoint->nullTestPassed)->isTrue(); assertsObject($checkpoint)->hasAttribute("arrayTestPassed"); assertsBoolean($checkpoint->arrayTestPassed)->isTrue(); assertsObject($checkpoint)->hasAttribute("booleanTest1Passed"); assertsBoolean($checkpoint->booleanTest1Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("booleanTest2Passed"); assertsBoolean($checkpoint->booleanTest2Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("doubleTest1Passed"); assertsBoolean($checkpoint->doubleTest1Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("doubleTest2Passed"); assertsBoolean($checkpoint->doubleTest2Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("intTest1Passed"); assertsBoolean($checkpoint->intTest1Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("intTest2Passed"); assertsBoolean($checkpoint->intTest2Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("objectTestPassed"); assertsBoolean($checkpoint->objectTestPassed)->isTrue(); });
// STORY SETUP / TEAR-DOWN // // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $objectData = new stdClass(); assertsObject($objectData)->isNotNull(); // and these should fail try { $nullData = null; assertsObject($nullData)->isNotNull(); } catch (Exception $e) { $checkpoint->nullTestPassed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("nullTestPassed"); assertsBoolean($checkpoint->nullTestPassed)->isTrue(); });