public function grade(CodingExecutionResult $result) { $normalGrader = new PhpGradingTool($result); $htmlGrader = new HtmlOutputGradingTool($result); $normalGrader->assertInputContains('fallCollection.twig', 'random(', 'Are you using the random() function?'); $normalGrader->assertInputContains('fallCollection.twig', 'upper', 'Don\'t forget to use the `upper` filter to uppercase the colors!'); $normalGrader->assertInputContains('fallCollection.twig', 'black', 'Use `black` (lowercase) as one of the random colors', true); $normalGrader->assertInputContains('fallCollection.twig', 'white', 'Use `black` (lowercase) as one of the random colors', true); $normalGrader->assertInputContains('fallCollection.twig', 'green', 'Use `black` (lowercase) as one of the random colors', true); if (!$htmlGrader->doesOutputContain('BLACK', true) && !$htmlGrader->doesOutputContain('WHITE', true) && !$htmlGrader->doesOutputContain('GREEN', true)) { throw new GradingException('The output does not contain any of the colors BLACK, GREEN or WHITE - are you randomly selecting one of these and uppercasing them?'); } }
public function grade(CodingExecutionResult $result) { $htmlGrader = new HtmlOutputGradingTool($result); $deathStar3Class = new \ReflectionClass('\\DeathStarIII'); if (!$deathStar3Class->isSubclassOf('\\AbstractDeathStar')) { throw new GradingException('The `DeathStarIII` class should extend the `AbstractDeathStar` one.'); } $deathStar3 = $result->getDeclaredVariableValue('deathStar3'); if (!$htmlGrader->doesOutputContain($deathStar3->getDescription())) { throw new GradingException('Hmm, did you print the `DeathStarIII` description in `h3` tag?'); } }