-
Notifications
You must be signed in to change notification settings - Fork 397
Add cache to ConfigManager #4570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
demiankatz
merged 3 commits into
vufind-org:dev
from
ThoWagen:pull-request/cache-in-config-manager
Aug 28, 2025
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
module/VuFind/src/VuFindTest/Integration/ConfigTestCase.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Abstract base class for config integration test cases. | ||
| * | ||
| * PHP version 8 | ||
| * | ||
| * Copyright (C) Hebis Verbundzentrale 2025. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| * | ||
| * @category VuFind | ||
| * @package Tests | ||
| * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:testing:unit_tests Wiki | ||
| */ | ||
|
|
||
| namespace VuFindTest\Integration; | ||
|
|
||
| use VuFind\Exception\FileAccess; | ||
| use VuFind\Feature\DirUtilityTrait; | ||
| use VuFindTest\Feature\ConfigRelatedServicesTrait; | ||
| use VuFindTest\Feature\FixtureTrait; | ||
| use VuFindTest\Feature\LiveDetectionTrait; | ||
|
|
||
| /** | ||
| * Abstract base class for config integration test cases. | ||
| * | ||
| * @category VuFind | ||
| * @package Tests | ||
| * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:testing:unit_tests Wiki | ||
| */ | ||
| abstract class ConfigTestCase extends \PHPUnit\Framework\TestCase | ||
| { | ||
| use LiveDetectionTrait; | ||
| use FixtureTrait; | ||
| use DirUtilityTrait; | ||
| use ConfigRelatedServicesTrait; | ||
|
|
||
| /** | ||
| * Path to base configurations | ||
| * | ||
| * @var string | ||
| */ | ||
| protected string $baseDirPath; | ||
|
|
||
| /** | ||
| * Path to local dir configurations | ||
| * | ||
| * @var string | ||
| */ | ||
| protected string $localDirPath; | ||
|
|
||
| /** | ||
| * Setup local dir with fixture. | ||
| * | ||
| * @param string $fixture Fixture to use | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function setUpLocalConfigDir(string $fixture): void | ||
| { | ||
| $fixtureDir = realpath($this->getFixtureDir() . 'configs/' . $fixture); | ||
| $localDirPath = $this->localDirPath; | ||
| if (is_dir($localDirPath)) { | ||
| self::rmDir($localDirPath); | ||
| } | ||
| self::cpDir($fixtureDir, $localDirPath); | ||
| } | ||
|
|
||
| /** | ||
| * Read the current config. | ||
| * | ||
| * @param string $config Config name | ||
| * @param ?string $path Optional alternative path to config directory | ||
| * | ||
| * @return array | ||
| */ | ||
| protected function readConfig(string $config, ?string $path = null): array | ||
| { | ||
| $configFile = ($path ?? $this->localDirPath) . '/' . $config . '.ini'; | ||
| $result = parse_ini_file($configFile, true); | ||
| if ($result === false) { | ||
| throw new FileAccess('Could not read config file: ' . $configFile); | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * Standard setup method. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function setUp(): void | ||
| { | ||
| // Give up if we're not running in CI: | ||
| if (!$this->continuousIntegrationRunning()) { | ||
| $this->markTestSkipped('Continuous integration not running.'); | ||
| return; | ||
| } | ||
|
|
||
| $pathResolver = $this->getPathResolver(); | ||
| $this->baseDirPath = $pathResolver->getBaseConfigDirPath(); | ||
| $this->localDirPath = $pathResolver->getLocalConfigDirPath(); | ||
| if ($this->localDirPath === null) { | ||
| $this->markTestSkipped('No local config dir configured.'); | ||
| } | ||
|
|
||
| // create backup of local config dir | ||
| if (is_dir($this->localDirPath)) { | ||
| $backUpDir = $this->localDirPath . '.bak'; | ||
|
demiankatz marked this conversation as resolved.
Outdated
|
||
| rename($this->localDirPath, $backUpDir); | ||
| mkdir($this->localDirPath); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Standard teardown method. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function tearDown(): void | ||
| { | ||
| // restore backup of local config dir | ||
| $localDirPath = $this->localDirPath; | ||
|
demiankatz marked this conversation as resolved.
Outdated
|
||
| $backUpDir = $localDirPath . '.bak'; | ||
| if (is_dir($localDirPath)) { | ||
| self::rmDir($localDirPath); | ||
| } | ||
| if (is_dir($backUpDir)) { | ||
| rename($backUpDir, $localDirPath); | ||
| } | ||
| } | ||
| } | ||
85 changes: 85 additions & 0 deletions
85
module/VuFind/tests/integration-tests/src/VuFindTest/Config/ConfigManagerIntegrationTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * ConfigManager Integration Test Class | ||
| * | ||
| * PHP version 8 | ||
| * | ||
| * Copyright (C) Hebis Verbundzentrale 2025. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| * | ||
| * @category VuFind | ||
| * @package Tests | ||
| * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:testing:unit_tests Wiki | ||
| */ | ||
|
|
||
| namespace VuFindTest\Config; | ||
|
|
||
| use VuFind\Config\ConfigManager; | ||
| use VuFindTest\Integration\ConfigTestCase; | ||
|
|
||
| /** | ||
| * ConfigManager Integration Test Class | ||
| * | ||
| * @category VuFind | ||
| * @package Tests | ||
| * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:testing:unit_tests Wiki | ||
| */ | ||
| class ConfigManagerIntegrationTest extends ConfigTestCase | ||
| { | ||
| /** | ||
| * Test caching. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function testCaching(): void | ||
| { | ||
| $container = $this->getContainerWithConfigRelatedServices(); | ||
| $configManager = $container->get(ConfigManager::class); | ||
|
demiankatz marked this conversation as resolved.
Outdated
|
||
| $this->setUpLocalConfigDir('defaultgenerator'); | ||
| $config = $configManager->getConfig('config'); | ||
| $this->assertEquals('VuFind 1.0', $config['Site']['generator']); | ||
| // check that the cache is used and the change in the config files is ignored | ||
| $this->setUpLocalConfigDir('customgenerator'); | ||
| $config = $configManager->getConfig('config'); | ||
| $this->assertEquals('VuFind 1.0', $config['Site']['generator']); | ||
| // check that the cache is ignored | ||
| $config = $configManager->getConfig('config', forceReload: true); | ||
| $this->assertEquals('Custom Generator', $config['Site']['generator']); | ||
| } | ||
|
|
||
| /** | ||
| * Test the userLocalConfig parameter. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function testUseLocalConfigParameter(): void | ||
| { | ||
| $container = $this->getContainerWithConfigRelatedServices( | ||
| baseDir: $this->getFixtureDir() . 'configs/defaultgenerator', | ||
| baseSubDir: '' | ||
| ); | ||
| $this->setUpLocalConfigDir('customgenerator'); | ||
| $configManager = $container->get(ConfigManager::class); | ||
| $config = $configManager->getConfig('config'); | ||
| $this->assertEquals('Custom Generator', $config['Site']['generator']); | ||
| $config = $configManager->getConfig('config', useLocalConfig: false); | ||
| $this->assertEquals('VuFind 1.0', $config['Site']['generator']); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.