public function testFailureFromArgsAndOutput() { $args = new ArrayObject(); $failure = RequestFailure::fromArgsAndOutput($args, 'Expected Output', 'Actual Output'); $this->assertEquals('Expected Output', $failure->getExpectedOutput()); $this->assertEquals('Actual Output', $failure->getActualOutput()); $this->assertSame($args, $failure->getArgs()); }
/** * @param array $args * @param Input $input * @return ResultInterface */ private function doVerify(array $args, Input $input) { //arrays are not pass-by-ref $args = new ArrayObject($args); try { $event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.reference-execute.pre', $args)); $solutionOutput = $this->executePhpFile($this->exercise->getSolution()->getEntryPoint(), $event->getArgs(), 'reference'); } catch (CodeExecutionException $e) { $this->eventDispatcher->dispatch(new Event('cli.verify.reference-execute.fail', ['exception' => $e])); throw new SolutionExecutionException($e->getMessage()); } try { $event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.student-execute.pre', $args)); $userOutput = $this->executePhpFile($input->getArgument('program'), $event->getArgs(), 'student'); } catch (CodeExecutionException $e) { $this->eventDispatcher->dispatch(new Event('cli.verify.student-execute.fail', ['exception' => $e])); return GenericFailure::fromArgsAndCodeExecutionFailure($args, $e); } if ($solutionOutput === $userOutput) { return new Success($args); } return RequestFailure::fromArgsAndOutput($args, $solutionOutput, $userOutput); }
/** * Print the actual and expected output. * * @param ResultsRenderer $renderer * @return string */ public function render(ResultsRenderer $renderer) { return sprintf(" %s\n%s\n\n %s\n%s\n", $renderer->style('YOUR OUTPUT:', ['bold', 'yellow']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getActualValue()), 'red')), $renderer->style('EXPECTED OUTPUT:', ['bold', 'yellow']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getExpectedValue()), 'green'))); }