コード例 #1
0
ファイル: CliRunner.php プロジェクト: php-school/php-workshop
 /**
  * @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);
 }
コード例 #2
0
ファイル: CliRunner.php プロジェクト: jacmoe/php-workshop
 /**
  * @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);
 }