mirror of
https://github.com/flarum/framework.git
synced 2025-02-18 08:13:15 +08:00
Write some specs for settings cache repository
This commit is contained in:
parent
8a1b2fcede
commit
1b39d85a7b
54
spec/Flarum/Core/Settings/CachedSettingsRepositorySpec.php
Normal file
54
spec/Flarum/Core/Settings/CachedSettingsRepositorySpec.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace spec\Flarum\Core\Settings;
|
||||
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CachedSettingsRepositorySpec extends ObjectBehavior
|
||||
{
|
||||
function let(SettingsRepository $inner)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user