Browse Source
Merge pull request #41 from dels07/bugfix/option-service
Fix option value can accept null
Resolves #40
pull/50/head
Nafies Luthfi
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
16 additions and
1 deletions
-
app/Services/Option.php
-
tests/Unit/Services/SiteOptionTest.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) { |
|
|
|
|
|
|
|
@ -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([ |
|
|
|
|