forked from top-think/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigTest.php
46 lines (35 loc) · 1.28 KB
/
ConfigTest.php
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
<?php
namespace think\tests;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use think\Config;
class ConfigTest extends TestCase
{
public function testLoad()
{
$root = vfsStream::setup();
$file = vfsStream::newFile('test.php')->setContent("<?php return ['key1'=> 'value1','key2'=>'value2'];");
$root->addChild($file);
$config = new Config();
$config->load($file->url(), 'test');
$this->assertEquals('value1', $config->get('test.key1'));
$this->assertEquals('value2', $config->get('test.key2'));
$this->assertSame(['key1' => 'value1', 'key2' => 'value2'], $config->get('test'));
}
public function testSetAndGet()
{
$config = new Config();
$config->set([
'key1' => 'value1',
'key2' => [
'key3' => 'value3',
],
], 'test');
$this->assertTrue($config->has('test.key1'));
$this->assertEquals('value1', $config->get('test.key1'));
$this->assertEquals('value3', $config->get('test.key2.key3'));
$this->assertEquals(['key3' => 'value3'], $config->get('test.key2'));
$this->assertFalse($config->has('test.key3'));
$this->assertEquals('none', $config->get('test.key3', 'none'));
}
}