public function testSaveRootPackageFileGeneratesFactoryIfManagerAvailable()
 {
     $baseConfig = new Config();
     $packageFile = new RootPackageFile(null, '/path', $baseConfig);
     $factoryManager = $this->getMock('Puli\\Manager\\Api\\Factory\\FactoryManager');
     $storage = new PackageFileStorage($this->reader, $this->writer, $factoryManager);
     $factoryManager->expects($this->once())->method('autoGenerateFactoryClass');
     $storage->saveRootPackageFile($packageFile);
 }
 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());
 }
Пример #4
0
 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'));
 }
Пример #5
0
 private function renameNonRootPackage(Package $package, $newName)
 {
     $previousInstallInfo = $package->getInstallInfo();
     $installInfo = new InstallInfo($newName, $previousInstallInfo->getInstallPath());
     $installInfo->setInstallerName($previousInstallInfo->getInstallerName());
     foreach ($previousInstallInfo->getDisabledBindingUuids() as $uuid) {
         $installInfo->addDisabledBindingUuid($uuid);
     }
     $this->rootPackageFile->removeInstallInfo($package->getName());
     $this->rootPackageFile->addInstallInfo($installInfo);
     try {
         $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
     } catch (Exception $e) {
         $this->rootPackageFile->removeInstallInfo($newName);
         $this->rootPackageFile->addInstallInfo($previousInstallInfo);
         throw $e;
     }
     $this->packages->remove($package->getName());
     $this->packages->add(new Package($package->getPackageFile(), $package->getInstallPath(), $installInfo, $package->getLoadErrors()));
 }
Пример #6
0
 private function saveRootPackageFile()
 {
     $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 protected function saveConfigFile()
 {
     $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
 }
Пример #8
0
 /**
  * Creates the context of a Puli project.
  *
  * The home directory is read from the context variable "PULI_HOME".
  * If this variable is not set, the home directory defaults to:
  *
  *  * `$HOME/.puli` on Linux, where `$HOME` is the context variable
  *    "HOME".
  *  * `$APPDATA/Puli` on Windows, where `$APPDATA` is the context
  *    variable "APPDATA".
  *
  * If none of these variables can be found, an exception is thrown.
  *
  * A .htaccess file is put into the home directory to protect it from web
  * access.
  *
  * @param string $rootDir The path to the project.
  *
  * @return ProjectContext The project context.
  */
 private function createProjectContext($rootDir, $env)
 {
     Assert::fileExists($rootDir, 'Could not load Puli context: The root %s does not exist.');
     Assert::directory($rootDir, 'Could not load Puli context: The root %s is a file. Expected a directory.');
     $baseConfig = new DefaultConfig();
     $homeDir = self::parseHomeDirectory();
     if (null !== ($configFile = $this->loadConfigFile($homeDir, $baseConfig))) {
         $baseConfig = $configFile->getConfig();
     }
     // Create a storage without the factory manager
     $packageFileStorage = new PackageFileStorage($this->getStorage(), $this->getPackageFileSerializer());
     $rootDir = Path::canonicalize($rootDir);
     $rootFilePath = $this->rootDir . '/puli.json';
     try {
         $rootPackageFile = $packageFileStorage->loadRootPackageFile($rootFilePath, $baseConfig);
     } catch (FileNotFoundException $e) {
         $rootPackageFile = new RootPackageFile(null, $rootFilePath, $baseConfig);
     }
     $config = new EnvConfig($rootPackageFile->getConfig());
     return new ProjectContext($homeDir, $rootDir, $config, $rootPackageFile, $configFile, $this->dispatcher, $env);
 }
 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());
 }
Пример #10
0
 /**
  * Creates the environment of a Puli project.
  *
  * The home directory is read from the environment variable "PULI_HOME".
  * If this variable is not set, the home directory defaults to:
  *
  *  * `$HOME/.puli` on Linux, where `$HOME` is the environment variable
  *    "HOME".
  *  * `$APPDATA/Puli` on Windows, where `$APPDATA` is the environment
  *    variable "APPDATA".
  *
  * If none of these variables can be found, an exception is thrown.
  *
  * A .htaccess file is put into the home directory to protect it from web
  * access.
  *
  * @param string $rootDir The path to the project.
  *
  * @return ProjectEnvironment The project environment.
  */
 private function createProjectEnvironment($rootDir)
 {
     Assert::fileExists($rootDir, 'Could not load Puli environment: The root %s does not exist.');
     Assert::directory($rootDir, 'Could not load Puli environment: The root %s is a file. Expected a directory.');
     $homeDir = self::parseHomeDirectory();
     if (null !== $homeDir) {
         Assert::fileExists($homeDir, 'Could not load Puli environment: The home directory %s does not exist.');
         Assert::directory($homeDir, 'Could not load Puli environment: The home directory %s is a file. Expected a directory.');
         // Create a storage without the factory manager
         $configStorage = new ConfigFileStorage($this->getConfigFileReader(), $this->getConfigFileWriter());
         $configPath = Path::canonicalize($homeDir) . '/config.json';
         $configFile = $configStorage->loadConfigFile($configPath, new DefaultConfig());
         $baseConfig = $configFile->getConfig();
     } else {
         $configFile = null;
         $baseConfig = new DefaultConfig();
     }
     // Create a storage without the factory manager
     $packageFileStorage = new PackageFileStorage($this->getPackageFileReader(), $this->getPackageFileWriter());
     $rootDir = Path::canonicalize($rootDir);
     $rootFilePath = $this->rootDir . '/puli.json';
     $rootPackageFile = $packageFileStorage->loadRootPackageFile($rootFilePath, $baseConfig);
     $config = new EnvConfig($rootPackageFile->getConfig());
     return new ProjectEnvironment($homeDir, $rootDir, $config, $rootPackageFile, $configFile, $this->dispatcher);
 }