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'));
 }
 /**
  * Constructeur d'objet Commune.
  *
  * @param Departement $departement Le département de la commune.
  * @param int         $code        Le code INSEE de la commune.
  * @param string      $nom         Le nom de la commune.
  */
 public function __construct(Departement $departement, $code, $nom)
 {
     \Assert\that((string) $code)->maxLength(10);
     \Assert\that($nom)->string()->maxLength(255, 'Le nom de la commune ne peut dépasser 255 caractères.');
     $this->arrondissements = new ArrayCollection();
     $this->departement = $departement;
     $departement->addCommune($this);
     $this->code = $code;
     $this->nom = $nom;
 }
 public function testHasRegionAndCodeAndNom()
 {
     $pays = new Pays('France');
     $region = new Region($pays, 11, 'Île-de-France');
     $departement = new Departement($region, 92, 'Hauts-de-Seine');
     $this->assertEquals(92, $departement->getCode());
     $this->assertEquals('Hauts-de-Seine', $departement->getNom());
     $this->assertEquals($region, $departement->getRegion());
     $this->assertContains($departement, $region->getDepartements());
 }