/**
  * {@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 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);
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     // sanity check
     if ($this->typeDescriptor->isLoaded()) {
         return;
     }
     // never fails with the check before
     $this->typeDescriptor->load($this->containingPackage);
     $typeName = $this->typeDescriptor->getTypeName();
     $packageName = $this->containingPackage->getName();
     if ($this->typeDescriptors->contains($typeName, $packageName)) {
         // never fails with the check before
         $this->previousDescriptor = $this->typeDescriptors->get($typeName, $packageName);
     }
     // never fails
     $this->typeDescriptors->add($this->typeDescriptor);
 }
 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);
 }
 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 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)));
 }
Beispiel #7
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);
 }
    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 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')))));
 }