Rename cacheFileTest in cachefileTest
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1554 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
82
Tests/cachefileTest.php
Normal file
82
Tests/cachefileTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/** DomFramework - Tests
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
|
||||
/** Test the cache.php file */
|
||||
class test_cacheFile extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function __construct ()
|
||||
{
|
||||
// Removing the cache file if it previously exists
|
||||
$c = new cacheFile ();
|
||||
$res = $c->delete ("id");
|
||||
}
|
||||
|
||||
// Unknown cache file : return FALSE
|
||||
public function testRead1 ()
|
||||
{
|
||||
$c = new cacheFile ();
|
||||
$res = $c->read ("id");
|
||||
$this->assertFalse ($res);
|
||||
}
|
||||
|
||||
// Write in cache file
|
||||
public function testWrite1 ()
|
||||
{
|
||||
$c = new cacheFile ();
|
||||
$res = $c->write ("id","DATA_TO_STORE", 3);
|
||||
$this->assertTrue ($res);
|
||||
}
|
||||
|
||||
// Previous cache file : return DATA_TO_STORE
|
||||
public function testRead2 ()
|
||||
{
|
||||
$c = new cacheFile ();
|
||||
$res = $c->read ("id");
|
||||
$this->assertEquals ("DATA_TO_STORE", $res);
|
||||
}
|
||||
|
||||
// Sleep 3s to expire the cache
|
||||
public function testWait1 ()
|
||||
{
|
||||
sleep (4);
|
||||
}
|
||||
|
||||
// Previous cache file but expired : return false
|
||||
public function testRead3 ()
|
||||
{
|
||||
$c = new cacheFile ();
|
||||
$res = $c->read ("id");
|
||||
$this->assertFalse ($res);
|
||||
}
|
||||
|
||||
// Write in cache file
|
||||
public function testWrite2 ()
|
||||
{
|
||||
$c = new cacheFile ();
|
||||
$res = $c->write ("id","DATA_TO_STORE", 30);
|
||||
$this->assertTrue ($res);
|
||||
}
|
||||
|
||||
// Create stale lock
|
||||
public function testLock1 ()
|
||||
{
|
||||
touch ("cache/".sha1 ("id").".lock");
|
||||
}
|
||||
|
||||
// Previous cache in time file but lock : return content after lock timeout
|
||||
public function testRead4 ()
|
||||
{
|
||||
$c = new cacheFile ();
|
||||
$res = $c->read ("id");
|
||||
$this->assertEquals ("DATA_TO_STORE", $res);
|
||||
}
|
||||
|
||||
public function testDel1 ()
|
||||
{
|
||||
$c = new cacheFile ();
|
||||
$res = $c->delete ("id");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user