public function rollback()
 {
     if ($this->previousDescriptor) {
         $this->rootPackageFile->addTypeDescriptor($this->previousDescriptor);
     } else {
         $this->rootPackageFile->removeTypeDescriptor($this->typeDescriptor->getName());
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     // sanity check
     if ($this->typeDescriptor->isLoaded() || !$this->containingModule) {
         return;
     }
     // never fails with the check before
     $this->typeDescriptor->load($this->containingModule);
     if ($this->wasRemoved) {
         // never fails
         $this->typeDescriptors->add($this->typeDescriptor);
     }
 }
 public function testWritePackageFileWritesDefaultParameterValuesOfBindings()
 {
     $packageFile = new PackageFile();
     $package = new Package($packageFile, '/path', new InstallInfo('vendor/package', '/path'));
     // We need to create a type and a binding in state ENABLED
     $bindingType = new BindingTypeDescriptor('my/type', null, array(new BindingParameterDescriptor('param', BindingParameterDescriptor::OPTIONAL, 'default')));
     $bindingType->load($package);
     $binding = new BindingDescriptor('/app/config*.yml', 'my/type', array(), 'glob', Uuid::fromString(self::BINDING_UUID1));
     $binding->load($package, $bindingType);
     // The default value is accessible
     $this->assertSame('default', $binding->getParameterValue('param'));
     // But not written by the writer
     $packageFile->addBindingDescriptor($binding);
     $this->writer->writePackageFile($packageFile, $this->tempFile);
     $this->assertFileExists($this->tempFile);
     $this->assertJsonFileEquals(__DIR__ . '/Fixtures/json/binding-no-default-params.json', $this->tempFile);
 }
 public function testRemoveRootAssetMapping()
 {
     $uuid = $this->binding1->getUuid();
     $this->bindingType->load($this->rootPackage);
     $this->binding1->load($this->rootPackage, $this->bindingType);
     $this->discoveryManager->expects($this->at(0))->method('removeRootBindings')->with($this->uuid($uuid));
     $this->manager->removeRootAssetMapping($uuid);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     // sanity check
     if (!$this->typeDescriptor->isLoaded()) {
         return;
     }
     $typeName = $this->typeDescriptor->getTypeName();
     // never fails with the check before
     $this->typeDescriptor->unload();
     if ($this->previousDescriptor && $this->previousDescriptor->isLoaded()) {
         // never fails
         $this->typeDescriptors->add($this->previousDescriptor);
     } else {
         // never fails
         $this->typeDescriptors->remove($typeName, $this->containingPackage->getName());
     }
 }
Пример #6
0
 public function testRemoveRootAssetMappingDispatchesEvent()
 {
     $uuid = $this->binding1->getUuid();
     $mapping = new AssetMapping('/path', 'target1', '/css', $uuid);
     $event = new RemoveAssetMappingEvent($mapping);
     $this->bindingType->load($this->rootPackage);
     $this->binding1->load($this->rootPackage, $this->bindingType);
     $this->dispatcher->expects($this->any())->method('hasListeners')->with(PuliEvents::POST_REMOVE_ASSET_MAPPING)->willReturn(true);
     $this->dispatcher->expects($this->once())->method('dispatch')->with(PuliEvents::POST_REMOVE_ASSET_MAPPING, $event);
     $this->discoveryManager->expects($this->once())->method('findRootBindings')->with($this->uuid($uuid))->willReturn(array($this->binding1));
     $this->discoveryManager->expects($this->once())->method('removeRootBindings')->with($this->uuid($uuid));
     $this->manager->removeRootAssetMapping($uuid);
 }
Пример #7
0
 private function refreshState()
 {
     if (null === $this->typeDescriptor || !$this->typeDescriptor->isLoaded()) {
         $this->state = BindingState::TYPE_NOT_FOUND;
     } elseif (!$this->typeDescriptor->isEnabled()) {
         $this->state = BindingState::TYPE_NOT_ENABLED;
     } elseif (count($this->loadErrors) > 0) {
         $this->state = BindingState::INVALID;
     } elseif ($this->containingModule instanceof RootModule) {
         $this->state = BindingState::ENABLED;
     } elseif ($this->containingModule->getInstallInfo()->hasDisabledBindingUuid($this->binding->getUuid())) {
         $this->state = BindingState::DISABLED;
     } else {
         $this->state = BindingState::ENABLED;
     }
 }
Пример #8
0
 private function typesEqual(BindingTypeDescriptor $descriptor1, BindingTypeDescriptor $descriptor2)
 {
     return $descriptor1->getTypeName() === $descriptor2->getTypeName() && $descriptor1->getDescription() === $descriptor2->getDescription() && $descriptor1->getParameterDescriptions() === $descriptor2->getParameterDescriptions() && $descriptor1->getType()->getParameters() === $descriptor2->getType()->getParameters();
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     $this->discovery->unbind($this->bindingDescriptor->getQuery(), $this->bindingDescriptor->getTypeName(), $this->bindingDescriptor->getParameterValues(), $this->bindingDescriptor->getLanguage());
 }
Пример #10
0
 private function refreshState()
 {
     if (null === $this->typeDescriptor || !$this->typeDescriptor->isLoaded()) {
         $this->state = BindingState::TYPE_NOT_FOUND;
     } elseif (!$this->typeDescriptor->isEnabled()) {
         $this->state = BindingState::TYPE_NOT_ENABLED;
     } elseif (count($this->violations) > 0) {
         $this->state = BindingState::INVALID;
     } elseif ($this->containingPackage instanceof RootPackage) {
         $this->state = BindingState::ENABLED;
     } elseif ($this->containingPackage->getInstallInfo()->hasDisabledBindingUuid($this->uuid)) {
         $this->state = BindingState::DISABLED;
     } else {
         $this->state = BindingState::ENABLED;
     }
 }
Пример #11
0
 private function typesEqual(BindingTypeDescriptor $type1, BindingTypeDescriptor $type2)
 {
     if ($type1->getName() !== $type2->getName()) {
         return false;
     }
     if ($type1->getDescription() !== $type2->getDescription()) {
         return false;
     }
     if ($type1->getParameters() != $type2->getParameters()) {
         return false;
     }
     return true;
 }
Пример #12
0
 /**
  * Adds a type descriptor.
  *
  * @param BindingTypeDescriptor $descriptor The type descriptor.
  */
 public function addTypeDescriptor(BindingTypeDescriptor $descriptor)
 {
     $this->typeDescriptors[$descriptor->getName()] = $descriptor;
 }
Пример #13
0
 private function syncTypeName(BindingTypeDescriptor $enabledTypeBefore = null, BindingTypeDescriptor $enabledTypeAfter = null)
 {
     if ($enabledTypeBefore && !$enabledTypeAfter) {
         $this->discovery->removeBindingType($this->typeName);
     } elseif (!$enabledTypeBefore && $enabledTypeAfter) {
         $this->discovery->addBindingType($enabledTypeAfter->getType());
     } elseif ($enabledTypeBefore !== $enabledTypeAfter) {
         $this->discovery->removeBindingType($this->typeName);
         $this->discovery->addBindingType($enabledTypeAfter->getType());
     }
 }
 public function testMatch()
 {
     $type = new BindingTypeDescriptor('vendor/type');
     $type->load($this->package);
     $this->assertFalse($type->match(Expr::same('foobar', BindingTypeDescriptor::NAME)));
     $this->assertTrue($type->match(Expr::same('vendor/type', BindingTypeDescriptor::NAME)));
     $this->assertFalse($type->match(Expr::same('foobar', BindingTypeDescriptor::CONTAINING_PACKAGE)));
     $this->assertTrue($type->match(Expr::same($this->package->getName(), BindingTypeDescriptor::CONTAINING_PACKAGE)));
     $this->assertFalse($type->match(Expr::same(BindingTypeState::DUPLICATE, BindingTypeDescriptor::STATE)));
     $this->assertTrue($type->match(Expr::same(BindingTypeState::ENABLED, BindingTypeDescriptor::STATE)));
 }
Пример #15
0
 /**
  * @expectedException \RuntimeException
  */
 public function testUpdateTypeFailsIfNoChanges()
 {
     $args = self::$updateCommand->parseArgs(new StringArgs('my/type'));
     $typeDescriptor = new BindingTypeDescriptor('my/type');
     $typeDescriptor->load($this->packages->getRootPackage());
     $this->discoveryManager->expects($this->once())->method('getRootBindingType')->with('my/type')->willReturn($typeDescriptor);
     $this->discoveryManager->expects($this->never())->method('addRootBindingType');
     $this->handler->handleUpdate($args);
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     $this->discovery->undefineType($this->typeDescriptor->getName());
 }
Пример #17
0
 private function unloadTypeDescriptor(BindingTypeDescriptor $typeDescriptor)
 {
     $typeName = $typeDescriptor->getName();
     return new InterceptedOperation(new UnloadTypeDescriptor($typeDescriptor, $this->typeDescriptors), array(new UpdateDuplicateMarksForTypeName($typeName, $this->typeDescriptors), new ReloadBindingDescriptorsByTypeName($typeName, $this->bindingDescriptors, $this->typeDescriptors)));
 }
Пример #18
0
 public function testMatch()
 {
     $type = new BindingTypeDescriptor('vendor/type', null, array(new BindingParameterDescriptor('param')));
     $type->load($this->package);
     $uuid = Uuid::fromString('abcdb814-9dad-11d1-80b4-00c04fd430c8');
     $this->package->getInstallInfo()->addEnabledBindingUuid($uuid);
     $binding = new BindingDescriptor('/path', 'vendor/type', array('param' => 'value'), 'glob', $uuid);
     $binding->load($this->package, $type);
     $this->assertFalse($binding->match(Expr::same('foobar', BindingDescriptor::CONTAINING_PACKAGE)));
     $this->assertTrue($binding->match(Expr::same($this->package->getName(), BindingDescriptor::CONTAINING_PACKAGE)));
     $this->assertFalse($binding->match(Expr::same(BindingState::DISABLED, BindingDescriptor::STATE)));
     $this->assertTrue($binding->match(Expr::same(BindingState::ENABLED, BindingDescriptor::STATE)));
     $this->assertFalse($binding->match(Expr::startsWith('abce', BindingDescriptor::UUID)));
     $this->assertTrue($binding->match(Expr::startsWith('abcd', BindingDescriptor::UUID)));
     $this->assertFalse($binding->match(Expr::same('/path/nested', BindingDescriptor::QUERY)));
     $this->assertTrue($binding->match(Expr::same('/path', BindingDescriptor::QUERY)));
     $this->assertFalse($binding->match(Expr::same('xpath', BindingDescriptor::LANGUAGE)));
     $this->assertTrue($binding->match(Expr::same('glob', BindingDescriptor::LANGUAGE)));
     $this->assertFalse($binding->match(Expr::same('vendor/other', BindingDescriptor::TYPE_NAME)));
     $this->assertTrue($binding->match(Expr::same('vendor/type', BindingDescriptor::TYPE_NAME)));
     $this->assertFalse($binding->match(Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key('param', Expr::same('foobar')))));
     $this->assertTrue($binding->match(Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key('param', Expr::same('value')))));
 }
Пример #19
0
    public function testSerializePackageFileWritesDefaultParameterValuesOfBindings()
    {
        $packageFile = new PackageFile();
        $package = new Package($packageFile, '/path', new InstallInfo('vendor/package', '/path'));
        // We need to create a type and a binding in state ENABLED
        $bindingType = new BindingTypeDescriptor('my/type', null, array(new BindingParameterDescriptor('param', BindingParameterDescriptor::OPTIONAL, 'default')));
        $bindingType->load($package);
        $binding = new BindingDescriptor('/app/config*.yml', 'my/type', array(), 'glob', Uuid::fromString(self::BINDING_UUID1));
        $binding->load($package, $bindingType);
        // The default value is accessible
        $this->assertSame('default', $binding->getParameterValue('param'));
        // But not written by the serializer
        $packageFile->addBindingDescriptor($binding);
        $json = <<<JSON
{
    "version": "1.0",
    "bindings": {
        "2438256b-c2f5-4a06-a18f-f79755e027dd": {
            "query": "/app/config*.yml",
            "type": "my/type"
        }
    }
}

JSON;
        $this->assertJsonEquals($json, $this->serializer->serializePackageFile($packageFile));
    }
 public function testBuildDiscoveryOnlyIncludesEnabledBindingsOfInstalledPackages()
 {
     $this->initDefaultManager();
     $this->packageFile1->addBindingDescriptor($binding1 = new BindingDescriptor('/path1', 'my/type'));
     $this->packageFile1->addBindingDescriptor($binding2 = new BindingDescriptor('/path2', 'my/type'));
     $this->packageFile1->addBindingDescriptor($binding3 = new BindingDescriptor('/path3', 'my/type'));
     $this->installInfo1->addEnabledBindingUuid($binding2->getUuid());
     $this->installInfo1->addDisabledBindingUuid($binding3->getUuid());
     $this->packageFile1->addTypeDescriptor($bindingType = new BindingTypeDescriptor('my/type'));
     $this->discovery->expects($this->once())->method('defineType')->with($bindingType->toBindingType());
     $this->discovery->expects($this->once())->method('bind')->with('/path2', 'my/type', array(), 'glob');
     $this->manager->buildDiscovery();
 }
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     $this->discovery->removeBindingType($this->typeDescriptor->getTypeName());
 }