Пример #1
0
 /**
  * Add a City to a Zone
  *
  * @param ZoneInterface $zone Zone
  * @param CityInterface $city City
  *
  * @return $this self Object
  */
 public function addCityToZone(ZoneInterface $zone, CityInterface $city)
 {
     $zoneHasCity = $this->zoneMatcher->isCityContainedInZone($zone, $city);
     if (!$zoneHasCity) {
         $zoneCityMember = new $this->zoneCityMemberNamespace($zone, $city);
         $zone->addMember($zoneCityMember);
         $this->zoneMemberObjectManager->persist($zoneCityMember);
         $this->zoneMemberObjectManager->flush($zoneCityMember);
     }
     return $this;
 }
Пример #2
0
 /**
  * Test add existing-already city
  */
 public function testAddCityInZoneExistingCity()
 {
     $existingCity = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\CityInterface');
     $anotherExistingCity = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\CityInterface');
     $city = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\CityInterface');
     $city->expects($this->any())->method('equals')->will($this->returnCallback(function (CityInterface $city) use($existingCity) {
         return $city === $existingCity;
     }));
     $zone = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ZoneInterface');
     $zone->expects($this->any())->method('getMembers')->will($this->returnValue(new ArrayCollection([new ZoneCityMember($zone, $existingCity), new ZoneCityMember($zone, $anotherExistingCity)])));
     $isCityContainedInZone = $this->zoneMatcher->isCityContainedInZone($zone, $city);
     $this->assertTrue($isCityContainedInZone);
 }