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
parent
commit
46dd0ee239
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/Services/Option.php
  2. 11
      tests/Unit/Services/SiteOptionTest.php

6
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) {

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