1 | <?php |
||
7 | class SharedMemoryTest extends TestCase |
||
8 | { |
||
9 | public function setUp() |
||
10 | { |
||
11 | (new SharedMemory())->destroy(); |
||
12 | } |
||
13 | |||
14 | public function testSet() |
||
15 | { |
||
16 | $memory = new SharedMemory(); |
||
17 | $result = $memory->set('foo', 'bar'); |
||
18 | $this->assertTrue($result); |
||
19 | } |
||
20 | |||
21 | public function testGet() |
||
22 | { |
||
23 | $memory = new SharedMemory(); |
||
24 | $memory->set('foo', 'bar'); |
||
25 | $this->assertEquals('bar', $memory->get('foo')); |
||
26 | } |
||
27 | |||
28 | public function testHas() |
||
29 | { |
||
30 | $memory = new SharedMemory(); |
||
31 | $this->assertFalse($memory->has('foo')); |
||
32 | $memory->set('foo', 'bar'); |
||
33 | $this->assertTrue($memory->has('foo')); |
||
34 | } |
||
35 | |||
36 | public function testDelete() |
||
37 | { |
||
38 | $memory = new SharedMemory(); |
||
39 | $memory->set('foo', 'bar'); |
||
40 | $this->assertTrue($memory->has('foo')); |
||
41 | $memory->delete('foo'); |
||
42 | $this->assertFalse($memory->has('foo')); |
||
43 | } |
||
44 | |||
45 | public function testClear() |
||
46 | { |
||
47 | $memory = new SharedMemory(); |
||
48 | $memory->set('foo', 'bar'); |
||
49 | $memory->set('bar', 'baz'); |
||
50 | $this->assertTrue($memory->has('foo')); |
||
51 | $this->assertTrue($memory->has('bar')); |
||
52 | $result = $memory->clear(); |
||
53 | $this->assertTrue($result); |
||
54 | // var_dump($result, $memory->get('foo')); |
||
55 | // $this->assertFalse($memory->has('foo')); |
||
56 | // $this->assertFalse($memory->has('bar')); |
||
57 | } |
||
58 | |||
59 | public function testCheckIsEnabled() |
||
60 | { |
||
61 | $memory = new SharedMemory(); |
||
62 | $this->assertTrue($memory->isEnabled()); |
||
63 | } |
||
64 | |||
65 | public function testClose() |
||
66 | { |
||
67 | $memory = new SharedMemory(); |
||
68 | $result = $memory->set('foo', 'bar'); |
||
69 | $this->assertTrue($result); |
||
70 | $memory->close(); |
||
71 | $this->assertFalse($memory->isEnabled()); |
||
72 | } |
||
73 | |||
74 | public function testDestroy() |
||
75 | { |
||
76 | $memory = new SharedMemory(); |
||
77 | $result = $memory->set('foo', 'bar'); |
||
78 | $this->assertTrue($result); |
||
79 | $memory->destroy(); |
||
80 | $this->assertFalse($memory->isEnabled()); |
||
81 | } |
||
82 | |||
83 | public function testConvertToHumanReadableSize() |
||
84 | { |
||
85 | $this->assertEquals(8 * 1024, SharedMemory::humanReadableToBytes('8K')); |
||
86 | $this->assertEquals(8 * 1024 * 1024, SharedMemory::humanReadableToBytes('8M')); |
||
87 | $this->assertEquals(8 * 1024 * 1024 * 1024, SharedMemory::humanReadableToBytes('8G')); |
||
88 | $this->assertEquals(8 * 1024 * 1024 * 1024, SharedMemory::humanReadableToBytes('8g')); |
||
89 | } |
||
90 | } |
||
91 |