Exemplo n.º 1
0
 public function test_different_caches_have_different_prefixes()
 {
     $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test');
     $instance = new cachestore_apcu('Test', cachestore_apcu::unit_test_configuration());
     $instance->initialise($definition);
     $definition2 = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test2');
     $instance2 = new cachestore_apcu('Test', cachestore_apcu::unit_test_configuration());
     $instance2->initialise($definition2);
     $instance->set('test1', 1);
     $this->assertFalse($instance2->get('test1'));
     $instance2->purge();
     $this->assertSame(1, $instance->get('test1'));
 }
Exemplo n.º 2
0
 /**
  * Test purging the apcu cache store.
  */
 public function test_purge()
 {
     if (!cachestore_apcu::are_requirements_met()) {
         $this->markTestSkipped('Could not test cachestore_apcu. Requirements are not met.');
     }
     $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test');
     $instance = cachestore_apcu::initialise_unit_test_instance($definition);
     // Test a simple purge return.
     $this->assertTrue($instance->purge());
     // Test purge works.
     $this->assertTrue($instance->set('test', 'monster'));
     $this->assertSame('monster', $instance->get('test'));
     $this->assertTrue($instance->purge());
     $this->assertFalse($instance->get('test'));
     // Test purge with custom data.
     $this->assertTrue($instance->set('test', 'monster'));
     $this->assertSame('monster', $instance->get('test'));
     $this->assertTrue(apcu_store('test', 'pirate', 180));
     $this->assertSame('monster', $instance->get('test'));
     $this->assertTrue(apcu_exists('test'));
     $this->assertSame('pirate', apcu_fetch('test'));
     // Purge and check that our data is gone but the the custom data is still there.
     $this->assertTrue($instance->purge());
     $this->assertFalse($instance->get('test'));
     $this->assertTrue(apcu_exists('test'));
     $this->assertSame('pirate', apcu_fetch('test'));
 }
Exemplo n.º 3
0
Arquivo: lib.php Projeto: dg711/moodle
 /**
  * Generates an instance of the cache store that can be used for testing.
  *
  * @param cache_definition $definition
  * @return cachestore_apcu|false
  */
 public static function initialise_unit_test_instance(cache_definition $definition)
 {
     if (!self::are_requirements_met()) {
         return false;
     }
     $store = new cachestore_apcu('Test APCu', array('prefix' => 'phpunit'));
     if (!$store->is_ready()) {
         return false;
     }
     $store->initialise($definition);
     return $store;
 }
Exemplo n.º 4
0
 /**
  * Generates an instance of the cache store that can be used for testing.
  *
  * @param cache_definition $definition
  * @return cachestore_apcu|false
  */
 public static function initialise_unit_test_instance(cache_definition $definition)
 {
     if (!self::are_requirements_met()) {
         return false;
     }
     if (!defined('TEST_CACHESTORE_APCU')) {
         return false;
     }
     $store = new cachestore_apcu('Test APCu', array());
     if (!$store->is_ready()) {
         return false;
     }
     $store->initialise($definition);
     return $store;
 }
Exemplo n.º 5
0
 /**
  * Generates an instance of the cache store that can be used for testing.
  *
  * Returns an instance of the cache store, or false if one cannot be created.
  *
  * @param cache_definition $definition
  * @return cache_store
  */
 public static function initialise_test_instance(cache_definition $definition)
 {
     $testperformance = get_config('cachestore_apcu', 'testperformance');
     if (empty($testperformance)) {
         return false;
     }
     if (!self::are_requirements_met()) {
         return false;
     }
     $name = 'APCu test';
     $cache = new cachestore_apcu($name);
     // No need to check if is_ready() as this has already being done by requirement check.
     $cache->initialise($definition);
     return $cache;
 }