diff --git a/framework/core/spec/Flarum/Core/Settings/CachedSettingsRepositorySpec.php b/framework/core/spec/Flarum/Core/Settings/CachedSettingsRepositorySpec.php new file mode 100644 index 000000000..4119fcee6 --- /dev/null +++ b/framework/core/spec/Flarum/Core/Settings/CachedSettingsRepositorySpec.php @@ -0,0 +1,54 @@ +beConstructedWith($inner); + } + + function it_is_initializable() + { + $this->shouldHaveType('Flarum\Core\Settings\CachedSettingsRepository'); + } + + function it_retrieves_data_from_inner(SettingsRepository $inner) + { + $settings = ['a' => 1, 'b' => 2]; + $inner->all()->willReturn($settings); + $inner->all()->shouldBeCalled(); + + // Test fetching all settings + $this->all()->shouldReturn($settings); + + // Test fetching single settings + $this->get('a')->shouldReturn(1); + $this->get('b')->shouldReturn(2); + + // Test invalid key + $this->get('c')->shouldReturn(null); + + // Test invalid key with custom default + $this->get('d', 'foobar')->shouldReturn('foobar'); + } + + function it_passes_new_data_to_inner(SettingsRepository $inner) + { + $this->set('a', 1); + $inner->set('a', 1)->shouldHaveBeenCalled(); + } + + function it_caches_new_data(SettingsRepository $inner) + { + $this->set('b', 2); + $this->get('b')->shouldReturn(2); + $inner->all()->shouldNotHaveBeenCalled(); + $inner->get('b')->shouldNotHaveBeenCalled(); + } +}