Kohana v3.3.5
This commit is contained in:
@@ -164,6 +164,17 @@ TESTTEXT;
|
||||
),
|
||||
'foo bar snafu'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'id' => 'test ttl 0 means never expire',
|
||||
'value' => 'cache value that should last',
|
||||
'ttl' => 0,
|
||||
'wait' => 1,
|
||||
'type' => 'string',
|
||||
'default' => NULL
|
||||
),
|
||||
'cache value that should last'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'id' => 'bar',
|
||||
@@ -196,6 +207,28 @@ TESTTEXT;
|
||||
'default' => NULL,
|
||||
),
|
||||
$html_text
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'id' => 'test with 60*5',
|
||||
'value' => 'blabla',
|
||||
'ttl' => 60*5,
|
||||
'wait' => FALSE,
|
||||
'type' => 'string',
|
||||
'default' => NULL,
|
||||
),
|
||||
'blabla'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'id' => 'test with 60*50',
|
||||
'value' => 'bla bla',
|
||||
'ttl' => 60*50,
|
||||
'wait' => FALSE,
|
||||
'type' => 'string',
|
||||
'default' => NULL,
|
||||
),
|
||||
'bla bla'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
9
modules/cache/tests/cache/CacheTest.php
vendored
9
modules/cache/tests/cache/CacheTest.php
vendored
@@ -90,14 +90,13 @@ class Kohana_CacheTest extends PHPUnit_Framework_TestCase {
|
||||
*/
|
||||
public function test_cloning_fails()
|
||||
{
|
||||
if ( ! Kohana::$config->load('cache.file'))
|
||||
{
|
||||
$this->markTestSkipped('Unable to load File configuration');
|
||||
}
|
||||
$cache = $this->getMockBuilder('Cache')
|
||||
->disableOriginalConstructor()
|
||||
->getMockForAbstractClass();
|
||||
|
||||
try
|
||||
{
|
||||
$cache_clone = clone(Cache::instance('file'));
|
||||
clone($cache);
|
||||
}
|
||||
catch (Cache_Exception $e)
|
||||
{
|
||||
|
69
modules/cache/tests/cache/FileTest.php
vendored
69
modules/cache/tests/cache/FileTest.php
vendored
@@ -30,7 +30,21 @@ class Kohana_Cache_FileTest extends Kohana_CacheBasicMethodsTest {
|
||||
|
||||
if ( ! Kohana::$config->load('cache.file'))
|
||||
{
|
||||
$this->markTestSkipped('Unable to load File configuration');
|
||||
Kohana::$config->load('cache')
|
||||
->set(
|
||||
'file',
|
||||
array(
|
||||
'driver' => 'file',
|
||||
'cache_dir' => APPPATH.'cache',
|
||||
'default_expire' => 3600,
|
||||
'ignore_on_delete' => array(
|
||||
'file_we_want_to_keep.cache',
|
||||
'.gitignore',
|
||||
'.git',
|
||||
'.svn'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->cache(Cache::instance('file'));
|
||||
@@ -45,7 +59,7 @@ class Kohana_Cache_FileTest extends Kohana_CacheBasicMethodsTest {
|
||||
{
|
||||
$cache = $this->cache();
|
||||
$config = Kohana::$config->load('cache')->file;
|
||||
$file = $config['cache_dir'].'/.gitignore';
|
||||
$file = $config['cache_dir'].'/file_we_want_to_keep.cache';
|
||||
|
||||
// Lets pollute the cache folder
|
||||
file_put_contents($file, 'foobar');
|
||||
@@ -95,4 +109,55 @@ class Kohana_Cache_FileTest extends Kohana_CacheBasicMethodsTest {
|
||||
$this->assertSame($expected, $cache->get('utf8'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests garbage collection.
|
||||
* Tests if non-expired cache files withstand garbage collection
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function test_garbage_collection()
|
||||
{
|
||||
$cache = $this->cache();
|
||||
$cache->set('persistent', 'dummy persistent data', 3);
|
||||
$cache->set('volatile', 'dummy volatile data', 1);
|
||||
|
||||
$this->assertTrue($this->is_file('persistent'));
|
||||
$this->assertTrue($this->is_file('volatile'));
|
||||
|
||||
// sleep for more than a second
|
||||
sleep(2);
|
||||
|
||||
$cache->garbage_collect();
|
||||
|
||||
$this->assertTrue($this->is_file('persistent'));
|
||||
$this->assertFalse($this->is_file('volatile'));
|
||||
}
|
||||
|
||||
/**
|
||||
* helper method for test_garbage_collection.
|
||||
* Tests if cache file exists given cache id.
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean TRUE if file exists FALSE otherwise
|
||||
*/
|
||||
protected function is_file($id)
|
||||
{
|
||||
$cache = $this->cache();
|
||||
|
||||
$method_sanitize_id = new ReflectionMethod($cache, '_sanitize_id');
|
||||
$method_sanitize_id->setAccessible(TRUE);
|
||||
$method_filename = new ReflectionMethod($cache, 'filename');
|
||||
$method_filename->setAccessible(TRUE);
|
||||
$method_resolve_directory = new ReflectionMethod($cache, '_resolve_directory');
|
||||
$method_resolve_directory->setAccessible(TRUE);
|
||||
|
||||
$sanitized_id = $method_sanitize_id->invoke($cache, $id);
|
||||
$filename = $method_filename->invoke($cache, $sanitized_id);
|
||||
$directory = $method_resolve_directory->invoke($cache, $filename);
|
||||
|
||||
$file = new SplFileInfo($directory.$filename);
|
||||
|
||||
//var_dump($cache->_is_expired($file));
|
||||
return $file->isFile();
|
||||
}
|
||||
} // End Kohana_SqliteTest
|
||||
|
11
modules/cache/tests/cache/SqliteTest.php
vendored
11
modules/cache/tests/cache/SqliteTest.php
vendored
@@ -35,7 +35,16 @@ class Kohana_SqliteTest extends Kohana_CacheBasicMethodsTest {
|
||||
|
||||
if ( ! Kohana::$config->load('cache.sqlite'))
|
||||
{
|
||||
$this->markTestIncomplete('Unable to load sqlite configuration');
|
||||
Kohana::$config->load('cache')
|
||||
->set(
|
||||
'sqlite',
|
||||
array(
|
||||
'driver' => 'sqlite',
|
||||
'default_expire' => 3600,
|
||||
'database' => 'memory',
|
||||
'schema' => 'CREATE TABLE caches(id VARCHAR(127) PRIMARY KEY, tags VARCHAR(255), expiration INTEGER, cache TEXT)',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->cache(Cache::instance('sqlite'));
|
||||
|
72
modules/cache/tests/cache/WincacheTest.php
vendored
72
modules/cache/tests/cache/WincacheTest.php
vendored
@@ -1,39 +1,49 @@
|
||||
<?php
|
||||
include_once(Kohana::find_file('tests/cache', 'CacheBasicMethodsTest'));
|
||||
|
||||
/**
|
||||
* @package Kohana/Cache
|
||||
* @group kohana
|
||||
* @group kohana.cache
|
||||
* @category Test
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2009-2012 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
class Kohana_WincacheTest extends Kohana_CacheBasicMethodsTest {
|
||||
if (isset($_ENV['TRAVIS']))
|
||||
{
|
||||
// This is really hacky, but without it the result is permanently full of noise that makes it impossible to see
|
||||
// any unexpected skipped tests.
|
||||
print "Skipping all Wincache driver tests as these will never run on Travis.".\PHP_EOL;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
include_once(Kohana::find_file('tests/cache', 'CacheBasicMethodsTest'));
|
||||
|
||||
/**
|
||||
* This method MUST be implemented by each driver to setup the `Cache`
|
||||
* instance for each test.
|
||||
*
|
||||
* This method should do the following tasks for each driver test:
|
||||
*
|
||||
* - Test the Cache instance driver is available, skip test otherwise
|
||||
* - Setup the Cache instance
|
||||
* - Call the parent setup method, `parent::setUp()`
|
||||
*
|
||||
* @return void
|
||||
* @package Kohana/Cache
|
||||
* @group kohana
|
||||
* @group kohana.cache
|
||||
* @category Test
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2009-2012 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
class Kohana_WincacheTest extends Kohana_CacheBasicMethodsTest {
|
||||
|
||||
if ( ! extension_loaded('wincache'))
|
||||
/**
|
||||
* This method MUST be implemented by each driver to setup the `Cache`
|
||||
* instance for each test.
|
||||
*
|
||||
* This method should do the following tasks for each driver test:
|
||||
*
|
||||
* - Test the Cache instance driver is available, skip test otherwise
|
||||
* - Setup the Cache instance
|
||||
* - Call the parent setup method, `parent::setUp()`
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->markTestSkipped('Wincache PHP Extension is not available');
|
||||
parent::setUp();
|
||||
|
||||
if ( ! extension_loaded('wincache'))
|
||||
{
|
||||
$this->markTestSkipped('Wincache PHP Extension is not available');
|
||||
}
|
||||
|
||||
$this->cache(Cache::instance('wincache'));
|
||||
}
|
||||
|
||||
$this->cache(Cache::instance('wincache'));
|
||||
}
|
||||
|
||||
} // End Kohana_WincacheTest
|
||||
} // End Kohana_WincacheTest
|
||||
}
|
||||
|
14
modules/cache/tests/cache/arithmetic/ApcTest.php
vendored
14
modules/cache/tests/cache/arithmetic/ApcTest.php
vendored
@@ -39,6 +39,18 @@ class Kohana_ApcTest extends Kohana_CacheArithmeticMethodsTest {
|
||||
'place "apc.enable_cli=1" in your php.ini file');
|
||||
}
|
||||
|
||||
if ( ! Kohana::$config->load('cache.apc'))
|
||||
{
|
||||
Kohana::$config->load('cache')
|
||||
->set(
|
||||
'apc',
|
||||
array(
|
||||
'driver' => 'apc',
|
||||
'default_expire' => 3600,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->cache(Cache::instance('apc'));
|
||||
}
|
||||
|
||||
@@ -57,7 +69,7 @@ class Kohana_ApcTest extends Kohana_CacheArithmeticMethodsTest {
|
||||
*
|
||||
* @dataProvider provider_set_get
|
||||
*
|
||||
* @param array data
|
||||
* @param array data
|
||||
* @param mixed expected
|
||||
* @return void
|
||||
*/
|
||||
|
87
modules/cache/tests/cache/arithmetic/ApcuTest.php
vendored
Normal file
87
modules/cache/tests/cache/arithmetic/ApcuTest.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
include_once(Kohana::find_file('tests/cache/arithmetic', 'CacheArithmeticMethods'));
|
||||
|
||||
/**
|
||||
* @package Kohana/Cache
|
||||
* @group kohana
|
||||
* @group kohana.cache
|
||||
* @category Test
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2009-2012 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
class Kohana_ApcuTest extends Kohana_CacheArithmeticMethodsTest {
|
||||
|
||||
/**
|
||||
* This method MUST be implemented by each driver to setup the `Cache`
|
||||
* instance for each test.
|
||||
*
|
||||
* This method should do the following tasks for each driver test:
|
||||
*
|
||||
* - Test the Cache instance driver is available, skip test otherwise
|
||||
* - Setup the Cache instance
|
||||
* - Call the parent setup method, `parent::setUp()`
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if ( ! extension_loaded('apcu'))
|
||||
{
|
||||
$this->markTestSkipped('APCu PHP Extension is not available');
|
||||
}
|
||||
|
||||
if ( ! (ini_get('apc.enabled') AND ini_get('apc.enable_cli')))
|
||||
{
|
||||
$this->markTestSkipped('APCu is not enabled. To fix '.
|
||||
'set "apc.enabled=1" and "apc.enable_cli=1" in your php.ini file');
|
||||
}
|
||||
|
||||
if ( ! Kohana::$config->load('cache.apcu'))
|
||||
{
|
||||
Kohana::$config->load('cache')
|
||||
->set(
|
||||
'apcu',
|
||||
array(
|
||||
'driver' => 'apcu',
|
||||
'default_expire' => 3600,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->cache(Cache::instance('apcu'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the [Cache::set()] method, testing;
|
||||
*
|
||||
* - The value is cached
|
||||
* - The lifetime is respected
|
||||
* - The returned value type is as expected
|
||||
* - The default not-found value is respected
|
||||
*
|
||||
* This test doesn't test the TTL as there is a known bug/feature
|
||||
* in APCu that prevents the same request from killing cache on timeout.
|
||||
*
|
||||
* @link http://pecl.php.net/bugs/bug.php?id=16814
|
||||
*
|
||||
* @dataProvider provider_set_get
|
||||
*
|
||||
* @param array data
|
||||
* @param mixed expected
|
||||
* @return void
|
||||
*/
|
||||
public function test_set_get(array $data, $expected)
|
||||
{
|
||||
if ($data['wait'] !== FALSE)
|
||||
{
|
||||
$this->markTestSkipped('Unable to perform TTL test in CLI, see: '.
|
||||
'http://pecl.php.net/bugs/bug.php?id=16814 for more info!');
|
||||
}
|
||||
|
||||
parent::test_set_get($data, $expected);
|
||||
}
|
||||
|
||||
} // End Kohana_ApcuTest
|
@@ -35,7 +35,28 @@ class Kohana_CacheArithmeticMemcacheTest extends Kohana_CacheArithmeticMethodsTe
|
||||
}
|
||||
if ( ! $config = Kohana::$config->load('cache.memcache'))
|
||||
{
|
||||
$this->markTestSkipped('Unable to load Memcache configuration');
|
||||
Kohana::$config->load('cache')
|
||||
->set(
|
||||
'memcache',
|
||||
array(
|
||||
'driver' => 'memcache',
|
||||
'default_expire' => 3600,
|
||||
'compression' => FALSE, // Use Zlib compression (can cause issues with integers)
|
||||
'servers' => array(
|
||||
'local' => array(
|
||||
'host' => 'localhost', // Memcache Server
|
||||
'port' => 11211, // Memcache port number
|
||||
'persistent' => FALSE, // Persistent connection
|
||||
'weight' => 1,
|
||||
'timeout' => 1,
|
||||
'retry_interval' => 15,
|
||||
'status' => TRUE,
|
||||
),
|
||||
),
|
||||
'instant_death' => TRUE,
|
||||
)
|
||||
);
|
||||
$config = Kohana::$config->load('cache.memcache');
|
||||
}
|
||||
|
||||
$memcache = new Memcache;
|
||||
|
Reference in New Issue
Block a user