88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Entity\SystemConfig;
|
|
use App\Enum\SystemSettingKey;
|
|
use App\Service\Config\AppName;
|
|
use App\Service\Config\LowStockMultiplier;
|
|
use App\Service\ConfigurationService;
|
|
|
|
test('AppName returns system name from configuration', function (): void {
|
|
// Arrange
|
|
$appName = $this->getContainer()->get(AppName::class);
|
|
$configService = $this->getContainer()->get(ConfigurationService::class);
|
|
$testSystemName = 'Test System Name';
|
|
|
|
// Set a custom system name
|
|
$configService->setConfigValue(SystemSettingKey::SYSTEM_NAME, $testSystemName);
|
|
|
|
// Act
|
|
$result = (string) $appName;
|
|
|
|
// Assert
|
|
expect($result)->toBe($testSystemName);
|
|
});
|
|
|
|
test('AppName returns default system name when not configured', function (): void {
|
|
// Arrange
|
|
$appName = $this->getContainer()->get(AppName::class);
|
|
$configService = $this->getContainer()->get(ConfigurationService::class);
|
|
|
|
// Reset to default value
|
|
$configService->setDefaultValue(SystemSettingKey::SYSTEM_NAME);
|
|
|
|
// Act
|
|
$result = (string) $appName;
|
|
|
|
// Assert
|
|
expect($result)->toBe(SystemConfig::DEFAULT_SYSTEM_NAME);
|
|
});
|
|
|
|
test('LowStockMultiplier returns multiplier from configuration', function (): void {
|
|
// Arrange
|
|
$lowStockMultiplier = $this->getContainer()->get(LowStockMultiplier::class);
|
|
$configService = $this->getContainer()->get(ConfigurationService::class);
|
|
$testMultiplier = '0.5';
|
|
|
|
// Set a custom multiplier
|
|
$configService->setConfigValue(SystemSettingKey::STOCK_LOW_MULTIPLIER, $testMultiplier);
|
|
|
|
// Act
|
|
$result = $lowStockMultiplier->getValue();
|
|
|
|
// Assert
|
|
expect($result)->toBe((float) $testMultiplier);
|
|
});
|
|
|
|
test('LowStockMultiplier returns default multiplier when not configured', function (): void {
|
|
// Arrange
|
|
$lowStockMultiplier = $this->getContainer()->get(LowStockMultiplier::class);
|
|
$configService = $this->getContainer()->get(ConfigurationService::class);
|
|
|
|
// Reset to default value
|
|
$configService->setDefaultValue(SystemSettingKey::STOCK_LOW_MULTIPLIER);
|
|
|
|
// Act
|
|
$result = $lowStockMultiplier->getValue();
|
|
|
|
// Assert
|
|
expect($result)->toBe((float) SystemConfig::DEFAULT_STOCK_LOW_MULTIPLIER);
|
|
});
|
|
|
|
test('LowStockMultiplier converts string value to float', function (): void {
|
|
// Arrange
|
|
$lowStockMultiplier = $this->getContainer()->get(LowStockMultiplier::class);
|
|
$configService = $this->getContainer()->get(ConfigurationService::class);
|
|
$testMultiplier = '0.75';
|
|
|
|
// Set a custom multiplier
|
|
$configService->setConfigValue(SystemSettingKey::STOCK_LOW_MULTIPLIER, $testMultiplier);
|
|
|
|
// Act
|
|
$result = $lowStockMultiplier->getValue();
|
|
|
|
// Assert
|
|
expect($result)->toBe(0.75);
|
|
expect($result)->toBeFloat();
|
|
});
|