diff --git a/knpu/Challenges/BehatHooksBackground/CheckStepTestResultCoding.php b/knpu/Challenges/BehatHooksBackground/CheckStepTestResultCoding.php new file mode 100644 index 0000000..d9e03ec --- /dev/null +++ b/knpu/Challenges/BehatHooksBackground/CheckStepTestResultCoding.php @@ -0,0 +1,209 @@ +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 + ) + ->addFileContents('ls.feature', <<setEntryPointFilename('features/bootstrap/FeatureContext.php') + ; + + return $fileBuilder; + } + + public function getExecutionMode() + { + return self::EXECUTION_MODE_PHP_NORMAL; + } + + public function setupContext(CodingContext $context) + { + // Create dummy interfaces if not exists that implemented by FeatureContext class. + if (!class_exists('\Behat\Behat\Context\Context')) { + eval(<<hasMethod('afterStepHook')) { + throw new GradingException('The `afterStepHook()` method wasn\'t found in the `FeatureContext` class.'); + } + if (!$featureContextClass->getMethod('afterStepHook')->isPublic()) { + throw new GradingException('The `afterStepHook()` method should be public.'); + } + $afterStepHookMethod = $featureContextClass->getMethod('afterStepHook'); + $docComment = $afterStepHookMethod->getDocComment(); + if (false === strpos($docComment, '@AfterStep')) { + throw new GradingException('You should to use `@AfterStep` annotation for `afterStepHook()` method.'); + } + $afterStepHookParameters = $afterStepHookMethod->getParameters(); + if (1 !== $afterStepHookMethod->getNumberOfRequiredParameters()) { + throw new GradingException('Make sure you give the `afterStepHook()` method exactly one argument.'); + } + if (0 !== strcmp('event', $afterStepHookParameters[0]->getName())) { + throw new GradingException('Though you can really call it anything, let\'s call the argument to `afterStepHook()` `$event` for clarity.'); + } + } + + public function configureCorrectAnswer(CorrectAnswer $correctAnswer) + { + $correctAnswer + ->setFileContents('features/bootstrap/FeatureContext.php', <<getTestResult()->isPassed(); + + var_dump(\$isPassed); + } + + /** + * @Given I have a file named :filename + */ + public function iHaveAFileNamed(\$filename) + { + touch(\$filename); + } + + /** + * @When I run :command + */ + public function iRun(\$command) + { + \$this->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 + ) + ; + } +} diff --git a/knpu/Challenges/BehatHooksBackground/afterStepHookCoding.php b/knpu/Challenges/BehatHooksBackground/afterStepHookCoding.php new file mode 100644 index 0000000..c648f0c --- /dev/null +++ b/knpu/Challenges/BehatHooksBackground/afterStepHookCoding.php @@ -0,0 +1,188 @@ +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 + ) + ->addFileContents('ls.feature', <<setEntryPointFilename('features/bootstrap/FeatureContext.php') + ; + + return $fileBuilder; + } + + public function getExecutionMode() + { + return self::EXECUTION_MODE_PHP_NORMAL; + } + + public function setupContext(CodingContext $context) + { + // Create dummy interfaces if not exists that implemented by FeatureContext class. + if (!class_exists('\Behat\Behat\Context\Context')) { + eval(<<hasMethod('afterStepHook')) { + throw new GradingException('The `afterStepHook()` method wasn\'t found in the `FeatureContext` class.'); + } + if (!$featureContextClass->getMethod('afterStepHook')->isPublic()) { + throw new GradingException('The `afterStepHook()` method should be public.'); + } + $docComment = $featureContextClass->getMethod('afterStepHook')->getDocComment(); + if (false === strpos($docComment, '@AfterStep')) { + throw new GradingException('You should to use `@AfterStep` annotation for `afterStepHook()` method.'); + } + } + + public function configureCorrectAnswer(CorrectAnswer $correctAnswer) + { + $correctAnswer + ->setFileContents('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 + ) + ; + } +} diff --git a/knpu/metadata.yml b/knpu/metadata.yml index aa649b5..4726563 100644 --- a/knpu/metadata.yml +++ b/knpu/metadata.yml @@ -52,6 +52,9 @@ chapters: behat-hooks-background: video_key: is_finished: false + challenges: + - Challenges\BehatHooksBackground\afterStepHookCoding + # - Challenges\BehatHooksBackground\CheckStepTestResultCoding using-mink: video_key: is_finished: false