/** * Test add existing-already country */ public function testAddCountryInZoneExistingCountry() { $existingCountry = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\CountryInterface'); $anotherExistingCountry = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\CountryInterface'); $country = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\CountryInterface'); $country->expects($this->any())->method('equals')->will($this->returnCallback(function (CountryInterface $country) use($existingCountry) { return $country === $existingCountry; })); $zone = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ZoneInterface'); $zone->expects($this->any())->method('getMembers')->will($this->returnValue(new ArrayCollection([new ZoneCountryMember($zone, $existingCountry), new ZoneCountryMember($zone, $anotherExistingCountry)]))); $isCountryContainedInZone = $this->zoneMatcher->isCountryContainedInZone($zone, $country); $this->assertTrue($isCountryContainedInZone); }
/** * Add a Country to a Zone * * @param ZoneInterface $zone Zone * @param CountryInterface $country Country * * @return $this self Object */ public function addCountryToZone(ZoneInterface $zone, CountryInterface $country) { $zoneHasCountry = $this->zoneMatcher->isCountryContainedInZone($zone, $country); if (!$zoneHasCountry) { $zoneCountryMember = new $this->zoneCountryMemberNamespace($zone, $country); $zone->addMember($zoneCountryMember); $this->zoneMemberObjectManager->persist($zoneCountryMember); $this->zoneMemberObjectManager->flush($zoneCountryMember); } return $this; }