| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/config/src/lmbCachedIni.class.php'); 10 lmb_require('limb/fs/src/lmbFs.class.php'); 11 12 class lmbCachedIniCachingTest extends UnitTestCase 13 { 14 var $cache_dir; 15 16 function setUp() 17 { 18 $this->cache_dir = LIMB_VAR_DIR . '/ini/'; 19 lmbFs :: rm($this->cache_dir); 20 lmbFs :: mkdir(LIMB_VAR_DIR . '/tmp_ini/'); 21 } 22 23 function tearDown() 24 { 25 lmbFs :: rm(LIMB_VAR_DIR . '/tmp_ini/'); 26 lmbFs :: rm($this->cache_dir); 27 } 28 29 function _createIniFile($contents, &$override_file = null) 30 { 31 $name = mt_rand(); 32 $file = LIMB_VAR_DIR . '/tmp_ini/' . $name . '.ini'; 33 $override_file = LIMB_VAR_DIR . '/tmp_ini/' . $name . '.override.ini'; 34 file_put_contents($file, $contents); 35 return $file; 36 } 37 38 function testCacheHit() 39 { 40 $file = $this->_createIniFile('test = 1'); 41 $ini1 = new lmbCachedIni($file, $this->cache_dir); 42 43 $this->assertEqual(sizeof(scandir($this->cache_dir)), 3);//cache file + . and .. 44 45 $this->assertEqual($ini1->get('test'), 1); 46 47 file_put_contents($file, 'test = 2');//explicitly changing ini file 48 touch($file, time() - 10); //but making it look older than it is 49 clearstatcache(); 50 51 $ini2 = new lmbCachedIni($file, $this->cache_dir); 52 $this->assertEqual($ini2->get('test'), 1); 53 } 54 55 function testCacheMissFileWasModified() 56 { 57 $file = $this->_createIniFile('test = 1'); 58 $ini1 = new lmbCachedIni($file, $this->cache_dir); 59 60 $this->assertEqual($ini1->get('test'), 1); 61 62 file_put_contents($file, 'test = 2'); 63 touch($file, time() + 10); 64 clearstatcache(); 65 66 $ini2 = new lmbCachedIni($file, $this->cache_dir); 67 $this->assertEqual($ini2->get('test'), 2); 68 } 69 70 function testCacheMissOverrideFileWasModified() 71 { 72 $file = $this->_createIniFile('test = 1', $override_file); 73 $ini1 = new lmbCachedIni($file, $this->cache_dir); 74 75 $this->assertEqual($ini1->get('test'), 1); 76 77 file_put_contents($override_file, 'test = 2'); 78 touch($override_file, time() + 10); 79 80 $ini2 = new lmbCachedIni($file, $this->cache_dir); 81 $this->assertEqual($ini2->get('test'), 2); 82 } 83 } 84 85 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Oct 14 04:47:40 2008 | Cross-referenced by PHPXref 0.7 |