From 7137f0e7a15d46ab1ef7cdff8f71eb3922a45347 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Wed, 8 Feb 2023 15:58:46 +0100 Subject: [PATCH] Add support of floats to SettingService --- app/Services/SettingService.php | 4 +++- tests/Feature/Services/SettingServiceTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Services/SettingService.php b/app/Services/SettingService.php index 58952298..530605ca 100644 --- a/app/Services/SettingService.php +++ b/app/Services/SettingService.php @@ -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; diff --git a/tests/Feature/Services/SettingServiceTest.php b/tests/Feature/Services/SettingServiceTest.php index 4445225c..e6470b35 100644 --- a/tests/Feature/Services/SettingServiceTest.php +++ b/tests/Feature/Services/SettingServiceTest.php @@ -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 */