Add support of floats to SettingService

This commit is contained in:
Bubka 2023-02-08 15:58:46 +01:00
parent ead31fef87
commit 7137f0e7a1
2 changed files with 18 additions and 1 deletions

View File

@ -140,7 +140,9 @@ private function replaceBoolean(mixed $value)
*/
private function restoreType(mixed $value)
{
$value = is_numeric($value) ? (int) $value : $value;
if (is_numeric($value)) {
$value = is_float($value + 0) ? (float) $value : (int) $value;
}
if ($value === '{{}}') {
return false;

View File

@ -37,6 +37,8 @@ class SettingServiceTest extends FeatureTestCase
private const SETTING_VALUE_INT = 10;
private const SETTING_VALUE_FLOAT = 10.5;
private const ACCOUNT = 'account';
private const SERVICE = 'service';
@ -132,6 +134,19 @@ public function test_get_int_setting_returns_int()
$this->assertIsInt($value);
}
/**
* @test
*/
public function test_get_float_setting_returns_float()
{
Settings::set(self::SETTING_NAME, self::SETTING_VALUE_FLOAT);
$value = Settings::get(self::SETTING_NAME);
$this->assertEquals(self::SETTING_VALUE_FLOAT, $value);
$this->assertIsFloat($value);
}
/**
* @test
*/