/** * Execute the process of iterating over the custom config and * storing the data within environment variables. * * @throws \RuntimeException */ public function execute() { $applicationRootPath = $this->filesystem->getApplicationRootPath(); $customEnvironmentConfigFilePath = sprintf('%s/.env.%s.php', $applicationRootPath, $this->environment); if ($this->config['customEnvironmentConfigPath'] !== null) { $customEnvironmentConfigPath = rtrim($this->config['customEnvironmentConfigPath'], '/') . '/'; $customEnvironmentConfigFilePath = sprintf('%s/%s.env.%s.php', $applicationRootPath, $customEnvironmentConfigPath, $this->environment); } if (!file_exists($customEnvironmentConfigFilePath)) { throw new \RuntimeException("Could not find configuration file: [{$customEnvironmentConfigFilePath}]"); } $this->process(require $customEnvironmentConfigFilePath); }
/** * Test that an exception is thrown in the event that the application path is not found. * * @param \Envariable\Util\Filesystem $filesystem */ function it_throws_an_exception_as_application_path_not_found(Filesystem $filesystem) { $frontControllerPath = 'path/to/index.php'; $frontControllerContent = <<<FC <?php \$system_path = 'system'; \$renamed_application_folder = 'alternate'; require_once BASEPATH.'core/CodeIgniter.php'; FC; $filesystem->getApplicationRootPath()->willReturn('path/to'); $filesystem->fileGetContents($frontControllerPath)->willReturn($frontControllerContent); $this->setFilesystem($filesystem); $this->shouldThrow(new \RuntimeException('Application path could not be found.'))->duringLocate($frontControllerPath); }
/** * Test that an exception is throw when name already exists within the environment store. * * @param \Envariable\Util\Filesystem $filesystem */ function it_will_throw_exception_when_name_already_exists_within_getenv_environment_store(Filesystem $filesystem) { putenv('SOMEGETENVDUPEDB_HOST=Too late! I got here first.'); $environment = 'getenvdupe'; $filesystem->getApplicationRootPath()->willReturn(__DIR__ . '/Config'); $this->setConfiguration(array('customEnvironmentConfigPath' => null)); $this->setEnvironment($environment); $this->setFilesystem($filesystem); $this->shouldThrow(new \RuntimeException('An environment variable with the name "SOMEGETENVDUPEDB_HOST" already exists. Aborting.'))->duringExecute(); }