Пример #1
0
 /**
  * Add a State in to Zone
  *
  * @param ZoneInterface  $zone  Zone
  * @param StateInterface $state State
  *
  * @return $this self Object
  */
 public function addStateToZone(ZoneInterface $zone, StateInterface $state)
 {
     $zoneHasState = $this->zoneMatcher->isStateContainedInZone($zone, $state);
     if (!$zoneHasState) {
         $zoneStateMember = new $this->zoneStateMemberNamespace($zone, $state);
         $zone->addMember($zoneStateMember);
         $this->zoneMemberObjectManager->persist($zoneStateMember);
         $this->zoneMemberObjectManager->flush($zoneStateMember);
     }
     return $this;
 }
Пример #2
0
 /**
  * Test add existing-already state
  */
 public function testAddStateInZoneExistingState()
 {
     $existingState = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\StateInterface');
     $anotherExistingState = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\StateInterface');
     $state = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\StateInterface');
     $state->expects($this->any())->method('equals')->will($this->returnCallback(function (StateInterface $state) use($existingState) {
         return $state === $existingState;
     }));
     $zone = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ZoneInterface');
     $zone->expects($this->any())->method('getMembers')->will($this->returnValue(new ArrayCollection([new ZoneStateMember($zone, $existingState), new ZoneStateMember($zone, $anotherExistingState)])));
     $isStateContainedInZone = $this->zoneMatcher->isStateContainedInZone($zone, $state);
     $this->assertTrue($isStateContainedInZone);
 }