pluf2

pluf2 Commit Details


Date:2010-05-07 05:38:44 (14 years 7 months ago)
Author:Mehdi Kabab
Branch:master
Commit:51958344844575796cdd5e3beb57ac0ea3500114
Parents: 4753b98fde22fa9681c27152d99d0c196ea5a45b
Message:Fixed the return value of Pluf_Cache_File::set(). Added Unit tests for the File and Apc cache API.

Changes:

File differences

src/Pluf/Cache/File.php
5151
5252
5353
54
54
55
5556
5657
5758
if ($timeout == null) $timeout = Pluf::f('cache_timeout', 300);
if (!file_exists($dir)) mkdir($dir, 0777, true);
$expire = time()+$timeout;
file_put_contents($fname, $expire."\n".serialize($value), LOCK_EX);
$success = file_put_contents($fname, $expire."\n".serialize($value), LOCK_EX);
return (false === $success) ? false : true;
}
/**
src/Pluf/Tests/Cache/Apc.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
class Pluf_Tests_Cache_Apc extends UnitTestCase {
private $_config;
private $_arrayData = array(
'hello' => 'world',
'foo' => false,
0 => array('foo', 'bar')
);
public function __construct()
{
parent::__construct('Test the APC cache API.');
}
public function setUp()
{
$this->_config = $GLOBALS['_PX_config']; // backup
$GLOBALS['_PX_config']['cache_engine'] = 'Pluf_Cache_Apc';
$GLOBALS['_PX_config']['cache_timeout'] = 5;
$GLOBALS['_PX_config']['cache_apc_keyprefix'] = 'pluf_unittest_';
}
public function tearDown()
{
$GLOBALS['_PX_config'] = $this->_config;
}
public function testBasic()
{
$cache = Pluf_Cache::factory();
$success = $cache->set('test1', 'foo1');
$this->assertTrue($success);
$this->assertEqual('foo1', $cache->get('test1'));
}
public function testGetUnknownKey()
{
$cache = Pluf_Cache::factory();
$this->assertNull(null, $cache->get('unknown'));
}
public function testGetDefault()
{
$cache = Pluf_Cache::factory();
$this->assertEqual('default', $cache->get('unknown', 'default'));
}
public function testSerialized()
{
$cache = Pluf_Cache::factory();
$success = $cache->set('array', $this->_arrayData);
$this->assertTrue($success);
$this->assertCopy($this->_arrayData, $cache->get('array'));
$obj = new stdClass();
$obj->foo = 'bar';
$obj->hello = 'world';
$success = $cache->set('object', $obj);
$this->assertTrue($success);
$this->assertCopy($obj, $cache->get('object'));
unset($obj);
$this->assertIsA($cache->get('object'), 'stdClass');
$this->assertEqual('world', $cache->get('object')->hello);
}
public function testCompress()
{
$GLOBALS['_PX_config']['cache_apc_compress'] = true;
$cache = Pluf_Cache::factory();
$success = $cache->set('compressed', $this->_arrayData);
$this->assertTrue($success);
$this->assertCopy($this->_arrayData, $cache->get('compressed'));
}
}
src/Pluf/Tests/Cache/File.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
class Pluf_Tests_Cache_File extends UnitTestCase {
private $_config;
private $_arrayData = array(
'hello' => 'world',
'foo' => false,
0 => array('foo', 'bar')
);
public function __construct()
{
parent::__construct('Test the File cache API.');
}
public function setUp()
{
$this->_config = $GLOBALS['_PX_config']; // backup
$GLOBALS['_PX_config']['cache_engine'] = 'Pluf_Cache_File';
$GLOBALS['_PX_config']['cache_timeout'] = 5;
$GLOBALS['_PX_config']['cache_file_folder'] = '/tmp/pluf_unittest_cache';
}
public function tearDown()
{
$GLOBALS['_PX_config'] = $this->_config;
}
public function testConstructor()
{
unset($GLOBALS['_PX_config']['cache_file_folder']);
try {
$cache = Pluf_Cache::factory();
} catch (Pluf_Exception_SettingError $e) {
$this->pass();
return;
}
$this->fail('An exception as not been raised, "cache_file_folder" setting not defined.');
}
public function testBasic()
{
$cache = Pluf_Cache::factory();
$success = $cache->set('test1', 'foo1');
$this->assertTrue($success);
$this->assertEqual('foo1', $cache->get('test1'));
}
public function testGetUnknownKey()
{
$cache = Pluf_Cache::factory();
$this->assertNull(null, $cache->get('unknown'));
}
public function testGetDefault()
{
$cache = Pluf_Cache::factory();
$this->assertEqual('default', $cache->get('unknown', 'default'));
}
public function testSerialized()
{
$cache = Pluf_Cache::factory();
$success = $cache->set('array', $this->_arrayData);
$this->assertTrue($success);
$this->assertCopy($this->_arrayData, $cache->get('array'));
$obj = new stdClass();
$obj->foo = 'bar';
$obj->hello = 'world';
$success = $cache->set('object', $obj);
$this->assertTrue($success);
$this->assertCopy($obj, $cache->get('object'));
unset($obj);
$this->assertIsA($cache->get('object'), 'stdClass');
$this->assertEqual('world', $cache->get('object')->hello);
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.06516s using 13 queries.