/** * Add a Province to a Zone * * @param ZoneInterface $zone Zone * @param ProvinceInterface $province Province * * @return $this self Object */ public function addProvinceToZone(ZoneInterface $zone, ProvinceInterface $province) { $zoneHasProvince = $this->zoneMatcher->isProvinceContainedInZone($zone, $province); if (!$zoneHasProvince) { $zoneProvinceMember = new $this->zoneProvinceMemberNamespace($zone, $province); $zone->addMember($zoneProvinceMember); $this->zoneMemberObjectManager->persist($zoneProvinceMember); $this->zoneMemberObjectManager->flush($zoneProvinceMember); } return $this; }
/** * Test add existing-already province */ public function testAddProvinceInZoneExistingProvince() { $existingProvince = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ProvinceInterface'); $anotherExistingProvince = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ProvinceInterface'); $province = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ProvinceInterface'); $province->expects($this->any())->method('equals')->will($this->returnCallback(function (ProvinceInterface $province) use($existingProvince) { return $province === $existingProvince; })); $zone = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ZoneInterface'); $zone->expects($this->any())->method('getMembers')->will($this->returnValue(new ArrayCollection([new ZoneProvinceMember($zone, $existingProvince), new ZoneProvinceMember($zone, $anotherExistingProvince)]))); $isProvinceContainedInZone = $this->zoneMatcher->isProvinceContainedInZone($zone, $province); $this->assertTrue($isProvinceContainedInZone); }