public function testClearExtraKeyRestoresValuesIfSavingFails() { $this->rootPackageFile->setExtraKey('key1', 'value1'); $this->rootPackageFile->setExtraKey('key2', 'value2'); $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->throwException(new TestException())); try { $this->manager->clearExtraKeys(); $this->fail('Expected a TestException'); } catch (TestException $e) { } $this->assertSame('value1', $this->rootPackageFile->getExtraKey('key1')); $this->assertSame('value2', $this->rootPackageFile->getExtraKey('key2')); }
public function testClearRootPathMappings() { $this->initDefaultManager(); $this->repo->expects($this->at(0))->method('remove')->with('/app1'); $this->repo->expects($this->at(1))->method('remove')->with('/app2'); $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->returnCallback(function (RootPackageFile $rootPackageFile) { PHPUnit_Framework_Assert::assertFalse($rootPackageFile->hasPathMappings()); })); $this->rootPackageFile->addPathMapping($mapping1 = new PathMapping('/app1', 'resources')); $this->rootPackageFile->addPathMapping($mapping2 = new PathMapping('/app2', 'resources')); $this->manager->clearRootPathMappings(); $this->assertFalse($mapping1->isLoaded()); $this->assertFalse($mapping2->isLoaded()); }
public function testClearPackages() { $this->initDefaultManager(); $packageDir = $this->packageDir1; $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->returnCallback(function (RootPackageFile $rootPackageFile) use($packageDir) { PHPUnit_Framework_Assert::assertFalse($rootPackageFile->hasInstallInfos()); })); $this->assertTrue($this->rootPackageFile->hasInstallInfo('vendor/package1')); $this->assertTrue($this->rootPackageFile->hasInstallInfo('vendor/package2')); $this->assertTrue($this->manager->hasPackage('vendor/root')); $this->assertTrue($this->manager->hasPackage('vendor/package1')); $this->assertTrue($this->manager->hasPackage('vendor/package2')); $this->manager->clearPackages(); $this->assertFalse($this->rootPackageFile->hasInstallInfos()); $this->assertCount(1, $this->manager->getPackages()); $this->assertTrue($this->manager->hasPackage('vendor/root')); }
public function testDisableBindingRestoresEnabledBindingsIfSavingFails() { $this->initDefaultManager(); $this->packageFile1->addTypeDescriptor(new BindingTypeDescriptor('my/type', null, array(new BindingParameterDescriptor('param')))); $this->packageFile1->addBindingDescriptor($binding = new BindingDescriptor('/path', 'my/type', array('param' => 'value'), 'xpath')); $this->installInfo1->addEnabledBindingUuid($binding->getUuid()); $this->discovery->expects($this->once())->method('unbind')->with('/path', 'my/type', array('param' => 'value'), 'xpath'); $this->discovery->expects($this->once())->method('bind')->with('/path', 'my/type', array('param' => 'value'), 'xpath'); $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->willThrowException(new TestException('Some exception')); try { $this->manager->disableBinding($binding->getUuid()); $this->fail('Expected an exception'); } catch (TestException $e) { } $this->assertSame(array(), $this->installInfo1->getDisabledBindingUuids()); $this->assertSame(array($binding->getUuid()), $this->installInfo1->getEnabledBindingUuids()); }