/** * @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); }