<commit_before><?php

class CacheTest extends \Codeception\TestCase\Test
{
	public function _before()
	{
		if (!Rhymix\Framework\Config::get('crypto.authentication_key'))
		{
			Rhymix\Framework\Config::set('crypto.authentication_key', Rhymix\Framework\Security::getRandom(64, 'alnum'));
		}
	}
	
	public function _after()
	{
		$driver = Rhymix\Framework\Cache::clearAll();
	}
	
	public function testInit()
	{
		$driver = Rhymix\Framework\Cache::init(array('type' => 'dummy'));
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\Dummy);
		
		$driver = Rhymix\Framework\Cache::init(array('type' => 'file'));
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
		
		$driver = Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\SQLite);
		
		$driver = Rhymix\Framework\Cache::init(array());
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
	}
	
	public function testGetSupportedDrivers()
	{
		$drivers = Rhymix\Framework\Cache::getSupportedDrivers();
		$this->assertTrue(is_array($drivers));
		$this->assertContains('dummy', $drivers);
		$this->assertContains('file', $drivers);
		$this->assertContains('sqlite', $drivers);
	}
	
	public function testGetCacheDriver()
	{
		$driver = Rhymix\Framework\Cache::getCacheDriver('dummy');
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\Dummy);
		
		$driver = Rhymix\Framework\Cache::getCacheDriver();
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
	}
	
	public function testGetCachePrefix()
	{
		$driver = Rhymix\Framework\Cache::init(array('type' => 'dummy'));
		$prefix = Rhymix\Framework\Cache::getCachePrefix();
		$this->assertEquals(substr(sha1(\RX_BASEDIR), 0, 10) . ':' . \RX_VERSION . ':', $prefix);
		
		$driver = Rhymix\Framework\Cache::init(array());
		$prefix = Rhymix\Framework\Cache::getCachePrefix();
		$this->assertEquals(\RX_VERSION . ':', $prefix);
	}
	
	public function testGetSet()
	{
		$value = true;
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar1', $value));
		$this->assertTrue(Rhymix\Framework\Cache::get('foobar1'));
		
		$value = false;
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar2', $value));
		$this->assertFalse(Rhymix\Framework\Cache::get('foobar2'));
		
		$value = 1756234;
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar3', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar3'));
		
		$value = 'Rhymix is a PHP CMS.';
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar4', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar4'));
		
		$value = array('foo' => 'bar', 'rhy' => 'mix');
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:5', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar:subkey:5'));
		
		$value = (object)array('foo' => 'bar', 'rhy' => 'mix');
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:6', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar:subkey:6'));
		
		$this->assertNull(Rhymix\Framework\Cache::get('foobar7'));
		$this->assertNull(Rhymix\Framework\Cache::get('foobar:subkey:8'));
	}
	
	public function testDeleteAndExists()
	{
		Rhymix\Framework\Cache::set('foo', 'FOO');
		Rhymix\Framework\Cache::set('bar', 'BAR');
		
		$this->assertTrue(Rhymix\Framework\Cache::delete('foo'));
		$this->assertFalse(Rhymix\Framework\Cache::delete('foo'));
		$this->assertFalse(Rhymix\Framework\Cache::exists('foo'));
		$this->assertTrue(Rhymix\Framework\Cache::exists('bar'));
	}
	
	public function testIncrDecr()
	{
		Rhymix\Framework\Cache::set('foo', 'foo');
		Rhymix\Framework\Cache::set('bar', 42);
		$prefix = Rhymix\Framework\Cache::getCachePrefix();
		
		$this->assertEquals(1, Rhymix\Framework\Cache::getCacheDriver()->incr($prefix . 'foo', 1));<commit_msg>Avoid inconsistent file cache test results in HHVM<commit_after><?php

class CacheTest extends \Codeception\TestCase\Test
{
	public function _before()
	{
		if (!Rhymix\Framework\Config::get('crypto.authentication_key'))
		{
			Rhymix\Framework\Config::set('crypto.authentication_key', Rhymix\Framework\Security::getRandom(64, 'alnum'));
		}
	}
	
	public function _after()
	{
		$driver = Rhymix\Framework\Cache::clearAll();
	}
	
	public function testInit()
	{
		$driver = Rhymix\Framework\Cache::init(array('type' => 'dummy'));
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\Dummy);
		
		$driver = Rhymix\Framework\Cache::init(array('type' => 'file'));
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
		
		$driver = Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\SQLite);
		
		$driver = Rhymix\Framework\Cache::init(array());
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
	}
	
	public function testGetSupportedDrivers()
	{
		$drivers = Rhymix\Framework\Cache::getSupportedDrivers();
		$this->assertTrue(is_array($drivers));
		$this->assertContains('dummy', $drivers);
		$this->assertContains('file', $drivers);
		$this->assertContains('sqlite', $drivers);
	}
	
	public function testGetCacheDriver()
	{
		$driver = Rhymix\Framework\Cache::getCacheDriver('dummy');
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\Dummy);
		
		$driver = Rhymix\Framework\Cache::getCacheDriver();
		$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
	}
	
	public function testGetCachePrefix()
	{
		$driver = Rhymix\Framework\Cache::init(array('type' => 'dummy'));
		$prefix = Rhymix\Framework\Cache::getCachePrefix();
		$this->assertEquals(substr(sha1(\RX_BASEDIR), 0, 10) . ':' . \RX_VERSION . ':', $prefix);
		
		$driver = Rhymix\Framework\Cache::init(array());
		$prefix = Rhymix\Framework\Cache::getCachePrefix();
		$this->assertEquals(\RX_VERSION . ':', $prefix);
	}
	
	public function testGetSet()
	{
		$value = true;
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar1', $value));
		$this->assertTrue(Rhymix\Framework\Cache::get('foobar1'));
		
		$value = false;
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar2', $value));
		$this->assertFalse(Rhymix\Framework\Cache::get('foobar2'));
		
		$value = 1756234;
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar3', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar3'));
		
		$value = 'Rhymix is a PHP CMS.';
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar4', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar4'));
		
		$value = array('foo' => 'bar', 'rhy' => 'mix');
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:5', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar:subkey:5'));
		
		$value = (object)array('foo' => 'bar', 'rhy' => 'mix');
		$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:6', $value));
		$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar:subkey:6'));
		
		$this->assertNull(Rhymix\Framework\Cache::get('foobar7'));
		$this->assertNull(Rhymix\Framework\Cache::get('foobar:subkey:8'));
	}
	
	public function testDeleteAndExists()
	{
		Rhymix\Framework\Cache::set('foo', 'FOO');
		Rhymix\Framework\Cache::set('bar', 'BAR');
		
		$this->assertTrue(Rhymix\Framework\Cache::delete('foo'));
		$this->assertFalse(Rhymix\Framework\Cache::delete('foo'));
		$this->assertFalse(Rhymix\Framework\Cache::exists('foo'));
		$this->assertTrue(Rhymix\Framework\Cache::exists('bar'));
	}
	
	public function testIncrDecr()
	{
		Rhymix\Framework\Cache::init(array('type' => 'dummy'));
		Rhymix\Framework\Cache::set('foo', 'foo');
		Rhymix\Framework\Cache::set('bar', 42);
		$prefix = Rhymix\Framework\Cache::getCachePrefix();
		
		$this->assertEquals(1, Rhymix\Framework\Cache::getCacheDriver()->incr($prefix . 'foo', 1));
{'fraction_non_alphanumeric': 0.1984858044164038, 'fraction_numerical': 0.007823343848580442, 'mean_word_length': 5.95873573309921, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 84, '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': '5089585', 'n_tokens_mistral': 3008, 'n_tokens_neox': 2683, 'n_words': 330}