Skip to content

Commit

Permalink
Test json value serializer with settings service
Browse files Browse the repository at this point in the history
  • Loading branch information
rawilk committed Sep 28, 2023
1 parent f5190ee commit caf6162
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/Feature/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\DB;
use Rawilk\Settings\Facades\Settings as SettingsFacade;
use Rawilk\Settings\Support\Context;
use Rawilk\Settings\Support\ValueSerializers\JsonValueSerializer;

beforeEach(function () {
config([
Expand Down Expand Up @@ -264,6 +265,28 @@
->not->toBe(serialize('bar'));
});

test('custom value serializers can be used', function () {
$settings = settings();
(fn () => $this->valueSerializer = new JsonValueSerializer)->call($settings);

$settings->disableEncryption();

$settings->set('foo', 'my value');
$settings->set('array-value', ['foo' => 'bar', 'bool' => true]);

$this->assertDatabaseHas('settings', [
'value' => '"my value"',
]);

$this->assertDatabaseHas('settings', [
'value' => '{"foo":"bar","bool":true}',
]);

expect($settings->get('foo'))->toBe('my value')
->and($settings->get('array-value'))->toBeArray()
->and($settings->get('array-value'))->toMatchArray(['foo' => 'bar', 'bool' => true]);
});

// Helpers...

function assertQueryCount(int $expected): void
Expand Down

0 comments on commit caf6162

Please sign in to comment.