forked from codeigniter4/settings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsTest.php
More file actions
93 lines (69 loc) · 2.72 KB
/
SettingsTest.php
File metadata and controls
93 lines (69 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Tests;
use CodeIgniter\Settings\Settings;
use Config\Services;
use Tests\Support\TestCase;
/**
* @internal
*/
final class SettingsTest extends TestCase
{
public function testSettingsUsesParameter()
{
$config = config('Settings');
$config->handlers = [];
$settings = new Settings($config);
$result = $this->getPrivateProperty($settings, 'handlers');
$this->assertSame([], $result);
}
public function testServiceUsesConfig()
{
Services::resetSingle('settings');
$config = config('Settings');
$config->handlers = [];
$settings = service('settings');
$result = $this->getPrivateProperty($settings, 'handlers');
$this->assertSame([], $result);
}
public function testSettingsGetsFromConfig()
{
$this->assertSame(config('Example')->siteName, $this->settings->get('Example.siteName'));
}
public function testSettingsNotFound()
{
$this->assertSame(config('Example')->siteName, $this->settings->get('Example.siteName'));
}
public function testGetWithContext()
{
$this->settings->set('Example.siteName', 'NoContext');
$this->settings->set('Example.siteName', 'YesContext', 'testing:true');
$this->assertSame('NoContext', $this->settings->get('Example.siteName'));
$this->assertSame('YesContext', $this->settings->get('Example.siteName', 'testing:true'));
}
public function testGetWithoutContextUsesGlobal()
{
$this->settings->set('Example.siteName', 'NoContext');
$this->assertSame('NoContext', $this->settings->get('Example.siteName', 'testing:true'));
}
public function testForgetWithContext()
{
$this->settings->set('Example.siteName', 'Bar');
$this->settings->set('Example.siteName', 'Amnesia', 'category:disease');
$this->settings->forget('Example.siteName', 'category:disease');
$this->assertSame('Bar', $this->settings->get('Example.siteName', 'category:disease'));
}
public function testPullWithContext()
{
$this->settings->set('Example.siteName', 'Amnesia', 'category:disease');
$value = $this->settings->take('Example.siteName', 'category:disease');
$this->assertSame('Amnesia', $value);
$this->assertSame('Settings Test', $this->settings->get('Example.siteName', 'category:disease'));
}
public function testPullWithoutContext()
{
$this->settings->set('Example.siteName', 'NoContext');
$value = $this->settings->take('Example.siteName');
$this->assertSame('NoContext', $value);
$this->assertSame('Settings Test', $this->settings->get('Example.siteName'));
}
}