public function grade(CodingExecutionResult $result)
 {
     $deathStar = $result->getDeclaredVariableValue('deathStar');
     if (!method_exists($deathStar, 'getLaserRange')) {
         throw new GradingException('The `getLaserRange` method does not exist for the `DeathStarII` class - did you create it?');
     }
     if (4000000 != $deathStar->getLaserRange()) {
         throw new GradingException('The `getLaserRange` method in the `DeathStarII` class should return a doubled value of the parent method.');
     }
 }
 public function assertInputDoesNotContain($filename, $string, $gradingErrorMessage = null, $caseSensitive = false)
 {
     $contents = $this->result->getInputFileContents($filename);
     if ($this->stringContains($contents, $string, $caseSensitive)) {
         if ($gradingErrorMessage === null) {
             $gradingErrorMessage = sprintf('I see `%s` used in `%`, but it shouldn\'t be there!', $string, $filename);
         }
         throw new GradingException($gradingErrorMessage);
     }
 }
 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?');
     }
 }
 public function grade(CodingExecutionResult $result)
 {
     $phpGrader = new PhpGradingTool($result);
     $phpGrader->assertVariableExists('deathStar');
     $deathStar = $result->getDeclaredVariableValue('deathStar');
     if (!$deathStar instanceof \DeathStarII) {
         throw new GradingException('The `$deathStar` variable exists, but is not set to a `DeathStarII` object.');
     }
     if (!$deathStar instanceof \DeathStar) {
         throw new GradingException('The `DeathStarII` class is not extending `DeathStar` one.');
     }
 }
 public function grade(CodingExecutionResult $result)
 {
     $phpGrader = new PhpGradingTool($result);
     $phpGrader->assertVariableExists('original');
     $phpGrader->assertVariableExists('new');
     $original = $result->getDeclaredVariableValue('original');
     $new = $result->getDeclaredVariableValue('new');
     if (!$original instanceof \DeathStar) {
         throw new GradingException('The `$original` variable exists, but is not set to a `DeathStar` object.');
     }
     if (!$new instanceof \DeathStarII) {
         throw new GradingException('The `$new` variable exists, but is not set to a `DeathStarII` object.');
     }
     if (!$new instanceof \DeathStar) {
         throw new GradingException('The `DeathStarII` class is not extending `DeathStar` one.');
     }
     if ('Thermal Exhaust Port' != $original->getWeakness()) {
         throw new GradingException('The return value of `getWeakness()` method in a `DeathStar` class was changed. You should override it.');
     }
     if (null !== $new->getWeakness()) {
         throw new GradingException('The `getWeakness()` method of `DeathStarII` class does not return `null`.');
     }
 }
 public function grade(CodingExecutionResult $result)
 {
     $grader = new GenericGradingTool($result);
     $phpGrader = new PhpGradingTool($result);
     if (!class_exists('\\Cache')) {
         throw new GradingException('Class `Cache` does not exist. Did you create it?');
     }
     $cacheClass = new \ReflectionClass('\\Cache');
     if (!$cacheClass->hasMethod('fetchFromCache')) {
         throw new GradingException('Method `fetchFromCache` does not exist in the `Cache` class.');
     }
     if (!$cacheClass->hasMethod('saveToCache')) {
         throw new GradingException('Method `saveToCache` does not exist in the `Cache` class.');
     }
     $phpGrader->assertVariableExists('transformer', 'I don\'t see the $transformer variable in index.php anymore - did you delete it?');
     $transformer = $result->getDeclaredVariableValue('transformer');
     $transformerClass = new \ReflectionObject($transformer);
     if (!$transformerClass->hasMethod('__construct')) {
         throw new GradingException('Make sure you give the `StringTransformer` class a `__construct()`. It should have one argument: a `Cache` object.');
     }
     $grader->assertInputDoesNotContain('StringTransformer.php', 'file_get_contents', 'I still see `file_get_contents()` inside of `StringTransformer`. Make sure you\'ve moved all of the caching logic into the Cache class');
     // todo - create a mocked Cache, pass it into
     // $transformer and assert that its cache methods are called
 }
 public function __construct(CodingExecutionResult $result)
 {
     $this->output = $result->getOutput();
 }