seb7
(Sebastienmonterisi)
September 27, 2012, 3:47pm
1
Hi,
I writing a unit test to test that a function return a cached result but caching doesn’t seems to work at all. (and it’s ok if i put the code in a controller).
// additionnal memcache component.
Yii::app()->memcache->set('ki', 'val', 0);
$this->assertEquals(Yii::app()->memcache->get('ki'), 'val');
Yii::app()->cache->set('ki', 'val', 0);
$this->assertEquals(Yii::app()->cache->get('ki'), 'val');
Any ideas why it fails ?
seb7
(Sebastienmonterisi)
September 27, 2012, 7:21pm
2
well I fixed the file caching. It was just a question of write access to the cache folder.
Now looking for a solution for the memcache (APC cache) …
seb7
(Sebastienmonterisi)
September 27, 2012, 7:49pm
3
Everythings is ok.
First : run test as the same user as the webserver does (www most of the time) with command (freebsd 8 )
su -m www -c 'phpunit unit/tmpTest.php'
So i do not need to change the rights on cache folder.
For Apc cache, change a config var :
apc.enable_cli=On
in php configuration file.
public function testCache()
{
$this->assertTrue( Yii::app()->memcache->set('ki', 'val', 20) );
$this->assertEquals(Yii::app()->memcache->get('ki'), 'val');
$this->assertTrue( Yii::app()->cache->set('ki', 'val', 20) ) ;
$this->assertEquals(Yii::app()->cache->get('ki'), 'val');
}
[color="#2E8B57 "]OK (1 test, 4 assertions)[/color]