|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class TestDict extends Dictionary {} |
|
4
|
|
|
|
|
5
|
|
|
class DictionaryTest extends PHPUnit_Framework_TestCase { |
|
6
|
|
|
|
|
7
|
|
|
public function __construct(){ |
|
8
|
|
|
$this->data = [ |
|
9
|
|
|
'a' => 123, |
|
10
|
|
|
'b' => 'hello', |
|
11
|
|
|
'c' => [ |
|
12
|
|
|
'r' => '#f00', |
|
13
|
|
|
'g' => '#0f0', |
|
14
|
|
|
'b' => '#00f', |
|
15
|
|
|
], |
|
16
|
|
|
]; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testInit(){ |
|
20
|
|
|
$this->assertEquals(json_encode(TestDict::all()), "[]"); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testLoad(){ |
|
24
|
|
|
TestDict::load($this->data); |
|
25
|
|
|
$this->assertEquals(json_encode(TestDict::all()), json_encode($this->data)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testClear(){ |
|
29
|
|
|
TestDict::clear(); |
|
30
|
|
|
$this->assertEquals(json_encode(TestDict::all()), "[]"); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testSetGet(){ |
|
34
|
|
|
TestDict::set('a',999); |
|
35
|
|
|
$this->assertEquals(TestDict::all()['a'], 999); |
|
36
|
|
|
$this->assertEquals(TestDict::get('a'), 999); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testExists(){ |
|
40
|
|
|
TestDict::set('a',999); |
|
41
|
|
|
$this->assertTrue(TestDict::exists('a')); |
|
42
|
|
|
$this->assertFalse(TestDict::exists('not-a')); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testLeftMerge(){ |
|
46
|
|
|
TestDict::merge($this->data,true); |
|
47
|
|
|
$this->assertEquals(TestDict::all()['a'], 999); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testRightMerge(){ |
|
51
|
|
|
TestDict::clear(); |
|
52
|
|
|
TestDict::set('a',999); |
|
53
|
|
|
TestDict::merge($this->data); |
|
54
|
|
|
$this->assertEquals(TestDict::all()['a'], 123); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testDefaultOnGetFail(){ |
|
58
|
|
|
$this->assertEquals(TestDict::get('i-dont-exists','OK'), 'OK'); |
|
59
|
|
|
$this->assertEquals(TestDict::get('i-dont-exists',function(){return 'OK';}), 'OK'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testSetGetFromPath(){ |
|
63
|
|
|
TestDict::clear(); |
|
64
|
|
|
$this->assertEquals(TestDict::set('a.b.c.d',1), 1); |
|
65
|
|
|
$this->assertEquals(TestDict::get('a.b.c.d',0), 1); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|