From 0b3b84706bb32d12586bfddefccf5600a347a380 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Sat, 17 Oct 2015 21:29:59 +0300 Subject: [PATCH 1/4] Add code activities to the ch4 (using-behat) --- .../UsingBehat/IndependentScenariosMC.php | 77 ++++++++ .../Challenges/UsingBehat/LsFeatureCoding.php | 185 ++++++++++++++++++ 2 files changed, 262 insertions(+) create mode 100644 knpu/Challenges/UsingBehat/IndependentScenariosMC.php create mode 100644 knpu/Challenges/UsingBehat/LsFeatureCoding.php diff --git a/knpu/Challenges/UsingBehat/IndependentScenariosMC.php b/knpu/Challenges/UsingBehat/IndependentScenariosMC.php new file mode 100644 index 0000000..954b86b --- /dev/null +++ b/knpu/Challenges/UsingBehat/IndependentScenariosMC.php @@ -0,0 +1,77 @@ +addAnswer(<<addAnswer(<<addAnswer(<<addFileContents('ls.feature', <<addFileContents('features/bootstrap/FeatureContext.php', <<output = shell_exec(\$command); + } + + /** + * @Then I should see :string in the output + */ + public function iShouldSeeInTheOutput(\$string) + { + if (strpos(\$this->output, \$string) === false) { + throw new \Exception(sprintf('Did not see "%s" in output "%s"', \$string, \$this->output)); + } + } +} +EOF + , true) + ->setEntryPointFilename('ls.feature') + ; + + return $fileBuilder; + } + + public function getExecutionMode() + { + return self::EXECUTION_MODE_GHERKIN; + } + + public function setupContext(CodingContext $context) + { + } + + public function grade(CodingExecutionResult $result) + { + $gherkin = new GherkinGradingTool($result); + + $feature = $gherkin->getFeature('ls.feature'); + + $scenarios = $feature->getScenarios(); + + if (empty($scenarios)) { + throw new GradingException('I don\'t see *any* scenarios. Check your syntax on the scenario'); + } + + $countScenarios = count($scenarios); + if (2 !== $countScenarios) { + throw new GradingException( + sprintf('Make sure to create only a *2* new scenarios. Looks like *%d* was created.', $countScenarios) + ); + } + + /** @var ScenarioNode $scenario */ + foreach ($scenarios as $index => $scenario) { + $scenarioNumber = $index + 1; + + if (!$scenario->getTitle()) { + throw new GradingException(sprintf( + 'Make sure to put a short title after your scenario %d.', + $scenarioNumber + )); + } + + /** @var StepNode[] $steps */ + $steps = $scenario->getSteps(); + $hasGiven = false; + $hasWhen = false; + $hasThen = false; + foreach ($steps as $step) { + if ('Given' == $step->getType()) { + $hasGiven = true; + } elseif ('When' == $step->getType()) { + $hasWhen = true; + } elseif ('Then' == $step->getType()) { + $hasThen = true; + } + } + + if (!$hasGiven) { + throw new GradingException(sprintf( + 'I don\'t see a `Given` in your scenario %d: you probably want one to have a hidden file starting with `.`.', + $scenarioNumber + )); + } + if (!$hasWhen) { + throw new GradingException(sprintf( + 'I don\'t see a `When` in your scenario %d: you definitely need some, like for running commands in the terminal.', + $scenarioNumber + )); + } + if (!$hasThen) { + throw new GradingException(sprintf( + 'I don\'t see a `Then` in your scenario %d: you probably want one where you check if the success message was shown.', + $scenarioNumber + )); + } + } + } + + public function configureCorrectAnswer(CorrectAnswer $correctAnswer) + { + $correctAnswer + ->setFileContents('ls.feature', <<