/**
  * @ApiDoc(
  *  resource=true,
  *  description="Create new user",
  *  section="User",
  *  statusCodes={
  *     201="User created",
  *     400="Incorrect 'name' provided"
  *  }
  * )
  * @RequestParam(name="name", requirements=".*\S.*", allowBlank=false)
  *
  * @param ParamFetcher $paramFetcher
  * @return Response
  */
 public function postUserAction(ParamFetcher $paramFetcher)
 {
     $user = new User();
     $user->setName($paramFetcher->get('name'));
     $this->entityManager->persist($user);
     $this->entityManager->flush();
     $apiKey = $this->apiKeyManager->generateApiKeyForUser($user);
     $view = $this->routeRedirectView('api_v1_get_user', ['requestedUser' => $user->getId()])->setHeader(Headers::API_KEY, $apiKey);
     return $this->handleView($view);
 }
 public function testGenerateApiKeyForUserAndGetInfoFromApiKey()
 {
     $user = $this->prophesize('AppBundle\\Entity\\User');
     $user->getId()->willReturn(1);
     $user->getToken()->willReturn('token');
     $apiKey = $this->apiKeyManager->generateApiKeyForUser($user->reveal());
     $this->assertStringMatchesFormat('%s.%s.%s', $apiKey);
     $apiKeyInfo = $this->apiKeyManager->getInfoFromApiKey($apiKey);
     $this->assertEquals(1, $apiKeyInfo->id);
     $this->assertEquals('token', $apiKeyInfo->token);
 }