This commit is contained in:
2022-11-25 21:21:30 +01:00
parent 2d6df0d5f0
commit 94deb06f52
132 changed files with 44887 additions and 41368 deletions

View File

@@ -1,4 +1,5 @@
<?php
/** DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
@@ -12,84 +13,83 @@ use Domframework\Cachefile;
/** Test the Cachefile.php file */
class CachefileTest extends \PHPUnit_Framework_TestCase
{
public function testInit ()
{
// Removing the cache file if it previously exists
exec ("rm -rf /tmp/cache");
}
public function testInit()
{
// Removing the cache file if it previously exists
exec("rm -rf /tmp/cache");
}
// Unknown cache file : return FALSE
public function testRead1 ()
{
$c = new Cachefile ();
$c->directory = "/tmp/cache";
$res = $c->read ("id");
$this->assertFalse ($res);
}
public function testRead1()
{
$c = new Cachefile();
$c->directory = "/tmp/cache";
$res = $c->read("id");
$this->assertFalse($res);
}
// Write in cache file
public function testWrite1 ()
{
$c = new Cachefile ();
$c->directory = "/tmp/cache";
$res = $c->write ("id","DATA_TO_STORE", 3);
$this->assertTrue ($res);
}
public function testWrite1()
{
$c = new Cachefile();
$c->directory = "/tmp/cache";
$res = $c->write("id", "DATA_TO_STORE", 3);
$this->assertTrue($res);
}
// Previous cache file : return DATA_TO_STORE
public function testRead2 ()
{
$c = new Cachefile ();
$c->directory = "/tmp/cache";
$res = $c->read ("id");
$this->assertSame ("DATA_TO_STORE", $res);
}
public function testRead2()
{
$c = new Cachefile();
$c->directory = "/tmp/cache";
$res = $c->read("id");
$this->assertSame("DATA_TO_STORE", $res);
}
// Sleep 4s to expire the cache
public function testWait1 ()
{
sleep (4);
}
public function testWait1()
{
sleep(4);
}
// Previous cache file but expired : return false
public function testRead3 ()
{
$c = new Cachefile ();
$c->directory = "/tmp/cache";
$res = $c->read ("id");
$this->assertFalse ($res);
}
public function testRead3()
{
$c = new Cachefile();
$c->directory = "/tmp/cache";
$res = $c->read("id");
$this->assertFalse($res);
}
// Write in cache file
public function testWrite2 ()
{
$c = new Cachefile ();
$c->directory = "/tmp/cache";
$res = $c->write ("id","DATA_TO_STORE", 30);
$this->assertTrue ($res);
}
public function testWrite2()
{
$c = new Cachefile();
$c->directory = "/tmp/cache";
$res = $c->write("id", "DATA_TO_STORE", 30);
$this->assertTrue($res);
}
// Create stale lock
public function testLock1 ()
{
touch ("/tmp/cache/".sha1 ("id").".lock");
}
public function testLock1()
{
touch("/tmp/cache/" . sha1("id") . ".lock");
}
// Previous cache in time file but lock : return content after lock timeout
// This test takes 10s to wait the lock which will never be released
public function testRead4 ()
{
$c = new Cachefile ();
$c->directory = "/tmp/cache";
$res = $c->read ("id");
$this->assertSame ("DATA_TO_STORE", $res);
}
public function testRead4()
{
$c = new Cachefile();
$c->directory = "/tmp/cache";
$res = $c->read("id");
$this->assertSame("DATA_TO_STORE", $res);
}
public function testDel1 ()
{
$c = new Cachefile ();
$c->directory = "/tmp/cache";
$res = $c->delete ("id");
}
public function testDel1()
{
$c = new Cachefile();
$c->directory = "/tmp/cache";
$res = $c->delete("id");
}
}