Skip to content

Commit d6c027e

Browse files
bugfix and nullable return types
1 parent 29eebf5 commit d6c027e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/Drivers/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function all(): Collection
2424
$this->resetScopes();
2525
}
2626

27-
public function get(string $key, string $default = ''): string
27+
public function get(string $key, string $default = null): ?string
2828
{
2929
$this->fetchSettings();
3030

src/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface Settings
88
{
99
public function all(): Collection;
1010

11-
public function get(string $key, string $default = ''): string;
11+
public function get(string $key, string $default = null): ?string;
1212

1313
public function set($key, string $value = null): void;
1414

src/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function settings(string $key = null, string $default = null)
55
{
66
$settings = app()->make(Justijndepover\Settings\Settings::class);
77

8-
if (!is_null($key)) {
8+
if (! is_null($key)) {
99
return $settings->get($key, $default);
1010
}
1111

tests/Feature/DatabaseSettingsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function it_can_check_if_value_exists()
8686
]);
8787

8888
$this->assertEquals($this->settings->has('name'), true);
89+
$this->assertEquals($this->settings->has('name2'), false);
8990
}
9091

9192
/** @test */
@@ -148,6 +149,17 @@ public function it_can_delete_a_single_value()
148149
$this->assertEquals(DB::table('settings')->count(), 1);
149150
}
150151

152+
/** @test */
153+
public function it_has_a_helper_method()
154+
{
155+
DB::table('settings')->insert([
156+
'key' => 'name',
157+
'value' => 'value',
158+
]);
159+
160+
$this->assertEquals(settings('name'), 'value');
161+
}
162+
151163
/** @test */
152164
public function it_has_a_facade_accessor()
153165
{
@@ -265,4 +277,14 @@ public function it_has_a_working_user_setting_trait()
265277
$this->assertEquals($user->settings->get('name'), 'value');
266278
$this->assertEquals($user->settings()->get('name'), 'value');
267279
}
280+
281+
/** @test */
282+
public function it_can_return_a_default_value()
283+
{
284+
$value = $this->settings->get('key');
285+
$this->assertEquals($value, null);
286+
287+
$value = $this->settings->get('key', 'value');
288+
$this->assertEquals($value, 'value');
289+
}
268290
}

0 commit comments

Comments
 (0)