 fwolf    /
                    fwlib
                      fwolf    /
                    fwlib
                
                            This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
                                via PHP's auto-loading mechanism.
                                                    These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * Test - Cache class | ||
| 4 | * @package fwolflib | ||
| 5 | * @subpackage class-test | ||
| 6 | * @copyright Copyright 2010, Fwolf | ||
| 7 | * @author Fwolf <[email protected]> | ||
| 8 | * @since 2010-01-07 | ||
| 9 | */ | ||
| 10 | |||
| 11 | // Define like this, so test can run both under eclipse and web alone. | ||
| 12 | // {{{ | ||
| 13 | if (! defined('SIMPLE_TEST')) { | ||
| 14 | 	define('SIMPLE_TEST', 'simpletest/'); | ||
| 15 | require_once(SIMPLE_TEST . 'autorun.php'); | ||
| 16 | } | ||
| 17 | // Then set output encoding | ||
| 18 | //header('Content-Type: text/html; charset=utf-8'); | ||
| 19 | // }}} | ||
| 20 | |||
| 21 | // Require library define file which need test | ||
| 22 | require_once(dirname(__FILE__) . '/fwolflib.php'); | ||
| 23 | require_once(FWOLFLIB . 'class/cache.php'); | ||
| 24 | require_once(FWOLFLIB . 'func/ecl.php'); | ||
| 25 | require_once(FWOLFLIB . 'func/request.php'); | ||
| 26 | require_once(FWOLFLIB . 'func/string.php'); | ||
| 27 | |||
| 28 | class TestCache extends UnitTestCase { | ||
| 29 | |||
| 30 | /** | ||
| 31 | * Cache object | ||
| 32 | * @var object | ||
| 33 | */ | ||
| 34 | protected $oCh = null; | ||
| 35 | |||
| 36 | |||
| 37 | /** | ||
| 38 | * Constructor | ||
| 39 | */ | ||
| 40 | 	public function __construct () { | ||
| 41 | $ar_cfg = array( | ||
| 42 | 'cache-file-dir' => '/tmp/cache/', | ||
| 43 | 'cache-file-rule' => '1142', | ||
| 44 | ); | ||
| 45 | $this->oCh = new CacheTest($ar_cfg); | ||
| 46 | } // end of func __construct | ||
| 47 | |||
| 48 | |||
| 49 |     function TestCacheFilePath () { | ||
| 0 ignored issues–
                            show | |||
| 50 | $this->oCh->SetCfg(array( | ||
| 51 | 'cache-type' => 'file', | ||
| 52 | 'cache-file-dir' => '/tmp/cache/', | ||
| 53 | 'cache-file-rule' => '1140', | ||
| 54 | )); | ||
| 55 | $key = 'site/index'; | ||
| 56 | |||
| 57 | //Ecl(md5($key)); | ||
| 58 | |||
| 59 | $x = '/tmp/cache/d0/ex/3ed0dc6e'; | ||
| 60 | $y = $this->oCh->CacheFilePath($key); | ||
| 61 | $this->assertEqual($x, $y); | ||
| 62 | |||
| 63 | 		$this->oCh->SetCfg(array('cache-file-rule' => '1131')); | ||
| 64 | $x = '/tmp/cache/d0/te/3ed0dc6e'; | ||
| 65 | $y = $this->oCh->CacheFilePath($key); | ||
| 66 | $this->assertEqual($x, $y); | ||
| 67 | |||
| 68 | // Notice: Directly use key's part as path may cause wrong | ||
| 69 | 		$this->oCh->SetCfg(array('cache-file-rule' => '2342')); | ||
| 70 | $x = '/tmp/cache/57//i/3ed0dc6e'; | ||
| 71 | $y = $this->oCh->CacheFilePath($key); | ||
| 72 | $this->assertEqual($x, $y); | ||
| 73 | |||
| 74 | // Common usage | ||
| 75 | 		$this->oCh->SetCfg(array('cache-file-rule' => '1011')); | ||
| 76 | $x = '/tmp/cache/3e/d0/3ed0dc6e'; | ||
| 77 | $y = $this->oCh->CacheFilePath($key); | ||
| 78 | $this->assertEqual($x, $y); | ||
| 79 | |||
| 80 | // Common usage 2 | ||
| 81 | 		$this->oCh->SetCfg(array('cache-file-rule' => '2021')); | ||
| 82 | $x = '/tmp/cache/b6/9c/3ed0dc6e'; | ||
| 83 | $y = $this->oCh->CacheFilePath($key); | ||
| 84 | $this->assertEqual($x, $y); | ||
| 85 | |||
| 86 | // Common usage 3 | ||
| 87 | 		$this->oCh->SetCfg(array('cache-file-rule' => '55')); | ||
| 88 | $x = '/tmp/cache/89/3ed0dc6e'; | ||
| 89 | $y = $this->oCh->CacheFilePath($key); | ||
| 90 | $this->assertEqual($x, $y); | ||
| 91 | |||
| 92 | //Ecl($y); | ||
| 93 | |||
| 94 | // Read/write | ||
| 95 | $v = $this->oCh->CacheGet($key, 1); | ||
| 96 | var_dump($v); | ||
| 0 ignored issues–
                            show | |||
| 97 | 		Ecl(hash('crc32', $key) | ||
| 0 ignored issues–
                            show The function  Ecl()has been deprecated with message: Use Fwlib\Util\Env::ecl()This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.  Loading history... | |||
| 98 | . '|' | ||
| 99 | . $this->oCh->CacheFilePath($key)); | ||
| 100 | } // end of func TestCacheFilePath | ||
| 101 | |||
| 102 | |||
| 103 | } // end of class TestCache | ||
| 104 | |||
| 105 | |||
| 106 | class CacheTest extends Cache { | ||
| 0 ignored issues–
                            show The class  Cachehas been deprecated with message: use Fwlib\Cache\CacheThis class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.  Loading history... | |||
| 107 | 	protected function CacheGenVal ($key) { | ||
| 108 | $this->sDummy = RandomString(30, 'a0'); | ||
| 0 ignored issues–
                            show The property  sDummydoes not exist. Did you maybe forget to declare it?In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
    public $foo;
}
$x = new MyClass();
$x->foo = true;
 Loading history... The function  RandomString()has been deprecated with message: Use Fwlib\Util\StringUtil::random()This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.  Loading history... | |||
| 109 | return $this; | ||
| 0 ignored issues–
                            show The return type of  return $this;(CacheTest) is incompatible with the return type declared by the abstract methodCache::CacheGenValof typestring.If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
    private $name;
    public function __construct($name) {
        $this->name = $name;
    }
    public function getName() {
        return $this->name;
    }
}
abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}
class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}
Our function   Loading history... | |||
| 110 | } // end of func CacheGenVal | ||
| 111 | |||
| 112 | 	public function CacheLifetime ($key) { | ||
| 113 | return 0; | ||
| 114 | } // end of func CacheLifetime | ||
| 115 | } // end of class CacheTest | ||
| 116 | |||
| 117 | |||
| 118 | // Change output charset in this way. | ||
| 119 | // {{{ | ||
| 120 | $s_url = GetSelfUrl(false); | ||
| 0 ignored issues–
                            show The function  GetSelfUrl()has been deprecated with message: Use Fwlib\Util\HttpUtil::getSelfUrl()This function has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.  Loading history... | |||
| 121 | $s_url = substr($s_url, strrpos($s_url, '/') + 1); | ||
| 122 | if ('cache.test.php' == $s_url) { | ||
| 123 | $test = new TestCache(); | ||
| 124 | 	$test->run(new HtmlReporter('utf-8')); | ||
| 125 | } | ||
| 126 | // }}} | ||
| 127 | ?> | ||
| 0 ignored issues–
                            show It is not recommended to use PHP's closing tag  ?>in files other than templates.Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.  Loading history... | |||
| 128 | 
 
                                
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.