public function testSaveConfigFileGeneratesFactoryIfManagerAvailable() { $configFile = new ConfigFile('/path'); $factoryManager = $this->getMock('Puli\\Manager\\Api\\Factory\\FactoryManager'); $storage = new ConfigFileStorage($this->backend, $this->serializer, $factoryManager); $factoryManager->expects($this->once())->method('autoGenerateFactoryClass'); $storage->saveConfigFile($configFile); }
public function testClearConfigKeysRevertsIfSavingNotPossible() { $this->configFile->getConfig()->set(Config::PULI_DIR, 'my-puli-dir'); $this->configFileStorage->expects($this->once())->method('saveConfigFile')->willThrowException(new TestException()); try { $this->manager->clearConfigKeys(); $this->fail('Expected a TestException'); } catch (TestException $e) { } $this->assertTrue($this->configFile->getConfig()->contains(Config::PULI_DIR)); $this->assertFalse($this->configFile->getConfig()->contains(Config::FACTORY_IN_FILE)); $this->assertSame('my-puli-dir', $this->configFile->getConfig()->get(Config::PULI_DIR)); }
/** * {@inheritdoc} */ protected function saveConfigFile() { $this->configFileStorage->saveConfigFile($this->configFile); }
private function loadConfigFile($homeDir, Config $baseConfig) { if (null === $homeDir) { return null; } Assert::fileExists($homeDir, 'Could not load Puli context: The home directory %s does not exist.'); Assert::directory($homeDir, 'Could not load Puli context: The home directory %s is a file. Expected a directory.'); // Create a storage without the factory manager $configStorage = new ConfigFileStorage($this->getStorage(), $this->getConfigFileSerializer()); $configPath = Path::canonicalize($homeDir) . '/config.json'; try { return $configStorage->loadConfigFile($configPath, $baseConfig); } catch (FileNotFoundException $e) { // It's ok if no config.json exists. We'll work with // DefaultConfig instead return null; } }
/** * 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.'); $homeDir = self::parseHomeDirectory(); if (null !== $homeDir) { Assert::fileExists($homeDir, 'Could not load Puli context: The home directory %s does not exist.'); Assert::directory($homeDir, 'Could not load Puli context: The home directory %s is a file. Expected a directory.'); // Create a storage without the factory manager $configStorage = new ConfigFileStorage($this->getStorage(), $this->getConfigFileSerializer()); $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->getStorage(), $this->getPackageFileSerializer()); $rootDir = Path::canonicalize($rootDir); $rootFilePath = $this->rootDir . '/puli.json'; $rootPackageFile = $packageFileStorage->loadRootPackageFile($rootFilePath, $baseConfig); $config = new EnvConfig($rootPackageFile->getConfig()); return new ProjectContext($homeDir, $rootDir, $config, $rootPackageFile, $configFile, $this->dispatcher, $env); }