Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 public function testMappingBranchToModel()
 {
     // Mock d'une page eleveur en base de données
     $user = new User();
     $user->setId(1);
     $pageEleveurBranch = new PageEleveurBranch();
     $pageEleveurBranch->setId(1);
     $pageEleveurBranch->setOwner($user);
     $this->pageEleveurBranchRepository->method('findBySlug')->withAnyParameters()->willReturn($pageEleveurBranch);
     $pageAnimal = new PageAnimalBranch();
     $photo = new Photo();
     $photo->setNom('portrait');
     $pageAnimal->setCommit(new PageAnimalCommit(null, 'bobi', null, '', PageAnimal::DISPONIBLE, PageAnimal::MALE, [$photo]));
     $commit = new PageEleveurCommit(null, 'Tatouine', 'Plein de chartreux', 'Chats', 'Chartreux', 'Roubaix', [$pageAnimal], [new Actualite('Nouvelle portée', new \DateTime())]);
     $pageEleveurBranch->setCommit($commit);
     $this->pageEleveurCommitRepository->method('find')->with($commit->getId())->willReturn($commit);
     // requete cliente par le slug
     $pageEleveur = $this->pageEleveurService->findBySlug('');
     // l'objet PageEleveur est bien rempli
     $this->assertEquals('Tatouine', $pageEleveur->getNom());
     $this->assertEquals('Plein de chartreux', $pageEleveur->getDescription());
     $this->assertEquals('Chats', $pageEleveur->getEspeces());
     $this->assertEquals('Chartreux', $pageEleveur->getRaces());
     $this->assertEquals('Roubaix', $pageEleveur->getLieu());
     $this->assertEquals('Nouvelle portée', $pageEleveur->getActualites()[0]->getContenu());
     $this->assertEquals('portrait', $pageEleveur->getAnimaux()[0]->getPhotos()[0]->getNom());
 }
Ejemplo n.º 3
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);
 }