/** * @param RequestInterface $request * @param string $fileName * @return ResultInterface */ private function checkRequest(RequestInterface $request, $fileName) { try { $event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.verify.solution-execute.pre', $request)); $solutionResponse = $this->executePhpFile($this->exercise->getSolution()->getEntryPoint(), $event->getRequest(), 'solution'); } catch (CodeExecutionException $e) { $this->eventDispatcher->dispatch(new Event('cgi.verify.solution-execute.fail', ['exception' => $e])); throw new SolutionExecutionException($e->getMessage()); } try { $event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.verify.user-execute.pre', $request)); $userResponse = $this->executePhpFile($fileName, $event->getRequest(), 'user'); } catch (CodeExecutionException $e) { $this->eventDispatcher->dispatch(new Event('cgi.verify.user-execute.fail', ['exception' => $e])); return Failure::fromNameAndCodeExecutionFailure($this->getName(), $e); } $solutionBody = (string) $solutionResponse->getBody(); $userBody = (string) $userResponse->getBody(); $solutionHeaders = $this->getHeaders($solutionResponse); $userHeaders = $this->getHeaders($userResponse); if ($solutionBody !== $userBody || $solutionHeaders !== $userHeaders) { return new CgiOutRequestFailure($request, $solutionBody, $userBody, $solutionHeaders, $userHeaders); } return new Success($this->getName()); }
public function testFailureFromCodeExecutionException() { $e = new CodeExecutionException('Something went wrong yo'); $failure = Failure::fromNameAndCodeExecutionFailure('Some Check', $e); $this->assertInstanceOf(ResultInterface::class, $failure); $this->assertEquals('Something went wrong yo', $failure->getReason()); $this->assertEquals('Some Check', $failure->getCheckName()); }
/** * @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); }