Exemplo n.º 1
0
 /**
  * @param Request $request
  * @return Response
  * @throws AccessDeniedException
  * @throws ThrottleLimitExceededException
  * @throws UnknownEndpointException
  * @throws MethodNotFoundException
  * @throws NotAcceptableResponseTypeException
  */
 public function handleRequest(Request $request) : Response
 {
     $this->validateKey($request);
     $this->validateAcceptableMIMETypes($request);
     if ($this->throttle->shouldThrottle($request)) {
         throw new ThrottleLimitExceededException('Request limit exceeded');
     }
     if (!$this->accessControl->validateAccess($request)) {
         throw new AccessDeniedException("API key does not have the required permissions to access requested resource");
     }
     $this->throttle->logRequest($request);
     $responseData = $this->router->route($request);
     return $this->responseFactory->getResponse($responseData, $request->getAcceptableMIMETypes());
 }
Exemplo n.º 2
0
 public function testRouteThrowsExceptionWhenMethodIsInvalid()
 {
     $method = 'NotAMethodInEndpoint';
     $endpoint = 'asdasd';
     $version = '123';
     $requestMock = $this->getMockBuilder('\\LunixREST\\Request\\Request')->disableOriginalConstructor()->getMock();
     $requestMock->method('getVersion')->willReturn($version);
     $requestMock->method('getEndpoint')->willReturn($endpoint);
     $requestMock->method('getMethod')->willReturn($method);
     $endpointMock = $this->getMockBuilder('\\LunixREST\\Endpoint\\Endpoint')->getMock();
     $endpointFactoryMock = $this->getMockBuilder('\\LunixREST\\Endpoint\\EndpointFactory')->getMock();
     $endpointFactoryMock->method('getEndpoint')->with($endpoint, $version)->willReturn($endpointMock);
     $this->expectException('LunixREST\\Server\\Exceptions\\MethodNotFoundException');
     $router = new Router($endpointFactoryMock);
     $router->route($requestMock);
 }