public function testFailureFromCheck()
 {
     $check = $this->createMock(CheckInterface::class);
     $check->expects($this->any())->method('getName')->will($this->returnValue('Some Check'));
     $failure = StdOutFailure::fromCheckAndOutput($check, 'Expected Output', 'Actual Output');
     $this->assertEquals('Expected Output', $failure->getExpectedOutput());
     $this->assertEquals('Actual Output', $failure->getActualOutput());
     $this->assertEquals('Some Check', $failure->getCheckName());
 }
示例#2
0
 /**
  * @param string $fileName
  * @return ResultInterface
  */
 public function verify($fileName)
 {
     //arrays are not pass-by-ref
     $args = new ArrayObject($this->exercise->getArgs());
     try {
         $event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.solution-execute.pre', $args));
         $solutionOutput = $this->executePhpFile($this->exercise->getSolution()->getEntryPoint(), $event->getArgs(), 'solution');
     } catch (CodeExecutionException $e) {
         $this->eventDispatcher->dispatch(new Event('cli.verify.solution-execute.fail', ['exception' => $e]));
         throw new SolutionExecutionException($e->getMessage());
     }
     try {
         $event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.user-execute.pre', $args));
         $userOutput = $this->executePhpFile($fileName, $event->getArgs(), 'user');
     } catch (CodeExecutionException $e) {
         $this->eventDispatcher->dispatch(new Event('cli.verify.user-execute.fail', ['exception' => $e]));
         return Failure::fromNameAndCodeExecutionFailure($this->getName(), $e);
     }
     if ($solutionOutput === $userOutput) {
         return new Success($this->getName());
     }
     return StdOutFailure::fromNameAndOutput($this->getName(), $solutionOutput, $userOutput);
 }
 /**
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     return sprintf("  %s\n%s\n\n  %s\n%s\n", $renderer->style("ACTUAL", ['bold', 'underline', 'yellow']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getActualOutput()), 'red')), $renderer->style("EXPECTED", ['yellow', 'bold', 'underline']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getExpectedOutput()), 'red')));
 }