/**
  * {@inheritdoc}
  */
 public function removeTargets(Expression $expr)
 {
     $this->assertTargetsLoaded();
     $previousTargets = $this->targets->toArray();
     $previousData = $this->targetsData;
     $save = false;
     foreach ($this->targets as $target) {
         if ($target->match($expr)) {
             $this->targets->remove($target->getName());
             unset($this->targetsData[$target->getName()]);
             $save = true;
         }
     }
     if (!$save) {
         return;
     }
     try {
         $this->persistTargetsData();
     } catch (Exception $e) {
         $this->targets->replace($previousTargets);
         $this->targetsData = $previousData;
         throw $e;
     }
 }
 public function testReplace()
 {
     $this->collection->add($this->target1);
     $this->collection->replace(array($this->target2, $this->target3));
     $this->assertSame(array('target2' => $this->target2, 'target3' => $this->target3), $this->collection->toArray());
 }