| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/(Del)gepgroup.hk/php-activerecord/test/ |
Upload File : |
<?php
include 'helpers/config.php';
use ActiveRecord\Cache;
class CacheTest extends SnakeCase_PHPUnit_Framework_TestCase
{
public function set_up()
{
if (!extension_loaded('memcache'))
{
$this->markTestSkipped('The memcache extension is not available');
return;
}
Cache::initialize('memcache://localhost');
}
public function tear_down()
{
Cache::flush();
}
private function cache_get()
{
return Cache::get("1337", function() { return "abcd"; });
}
public function test_initialize()
{
$this->assert_not_null(Cache::$adapter);
}
public function test_initialize_with_null()
{
Cache::initialize(null);
$this->assert_null(Cache::$adapter);
}
public function test_get_returns_the_value()
{
$this->assert_equals("abcd", $this->cache_get());
}
public function test_get_writes_to_the_cache()
{
$this->cache_get();
$this->assert_equals("abcd", Cache::$adapter->read("1337"));
}
public function test_get_does_not_execute_closure_on_cache_hit()
{
$this->cache_get();
Cache::get("1337", function() { throw new Exception("I better not execute!"); });
}
public function test_cache_adapter_returns_false_on_cache_miss()
{
$this->assert_same(false, Cache::$adapter->read("some-key"));
}
public function test_get_works_without_caching_enabled()
{
Cache::$adapter = null;
$this->assert_equals("abcd", $this->cache_get());
}
public function test_cache_expire()
{
Cache::$options['expire'] = 1;
$this->cache_get();
sleep(2);
$this->assert_same(false, Cache::$adapter->read("1337"));
}
public function test_namespace_is_set_properly()
{
Cache::$options['namespace'] = 'myapp';
$this->cache_get();
$this->assert_same("abcd", Cache::$adapter->read("myapp::1337"));
}
}
?>