/**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->bindingDescriptor->isLoaded() || !$this->containingPackage || !$this->typeDescriptor) {
         return;
     }
     // never fails with the check before, given that the type name of
     // the description/type didn't changed, which is impossible since
     // they're immutable
     $this->bindingDescriptor->load($this->containingPackage, $this->typeDescriptor);
     if ($this->wasRemoved) {
         // never fails
         $this->bindingDescriptors->add($this->bindingDescriptor);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     // sanity check
     if (!$this->bindingDescriptor->isLoaded()) {
         return;
     }
     // never fails with the check before
     $this->bindingDescriptor->unload();
     if ($this->previousDescriptor) {
         // never fails
         $this->bindingDescriptors->add($this->previousDescriptor);
     } else {
         // never fails
         $this->bindingDescriptors->remove($this->bindingDescriptor->getUuid());
     }
 }
 /**
  * Unloads and loads a binding descriptor.
  *
  * The descriptor is remembered and reloaded again in {@link postRollback()}
  * if the intercepted operation needs to be rolled back.
  *
  * @param BindingDescriptor $bindingDescriptor The descriptor to reload.
  */
 protected function reloadBindingDescriptor(BindingDescriptor $bindingDescriptor)
 {
     if (!$bindingDescriptor->isLoaded()) {
         return;
     }
     // Keep backup of containing package before calling unload()
     $containingPackage = $bindingDescriptor->getContainingPackage();
     $typeName = $bindingDescriptor->getTypeName();
     $typeDescriptor = $this->typeDescriptors->getEnabled($typeName);
     // never fails with the check in the beginning
     $bindingDescriptor->unload();
     // never fails after unloading, given that the type name matches
     // (which we can guarantee here)
     $bindingDescriptor->load($containingPackage, $typeDescriptor);
     $this->reloadedDescriptors[] = $bindingDescriptor;
 }
 public function testClearRootBindings()
 {
     $this->initDefaultManager();
     $this->packageFile1->addTypeDescriptor(new BindingTypeDescriptor('my/type', null, array(new BindingParameterDescriptor('param'))));
     $this->rootPackageFile->addBindingDescriptor($binding1 = new BindingDescriptor('/path1', 'my/type', array('param' => 'value1'), 'xpath'));
     $this->rootPackageFile->addBindingDescriptor($binding2 = new BindingDescriptor('/path2', 'my/type', array('param' => 'value2'), 'xpath'));
     $this->discovery->expects($this->at(0))->method('unbind')->with('/path1', 'my/type', array('param' => 'value1'), 'xpath');
     $this->discovery->expects($this->at(1))->method('unbind')->with('/path2', 'my/type', array('param' => 'value2'), 'xpath');
     $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->returnCallback(function (RootPackageFile $rootPackageFile) {
         PHPUnit_Framework_Assert::assertFalse($rootPackageFile->hasBindingDescriptors());
     }));
     $this->manager->clearRootBindings();
     $this->assertFalse($binding1->isLoaded());
     $this->assertFalse($binding2->isLoaded());
 }