From fd865d85672851107e277003fa0bee99f4654e38 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 15 Jul 2015 23:47:56 +0200 Subject: [PATCH] Write some specs for settings cache repository --- .../Settings/CachedSettingsRepositorySpec.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 framework/core/spec/Flarum/Core/Settings/CachedSettingsRepositorySpec.php 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(); + } +}