/** @test */
 public function itThrowAnExceptionWhenNoResponseDefinitionIsFound()
 {
     $this->expectException(\InvalidArgumentException::class);
     $this->expectExceptionMessage('No response definition for GET /foo/{id} is available for status code 200');
     $requestDefinition = new RequestDefinition('GET', 'getFoo', '/foo/{id}', new Parameters([]), ['application/json'], []);
     $requestDefinition->getResponseDefinition(200);
 }
 public function validateQueryParameters(RequestInterface $request, RequestDefinition $definition)
 {
     if ($definition->hasQueryParametersSchema()) {
         parse_str($request->getUri()->getQuery(), $queryParams);
         $schema = $definition->getQueryParametersSchema();
         $queryParams = QueryParamsNormalizer::normalize($queryParams, $schema);
         $this->validate((object) $queryParams, $schema, 'query');
     }
 }
Exemple #3
0
 private function addRequestDefinition(RequestDefinition $request)
 {
     $this->requestDefinitions[$request->getOperationId()] = $request;
 }
 /**
  * Create an PSR-7 Request from the API Schema
  *
  * @param RequestDefinition $definition
  * @param array $params An array of parameters
  *
  * @todo handle default values for request parameters
  *
  * @return RequestInterface
  */
 private function createRequestFromDefinition(RequestDefinition $definition, array $params)
 {
     $contentType = $definition->getContentTypes()[0];
     $requestParameters = $definition->getRequestParameters();
     $path = [];
     $query = [];
     $headers = ['Content-Type' => $contentType];
     $body = null;
     foreach ($params as $name => $value) {
         $requestParameter = $requestParameters->getByName($name);
         if ($requestParameter === null) {
             throw new \InvalidArgumentException($name . ' is not a defined request parameter');
         }
         switch ($requestParameter->getLocation()) {
             case 'path':
                 $path[$name] = $value;
                 break;
             case 'query':
                 $query[$name] = $value;
                 break;
             case 'header':
                 $query[$name] = $value;
                 break;
             case 'body':
                 $body = $this->serializeRequestBody($value, $contentType);
         }
     }
     $request = $this->messageFactory->createRequest($definition->getMethod(), $this->buildRequestUri($definition->getPathTemplate(), $path, $query), $headers, $body);
     return $request;
 }