Exemplo n.º 1
0
 /**
  * https://github.com/yiisoft/yii/issues/2435
  */
 public function testEmbedExpiry()
 {
     $app = new TestApplication(array('id' => 'testApp', 'components' => array('cache' => array('class' => 'CFileCache'))));
     $app->reset();
     $cache = $app->cache;
     $cache->set('testKey1', 'testValue1', 2);
     $files = glob(Yii::getPathOfAlias('application.runtime.cache') . '/*.bin');
     $this->assertEquals(time() + 2, filemtime($files[0]));
     $cache->set('testKey2', 'testValue2', 2);
     sleep(1);
     $this->assertEquals('testValue2', $cache->get('testKey2'));
     $cache->set('testKey3', 'testValue3', 2);
     sleep(3);
     $this->assertEquals(false, $cache->get('testKey2'));
     $app = new TestApplication(array('id' => 'testApp', 'components' => array('cache' => array('class' => 'CFileCache', 'embedExpiry' => true))));
     $app->reset();
     $cache = $app->cache;
     $cache->set('testKey4', 'testValue4', 2);
     $files = glob(Yii::getPathOfAlias('application.runtime.cache') . '/*.bin');
     $this->assertEquals(time(), filemtime($files[0]));
     $cache->set('testKey5', 'testValue5', 2);
     sleep(1);
     $this->assertEquals('testValue5', $cache->get('testKey5'));
     $cache->set('testKey6', 'testValue6', 2);
     sleep(3);
     $this->assertEquals(false, $cache->get('testKey6'));
 }
 public function setUp()
 {
     if (!extension_loaded('pdo') || !extension_loaded('pdo_sqlite')) {
         $this->markTestSkipped('PDO and SQLite extensions are required.');
     }
     // clean up runtime directory
     $app = new TestApplication();
     $app->reset();
 }
Exemplo n.º 3
0
 public function testExpire()
 {
     $app = new TestApplication($this->_config1);
     $app->reset();
     $cache = $app->cache;
     $data = array('abc' => 1, 2 => 'def');
     $key = 'data3';
     $cache->set($key, $data, 2);
     $this->assertTrue($cache->get($key) === $data);
     sleep(4);
     $app2 = new TestApplication($this->_config1);
     $this->assertFalse($app2->cache->get($key));
 }
 public function testPublishFile()
 {
     $app = new TestApplication();
     $app->reset();
     $am = new CAssetManager();
     $am->init($app);
     $path1 = $am->getPublishedPath(__FILE__);
     clearstatcache();
     $this->assertFalse(is_file($path1));
     $url = $am->publish(__FILE__);
     $path2 = $am->getPublishedPath(__FILE__);
     $this->assertEquals($path1, $path2);
     clearstatcache();
     $this->assertTrue(is_file($path1));
     $this->assertEquals(basename($path1), basename(__FILE__));
     $this->assertEquals($url, $am->baseUrl . '/' . basename(dirname($path2)) . '/' . basename($path2));
 }
Exemplo n.º 5
0
 public function setUp()
 {
     // clean up runtime directory
     $app = new TestApplication();
     $app->reset();
 }
Exemplo n.º 6
0
 public function testExpire2()
 {
     $app = new TestApplication($this->_config);
     $app->reset();
     $cache = $app->cache;
     $data = array('xyz' => 3, 4 => 'mnp');
     $key = 'data3_2';
     $cache->set($key, $data, 5);
     $this->assertTrue($cache->get($key) === $data);
     sleep(2);
     $app2 = new TestApplication($this->_config);
     $this->assertEquals($data, $app2->cache->get($key));
 }