コード例 #1
0
 public function testFailureFromCodeExecutionException()
 {
     $e = new CodeExecutionException('Something went wrong yo');
     $request = $this->createMock(RequestInterface::class);
     $failure = GenericFailure::fromRequestAndCodeExecutionFailure($request, $e);
     $this->assertInstanceOf(GenericFailure::class, $failure);
     $this->assertSame($request, $failure->getRequest());
     $this->assertEquals('Something went wrong yo', $failure->getReason());
     $this->assertEquals('CGI Program Runner', $failure->getCheckName());
 }
コード例 #2
0
ファイル: CgiRunner.php プロジェクト: php-school/php-workshop
 /**
  * @param RequestInterface $request
  * @param string $fileName
  * @return ResultInterface
  */
 private function checkRequest(RequestInterface $request, $fileName)
 {
     try {
         $event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.verify.reference-execute.pre', $request));
         $solutionResponse = $this->executePhpFile($this->exercise->getSolution()->getEntryPoint(), $event->getRequest(), 'reference');
     } catch (CodeExecutionException $e) {
         $this->eventDispatcher->dispatch(new Event('cgi.verify.reference-execute.fail', ['exception' => $e]));
         throw new SolutionExecutionException($e->getMessage());
     }
     try {
         $event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.verify.student-execute.pre', $request));
         $userResponse = $this->executePhpFile($fileName, $event->getRequest(), 'student');
     } catch (CodeExecutionException $e) {
         $this->eventDispatcher->dispatch(new Event('cgi.verify.student-execute.fail', ['exception' => $e]));
         return GenericFailure::fromRequestAndCodeExecutionFailure($request, $e);
     }
     $solutionBody = (string) $solutionResponse->getBody();
     $userBody = (string) $userResponse->getBody();
     $solutionHeaders = $this->getHeaders($solutionResponse);
     $userHeaders = $this->getHeaders($userResponse);
     if ($solutionBody !== $userBody || $solutionHeaders !== $userHeaders) {
         return new RequestFailure($request, $solutionBody, $userBody, $solutionHeaders, $userHeaders);
     }
     return new Success($request);
 }