public function testArrayAccess()
 {
     $this->collection[] = $this->target1;
     $this->collection[] = $this->target2;
     $this->assertSame(array('target1' => $this->target1, 'target2' => $this->target2), $this->collection->toArray());
     $this->assertSame($this->target1, $this->collection['target1']);
     $this->assertSame($this->target2, $this->collection['target2']);
     $this->assertTrue(isset($this->collection['target1']));
     $this->assertFalse(isset($this->collection['foobar']));
     unset($this->collection['target2']);
     unset($this->collection['foobar']);
     $this->assertSame(array('target1' => $this->target1), $this->collection->toArray());
 }
 /**
  * {@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;
     }
 }