Completed
Push — stable8.2 ( 36aa4e...013031 )
by
unknown
12:55
created

CappedMemoryCache::testIndirectSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * ownCloud
4
 *
5
 * @author Robin Appelman
6
 * @copyright 2016 Robin Appelman [email protected]
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace Test\Cache;
24
25
/**
26
 * Class FileCache
27
 *
28
 * @group DB
29
 *
30
 * @package Test\Cache
31
 */
32
class CappedMemoryCache extends \Test_Cache {
33
	public function setUp() {
34
		parent::setUp();
35
		$this->instance = new \OC\Cache\CappedMemoryCache();
36
	}
37
38
	public function testSetOverCap() {
39
		$instance = new \OC\Cache\CappedMemoryCache(3);
40
41
		$instance->set('1', 'a');
42
		$instance->set('2', 'b');
43
		$instance->set('3', 'c');
44
		$instance->set('4', 'd');
45
		$instance->set('5', 'e');
46
47
		$this->assertFalse($instance->hasKey('1'));
48
		$this->assertFalse($instance->hasKey('2'));
49
		$this->assertTrue($instance->hasKey('3'));
50
		$this->assertTrue($instance->hasKey('4'));
51
		$this->assertTrue($instance->hasKey('5'));
52
	}
53
54
	function testClear() {
55
		$value = 'ipsum lorum';
56
		$this->instance->set('1_value1', $value);
57
		$this->instance->set('1_value2', $value);
58
		$this->instance->set('2_value1', $value);
59
		$this->instance->set('3_value1', $value);
60
61
		$this->assertTrue($this->instance->clear());
62
		$this->assertFalse($this->instance->hasKey('1_value1'));
63
		$this->assertFalse($this->instance->hasKey('1_value2'));
64
		$this->assertFalse($this->instance->hasKey('2_value1'));
65
		$this->assertFalse($this->instance->hasKey('3_value1'));
66
	}
67
68
	function testIndirectSet() {
69
		$this->instance->set('array', []);
70
71
		$this->instance['array'][] = 'foo';
72
73
		$this->assertEquals(['foo'], $this->instance->get('array'));
74
75
		$this->instance['array']['bar'] = 'qwerty';
76
77
		$this->assertEquals(['foo', 'bar' => 'qwerty'], $this->instance->get('array'));
78
	}
79
}
80