Browse Source

Fix option value can accept null

pull/41/head
Kang Dels 7 years ago
parent
commit
e4d970cb1a
  1. 8
      app/Services/Option.php
  2. 11
      tests/Unit/Services/SiteOptionTest.php

8
app/Services/Option.php

@ -45,12 +45,16 @@ class Option
* Set new value for given option key.
*
* @param string $key The option key.
* @param string $value The option value to be saved.
* @param mixed $value The option value to be saved.
*
* @return string The option value.
*/
public function set($key, string $value)
public function set($key, $value)
{
if (is_null($value) || !is_string($value)) {
$value = '';
}
$option = $this->option->where('key', $key)->first();
if ($option) {

11
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([

Loading…
Cancel
Save