~tsep-dev/tsep/0.9-beta

« back to all changes in this revision

Viewing changes to branches/symfony/cake/tests/cases/libs/cache/apc.test.php

  • Committer: geoffreyfishing
  • Date: 2011-01-11 23:46:12 UTC
  • Revision ID: svn-v4:ae0de26e-ed09-4cbe-9a20-e40b4c60ac6c::125
Created a symfony branch for future migration to symfony

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * ApcEngineTest file
 
4
 *
 
5
 * PHP versions 4 and 5
 
6
 *
 
7
 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
 
8
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
9
 *
 
10
 *  Licensed under The Open Group Test Suite License
 
11
 *  Redistributions of files must retain the above copyright notice.
 
12
 *
 
13
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
14
 * @link          http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
 
15
 * @package       cake
 
16
 * @subpackage    cake.tests.cases.libs.cache
 
17
 * @since         CakePHP(tm) v 1.2.0.5434
 
18
 * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
 
19
 */
 
20
if (!class_exists('Cache')) {
 
21
        require LIBS . 'cache.php';
 
22
}
 
23
 
 
24
/**
 
25
 * ApcEngineTest class
 
26
 *
 
27
 * @package       cake
 
28
 * @subpackage    cake.tests.cases.libs.cache
 
29
 */
 
30
class ApcEngineTest extends CakeTestCase {
 
31
 
 
32
/**
 
33
 * skip method
 
34
 *
 
35
 * @access public
 
36
 * @return void
 
37
 */
 
38
        function skip() {
 
39
                $skip = true;
 
40
                if (function_exists('apc_store')) {
 
41
                        $skip = false;
 
42
                }
 
43
                $this->skipIf($skip, '%s Apc is not installed or configured properly');
 
44
        }
 
45
 
 
46
/**
 
47
 * setUp method
 
48
 *
 
49
 * @access public
 
50
 * @return void
 
51
 */
 
52
        function setUp() {
 
53
                $this->_cacheDisable = Configure::read('Cache.disable');
 
54
                Configure::write('Cache.disable', false);
 
55
                Cache::config('apc', array('engine' => 'Apc', 'prefix' => 'cake_'));
 
56
        }
 
57
 
 
58
/**
 
59
 * tearDown method
 
60
 *
 
61
 * @access public
 
62
 * @return void
 
63
 */
 
64
        function tearDown() {
 
65
                Configure::write('Cache.disable', $this->_cacheDisable);
 
66
                Cache::drop('apc');
 
67
                Cache::config('default');
 
68
        }
 
69
 
 
70
/**
 
71
 * testReadAndWriteCache method
 
72
 *
 
73
 * @access public
 
74
 * @return void
 
75
 */
 
76
        function testReadAndWriteCache() {
 
77
                Cache::set(array('duration' => 1));
 
78
 
 
79
                $result = Cache::read('test');
 
80
                $expecting = '';
 
81
                $this->assertEqual($result, $expecting);
 
82
 
 
83
                $data = 'this is a test of the emergency broadcasting system';
 
84
                $result = Cache::write('test', $data);
 
85
                $this->assertTrue($result);
 
86
 
 
87
                $result = Cache::read('test');
 
88
                $expecting = $data;
 
89
                $this->assertEqual($result, $expecting);
 
90
 
 
91
                Cache::delete('test');
 
92
        }
 
93
 
 
94
/**
 
95
 * testExpiry method
 
96
 *
 
97
 * @access public
 
98
 * @return void
 
99
 */
 
100
        function testExpiry() {
 
101
                Cache::set(array('duration' => 1));
 
102
 
 
103
                $result = Cache::read('test');
 
104
                $this->assertFalse($result);
 
105
 
 
106
                $data = 'this is a test of the emergency broadcasting system';
 
107
                $result = Cache::write('other_test', $data);
 
108
                $this->assertTrue($result);
 
109
 
 
110
                sleep(2);
 
111
                $result = Cache::read('other_test');
 
112
                $this->assertFalse($result);
 
113
 
 
114
                Cache::set(array('duration' =>  1));
 
115
 
 
116
                $data = 'this is a test of the emergency broadcasting system';
 
117
                $result = Cache::write('other_test', $data);
 
118
                $this->assertTrue($result);
 
119
 
 
120
                sleep(2);
 
121
                $result = Cache::read('other_test');
 
122
                $this->assertFalse($result);
 
123
 
 
124
                sleep(2);
 
125
                $result = Cache::read('other_test');
 
126
                $this->assertFalse($result);
 
127
        }
 
128
 
 
129
/**
 
130
 * testDeleteCache method
 
131
 *
 
132
 * @access public
 
133
 * @return void
 
134
 */
 
135
        function testDeleteCache() {
 
136
                $data = 'this is a test of the emergency broadcasting system';
 
137
                $result = Cache::write('delete_test', $data);
 
138
                $this->assertTrue($result);
 
139
 
 
140
                $result = Cache::delete('delete_test');
 
141
                $this->assertTrue($result);
 
142
        }
 
143
 
 
144
/**
 
145
 * testDecrement method
 
146
 *
 
147
 * @access public
 
148
 * @return void
 
149
 */
 
150
        function testDecrement() {
 
151
                if ($this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement() %s')) {
 
152
                        return;
 
153
                }
 
154
                $result = Cache::write('test_decrement', 5);
 
155
                $this->assertTrue($result);
 
156
 
 
157
                $result = Cache::decrement('test_decrement');
 
158
                $this->assertEqual(4, $result);
 
159
 
 
160
                $result = Cache::read('test_decrement');
 
161
                $this->assertEqual(4, $result);
 
162
 
 
163
                $result = Cache::decrement('test_decrement', 2);
 
164
                $this->assertEqual(2, $result);
 
165
 
 
166
                $result = Cache::read('test_decrement');
 
167
                $this->assertEqual(2, $result);
 
168
                
 
169
        }
 
170
 
 
171
/**
 
172
 * testIncrement method
 
173
 *
 
174
 * @access public
 
175
 * @return void
 
176
 */
 
177
        function testIncrement() {
 
178
                if ($this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment() %s')) {
 
179
                        return;
 
180
                }
 
181
                $result = Cache::write('test_increment', 5);
 
182
                $this->assertTrue($result);
 
183
 
 
184
                $result = Cache::increment('test_increment');
 
185
                $this->assertEqual(6, $result);
 
186
 
 
187
                $result = Cache::read('test_increment');
 
188
                $this->assertEqual(6, $result);
 
189
 
 
190
                $result = Cache::increment('test_increment', 2);
 
191
                $this->assertEqual(8, $result);
 
192
 
 
193
                $result = Cache::read('test_increment');
 
194
                $this->assertEqual(8, $result);
 
195
        }
 
196
}