public function testAddGetRemove()
 {
     $pays = $this->repository->getPays();
     $region = new Region($pays, 82, 'Rhône-Alpes');
     $departement = new Departement($region, 38, 'Isère');
     $commune = new Commune($departement, 'ZE', 'Grenoble');
     $arrondissementCommunal = new ArrondissementCommunal($commune, 'ZE', 'Test');
     $circonscriptionLeg = new CirconscriptionLegislative($departement, 2);
     $circonscriptionEur = new CirconscriptionEuropeenne($pays, 1, 'Sud-Ouest');
     $this->repository->add($arrondissementCommunal);
     $this->repository->add($circonscriptionLeg);
     $this->repository->add($circonscriptionEur);
     $this->repository->save();
     // L'id peut avoir changer donc on teste juste le nom.
     $this->assertEquals($region->getNom(), $this->repository->getRegion(82)->getNom());
     $this->assertEquals($departement->getNom(), $this->repository->getDepartement(38)->getNom());
     $this->assertEquals($commune->getNom(), $this->repository->getCommune(38, 'ZE')->getNom());
     $this->assertEquals($arrondissementCommunal->getNom(), $this->repository->getArrondissementCommunal($commune, 'ZE')->getNom());
     $this->assertEquals($circonscriptionLeg->getCode(), $this->repository->getCirconscriptionLegislative(38, 2)->getCode());
     $this->assertEquals($circonscriptionEur->getNom(), $this->repository->getCirconscriptionEuropeenne('Sud-Ouest')->getNom());
     $this->assertEquals($circonscriptionEur->getNom(), $this->repository->getCirconscriptionEuropeenne(1)->getNom());
     $this->assertEquals('France', $this->repository->getPays()->getNom());
     // On teste remove
     $this->repository->remove($this->repository->getRegion(82));
     $this->repository->save();
     // Si on utilise assertNull, en cas d'échec du test, phpUnit fait un
     // var_dump ce qui pose problème lorsqu'il y a des associations
     // d'entités cycliques.
     $this->assertTrue(null === $this->repository->getRegion(82));
     $this->assertTrue(null === $this->repository->getDepartement(38));
     $this->assertTrue(null === $this->repository->getCommune(38, 'ZE'));
     $this->assertTrue(null === $this->repository->getArrondissementCommunal($commune, 'ZE'));
 }
Ejemplo n.º 2
0
 public function testHasCodeAndNomAndPays()
 {
     $pays = new Pays('France');
     $region = new Region($pays, 11, 'Île-de-France');
     $this->assertEquals(11, $region->getCode());
     $this->assertEquals('Île-de-France', $region->getNom());
     $this->assertEquals($pays, $region->getPays());
 }
 /**
  * Constructeur d'objet département.
  *
  * @param Region $region La région du département.
  * @param string $code   Le code du département.
  * @param string $nom    Le nom du département.
  */
 public function __construct(Region $region, $code, $nom)
 {
     \Assert\that((string) $code)->string()->maxLength(4, 'Le code du département ne peut dépasser 4 caractères.');
     \Assert\that($nom)->string()->maxLength(255, 'Le nom du déparement de peut dépasser 255 caractères.');
     $this->code = (string) $code;
     $this->nom = $nom;
     $this->region = $region;
     $region->addDepartement($this);
     $this->communes = new ArrayCollection();
     $this->circonscriptionsLegislatives = new ArrayCollection();
 }
 public function testSetSurCircoAndGetHigherScore()
 {
     $date = new \DateTime();
     $echeance = new Echeance($date, Echeance::CANTONALES);
     $pays = new Pays();
     $region = new Region($pays, 11, 'Île-de-France');
     $circoEuro = new CirconscriptionEuropeenne($pays, 1, 'Test');
     $region->setCirconscriptionEuropeenne($circoEuro);
     $circoEuro->addRegion($region);
     $departement = new Departement($region, 93, 'Seine-Saint-Denis');
     $departement2 = new Departement($region, 92, 'Hauts-de-Seine');
     $commune2 = new Commune($departement2, 20, 'Jesaispas');
     $this->territoireRepository->add($departement);
     $this->territoireRepository->add($commune2);
     $this->territoireRepository->add($region);
     $this->territoireRepository->add($circoEuro);
     $election = new ElectionUninominale($echeance, $departement);
     $election2 = new ElectionUninominale($echeance, $commune2);
     $candidat = new PersonneCandidate($election, 'FG', 'Naël', 'Ferret');
     $election->addCandidat($candidat);
     $candidat2 = new PersonneCandidate($election2, 'PG', 'Lea', 'Ferret');
     $election2->addCandidat($candidat2);
     $candidat3 = new PersonneCandidate($election2, 'FG', 'Leo', 'Ferret');
     $election2->addCandidat($candidat3);
     $voteInfo1 = new VoteInfo(1000, 900, 800);
     $election->setVoteInfo($voteInfo1);
     $voteInfo2 = new VoteInfo(100, 90, 80);
     $election2->setVoteInfo($voteInfo2);
     $election->setVoixCandidat(400, $candidat);
     $election2->setVoixCandidat(50, $candidat2);
     $election2->setVoixCandidat(10, $candidat3);
     $this->electionRepository->add($election);
     $this->electionRepository->add($election2);
     $this->electionRepository->save();
     $score = $this->electionRepository->getScore($echeance, $region, array($candidat, $candidat2, $candidat3));
     $scoreEuro = $this->electionRepository->getScore($echeance, $circoEuro, array($candidat, $candidat2, $candidat3));
     $this->assertEquals($score, $scoreEuro);
     $this->assertEquals(460, $score->toVoix());
     $this->assertTrue(abs(52.27 - $score->toPourcentage()) < 0.01);
     $score = $this->electionRepository->getScore($echeance, $region, new CandidatNuanceSpecification(array('FG', 'PG')));
     $scoreEuro = $this->electionRepository->getScore($echeance, $circoEuro, new CandidatNuanceSpecification(array('FG', 'PG')));
     $pays = $this->territoireRepository->getPays();
     $scorePays = $this->electionRepository->getScore($echeance, $pays, new CandidatNuanceSpecification(array('FG', 'PG')));
     $this->assertEquals($score, $scoreEuro);
     $this->assertEquals($score, $scorePays);
     $this->assertEquals(460, $score->toVoix());
     $this->assertTrue(abs(52.27 - $score->toPourcentage()) < 0.01);
 }