public function testParsingSingleUpdateActionRequest()
 {
     // Given...
     $queryOverrides = ['getContent' => function () {
         return self::UPDATE_BODY;
     }];
     $jsonCoder = Stub::makeEmpty('GoIntegro\\Json\\JsonCoder', ['decode' => json_decode(self::HTTP_PUT_BODY, TRUE)]);
     $request = self::createRequest('/api/v1/users', $queryOverrides, Parser::HTTP_PUT, self::HTTP_PUT_BODY);
     $params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryIds' => ['27'], 'primaryType' => 'users']);
     $parser = new ActionParser($jsonCoder, self::createMetadataMiner());
     // When...
     $action = $parser->parse($request, $params);
     // Then...
     $this->assertSame(RequestAction::ACTION_UPDATE, $action->name);
     $this->assertSame(RequestAction::TYPE_SINGLE, $action->type);
     $this->assertSame(RequestAction::TARGET_RESOURCE, $action->target);
 }
Exemple #2
0
 /**
  * Parsea ciertos parámetros de un pedido de HTTP.
  * @param Request $request
  * @throws ResourceNotFoundException
  * @throws ActionNotAllowedException
  * @throws ParseException
  * @throws EntityAccessDeniedException
  * @throws EntityNotFoundException
  */
 public function parse(Request $request)
 {
     $content = $request->getContent();
     if (!empty($content) && self::HTTP_DELETE == $request->getMethod()) {
         throw new ParseException(self::ERROR_CONTENT_ON_DELETE);
     }
     $params = new Params();
     $params->path = $this->parsePath($request);
     $params->i18n = $this->parseI18n($request);
     $params->primaryType = $this->parsePrimaryType($request);
     $params->primaryClass = $this->getEntityClass($params->primaryType);
     $params->relationship = $this->parseRelationship($request, $params);
     $params->primaryIds = $this->parsePrimaryIds($request, $params->relationship);
     $params->relationshipIds = $this->parseRelationshipIds($request);
     $params->locale = $this->localeNegotiator->negotiate($request);
     if (!empty($this->translatableListener) && !empty($params->locale)) {
         $params->translatable = TRUE;
         $this->translatableListener->setTranslatableLocale($params->locale);
     } else {
         $params->translatable = FALSE;
     }
     if ($request->query->has('include')) {
         $params->include = $this->parseInclude($request);
     }
     if ($request->query->has('fields')) {
         $params->sparseFields = $this->parseSparseFields($request, $params->primaryType);
     }
     if ($request->query->has('page')) {
         $params->pagination = $this->paginationParser->parse($request, $params);
     }
     $params->sorting = $this->sortingParser->parse($request, $params);
     $params->filters = $this->filterParser->parse($request, $params);
     $params->action = $this->actionParser->parse($request, $params);
     $params->resourceConfig = $this->resourceEntityMapper->getResourcesConfig()->get($params->primaryType);
     // Needs the params from the ActionParser.
     $params->entities = $this->entityFinder->find($params);
     // Needs the params from the ActionParser (and ParamEntityFinder).
     $params->resources = $this->bodyParser->parse($request, $params);
     return $params;
 }