<commit_before><?php


/**
 * Tests for NeevoCache.
 */
class CacheTest extends PHPUnit_Framework_TestCase {


	private $filename = 'neevo.cache';


	public function getImplementations(){
		return array(
			array(new Neevo\Cache\MemoryStorage),
			array(new Neevo\Cache\SessionStorage),
			array(new Neevo\Cache\FileStorage($this->filename))
		);
	}


	/**
	 * @dataProvider getImplementations
	 */
	public function testBehaviour(Neevo\ICache $cache){
		$cache->store($k = 'key', $v = 'value');
		$this->assertEquals($v, $cache->fetch($k));

		if(method_exists($cache, 'flush')){
			$cache->flush();
			$this->assertNull($cache->fetch($k));
		}

		if($cache instanceof Neevo\Cache\FileStorage)
			unlink($this->filename);
	}


	public function testMemcache(){
		$memcache = new Memcache();
		$memcache->connect('localhost');
		$cache = new Neevo\Cache\MemcacheStorage($memcache);

		$cache->store($k = 'key', $v = 'value');
		$this->assertEquals($v, $cache->fetch($k));

		if(method_exists($cache, 'flush')){
			$cache->flush();
			$this->assertNull($cache->fetch($k));<commit_msg>[tests] Only test MemcacheStorage if memchache available<commit_after><?php


/**
 * Tests for NeevoCache.
 */
class CacheTest extends PHPUnit_Framework_TestCase {


	private $filename = 'neevo.cache';


	public function getImplementations(){
		return array(
			array(new Neevo\Cache\MemoryStorage),
			array(new Neevo\Cache\SessionStorage),
			array(new Neevo\Cache\FileStorage($this->filename))
		);
	}


	/**
	 * @dataProvider getImplementations
	 */
	public function testBehaviour(Neevo\ICache $cache){
		$cache->store($k = 'key', $v = 'value');
		$this->assertEquals($v, $cache->fetch($k));

		if(method_exists($cache, 'flush')){
			$cache->flush();
			$this->assertNull($cache->fetch($k));
		}

		if($cache instanceof Neevo\Cache\FileStorage)
			unlink($this->filename);
	}


	public function testMemcache(){
		// Memcache not available in Travis CI
		if(!class_exists('Memcache'))
			return;

		$memcache = new Memcache();
		$memcache->connect('localhost');
		$cache = new Neevo\Cache\MemcacheStorage($memcache);

		$cache->store($k = 'key', $v = 'value');
		$this->assertEquals($v, $cache->fetch($k));

		if(method_exists($cache, 'flush')){
			$cache->flush();
			$this->assertNull($cache->fetch($k));
{'fraction_non_alphanumeric': 0.1851528384279476, 'fraction_numerical': 0.0, 'mean_word_length': 4.699004975124378, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '88698', 'n_tokens_mistral': 851, 'n_tokens_neox': 742, 'n_words': 137}