nochmal nue

This commit is contained in:
lubiana 2025-06-09 22:05:01 +02:00
parent 2c2e34b71e
commit 6f07d70436
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
27 changed files with 311 additions and 1988 deletions

View file

@ -6,142 +6,52 @@ use App\Entity\SystemConfig;
use App\Enum\SystemSettingKey;
use App\Service\ConfigurationService;
test('getAllConfigs returns all configurations', function (): void {
// Arrange
$configService = $this->getContainer()->get(ConfigurationService::class);
// Act
$configs = $configService->getAllConfigs();
// Assert
expect($configs)->toBeArray();
});
test('getConfigValue returns correct value', function (): void {
test('get returns correct value', function (): void {
// Arrange
/** @var ConfigurationService $configService */
$configService = $this->getContainer()->get(ConfigurationService::class);
$key = SystemSettingKey::SYSTEM_NAME;
$expectedValue = SystemSettingKey::getDefaultValue($key);
// Act
$value = $configService->getConfigValue($key);
$value = $configService->get($key);
// Assert
expect($value)->toBe($expectedValue);
expect($value)->toBe($key->defaultValue());
});
test('setConfigValue updates configuration value', function (): void {
// Arrange
/** @var ConfigurationService $configService */
$configService = $this->getContainer()->get(ConfigurationService::class);
$key = SystemSettingKey::SYSTEM_NAME;
$newValue = 'Test System Name';
// Act
$configService->setConfigValue($key, $newValue);
$value = $configService->getConfigValue($key);
$configService->set($key, $newValue);
$value = $configService->get($key);
// Assert
expect($value)->toBe($newValue);
});
test('getConfigByKey returns correct config', function (): void {
// Arrange
$configService = $this->getContainer()->get(ConfigurationService::class);
$key = SystemSettingKey::SYSTEM_NAME;
// Act
$config = $configService->getConfigByKey($key);
// Assert
expect($config)->toBeInstanceOf(SystemConfig::class)
->and($config->getKey())->toBe($key);
});
test('createConfig throws exception when config already exists', function (): void {
// Arrange
$configService = $this->getContainer()->get(ConfigurationService::class);
$key = SystemSettingKey::SYSTEM_NAME;
$value = 'Test System Name';
// Ensure config exists
$configService->setConfigValue($key, $value);
// Act & Assert
expect(fn() => $configService->createConfig($key, $value))
->toThrow(InvalidArgumentException::class);
});
test('updateConfig updates configuration value', function (): void {
// Arrange
$configService = $this->getContainer()->get(ConfigurationService::class);
$key = SystemSettingKey::SYSTEM_NAME;
$initialValue = 'Initial System Name';
$newValue = 'Updated System Name';
// Create or update config with initial value
$configService->setConfigValue($key, $initialValue);
$config = $configService->getConfigByKey($key);
// Act
$updatedConfig = $configService->updateConfig($config, $newValue);
// Assert
expect($updatedConfig->getValue())->toBe($newValue)
->and($configService->getConfigValue($key))->toBe($newValue);
});
test('updateConfig does not update when value is empty', function (): void {
// Arrange
$configService = $this->getContainer()->get(ConfigurationService::class);
$key = SystemSettingKey::SYSTEM_NAME;
$initialValue = 'Initial System Name';
// Create or update config with initial value
$configService->setConfigValue($key, $initialValue);
$config = $configService->getConfigByKey($key);
// Act
$updatedConfig = $configService->updateConfig($config, '');
// Assert
expect($updatedConfig->getValue())->toBe($initialValue);
expect($configService->getConfigValue($key))->toBe($initialValue);
});
test('resetAllConfigs resets all configurations to default values', function (): void {
// Arrange
/** @var ConfigurationService $configService */
$configService = $this->getContainer()->get(ConfigurationService::class);
// Set non-default values for all configs
foreach (SystemSettingKey::cases() as $key) {
$configService->setConfigValue($key, 'non-default-value');
$configService->set($key, 'non-default value');
}
// Act
$configService->resetAllConfigs();
$configService->resetAll();
// Assert
foreach (SystemSettingKey::cases() as $key) {
$expectedValue = SystemSettingKey::getDefaultValue($key);
$actualValue = $configService->getConfigValue($key);
expect($actualValue)->toBe($expectedValue);
expect($configService->get($key))->toBe($key->defaultValue());
}
});
test('setDefaultValue sets default value for specific key', function (): void {
// Arrange
$configService = $this->getContainer()->get(ConfigurationService::class);
$key = SystemSettingKey::SYSTEM_NAME;
$nonDefaultValue = 'Non-Default System Name';
// Set non-default value
$configService->setConfigValue($key, $nonDefaultValue);
// Act
$configService->setDefaultValue($key);
// Assert
$expectedValue = SystemSettingKey::getDefaultValue($key);
$actualValue = $configService->getConfigValue($key);
expect($actualValue)->toBe($expectedValue);
});