/** * @expectedException \AppBundle\Service\ValidationException * @expectedExceptionCode \AppBundle\Service\ValidationException::EMPTY_DATE_NAISSANCE */ public function testCommit_dateNaissance_empty() { // Simulation d'une page animal en base de données $user = new User(); $pageAnimalBranch = new PageAnimalBranch(); $pageAnimalBranch->setOwner($user); $commit = new PageAnimalCommit(null, 'rodolf', $this->timeService->now(), null, PageAnimal::DISPONIBLE, PageAnimal::MALE, null); $commit->setId(1); $pageAnimalBranch->setCommit($commit); $this->pageAnimalBranchRepository->method('find')->willReturn($pageAnimalBranch); $this->pageAnimalCommitRepository->method('find')->with($commit->getId())->willReturn($commit); // Commit la page avec un nom vide $pageAnimal = $this->pageAnimalService->find($pageAnimalBranch->getId()); $pageAnimal->setDateNaissance(null); $this->pageAnimalService->commit($user, $pageAnimal); }
/** * @Route("/animal/{pageAnimalId}", name="commitPageAnimal_route") * @Method("POST") * @return \Symfony\Component\HttpFoundation\Response */ public function commitAction($pageAnimalId, Request $request) { /** @var PageAnimal $pageEleveur */ $pageAnimal = $this->serializer->deserialize($request->getContent(), PageAnimal::class, 'json'); /** @var AnonymousToken $token */ $token = $this->tokenStorage->getToken(); /** @var User $user */ $user = $token->getUser(); if ($user === 'anon.') { return new RedirectResponse($this->router->generate('fos_user_security_login')); } try { $this->pageAnimalService->commit($user, $pageAnimal); return new Response($this->serializer->serialize($pageAnimal, 'json')); } catch (HistoryException $e) { return $this->createHistoryErrorResponse($e, $user, $pageAnimal); } catch (ValidationException $e) { return $this->createValidationErrorResponse($e, $user, $pageAnimal); } }