diff --git a/app/Services/Option.php b/app/Services/Option.php index 00733b6..844d212 100644 --- a/app/Services/Option.php +++ b/app/Services/Option.php @@ -49,8 +49,12 @@ class Option * * @return string The option value. */ - public function set($key, string $value) + public function set($key, ?string $value) { + if (is_null($value)) { + $value = ''; + } + $option = $this->option->where('key', $key)->first(); if ($option) { diff --git a/tests/Unit/Services/SiteOptionTest.php b/tests/Unit/Services/SiteOptionTest.php index 566e8ff..c2f3ae7 100644 --- a/tests/Unit/Services/SiteOptionTest.php +++ b/tests/Unit/Services/SiteOptionTest.php @@ -22,6 +22,17 @@ class SiteOptionTest extends TestCase } /** @test */ + public function option_value_null_must_be_converted_to_empty_string() + { + Option::set('testing_key', null); + + $this->seeInDatabase('site_options', [ + 'key' => 'testing_key', + 'value' => '', + ]); + } + + /** @test */ public function option_can_be_get() { \DB::table('site_options')->insert([