/**
  * @Route("/apigen/{id}", name="oro_user_apigen", requirements={"id"="\d+"})
  * @AclAncestor("oro_user_user_update")
  */
 public function apigenAction(User $user)
 {
     if (!($api = $user->getApi())) {
         $api = new UserApi();
     }
     $api->setApiKey($api->generateKey())->setUser($user);
     $em = $this->getDoctrine()->getManager();
     $em->persist($api);
     $em->flush();
     return $this->getRequest()->isXmlHttpRequest() ? new JsonResponse($api->getApiKey()) : $this->forward('OroUserBundle:User:view', array('user' => $user));
 }
 public function testApi()
 {
     $user = new User();
     $api = new UserApi();
     $this->assertNull($user->getApi());
     $user->setApi($api);
     $this->assertEquals($api, $user->getApi());
 }