コード例 #1
0
 /**
  * @param User $owner
  * @return PageAnimal
  * @throws HistoryException
  */
 public function create(User $owner)
 {
     $pageAnimalBranch = new PageAnimalBranch();
     $pageAnimalBranch->setOwner($owner);
     $noms = file($this->fileLocator->locate('@AppBundle/Resources/noms-animaux/noms.txt'));
     $nom = trim($noms[rand(0, count($noms) - 1)]);
     $pageAnimalBranch->setCommit(new PageAnimalCommit(null, $nom, $this->timeService->now(), null, PageAnimal::DISPONIBLE, PageAnimal::MALE, null));
     $this->doctrine->persist($pageAnimalBranch->getCommit());
     $this->doctrine->persist($pageAnimalBranch);
     $this->doctrine->flush([$pageAnimalBranch->getCommit(), $pageAnimalBranch]);
     return self::fromBranch($pageAnimalBranch);
 }
コード例 #2
0
 /**
  * @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);
 }