Skip to content

Commit

Permalink
test: Added More Tests to Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Nov 27, 2024
1 parent 434fd72 commit 277fed8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<file>./webfiori/framework/router/Router.php</file>

<file>./webfiori/framework/cache/AbstractCacheStore.php</file>
<file>./webfiori/framework/cache/FileCacheStore.php</file>
<file>./webfiori/framework/cache/FileStorage.php</file>
<file>./webfiori/framework/cache/Cache.php</file>

<file>./webfiori/framework/session/Session.php</file>
Expand Down
59 changes: 59 additions & 0 deletions tests/webfiori/framework/test/cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CacheTest extends TestCase {
*/
public function test00() {
$key = 'first';
$this->assertTrue(Cache::isEnabled());
$data = Cache::get($key, function () {
return 'This is a test.';
});
Expand Down Expand Up @@ -84,4 +85,62 @@ public function test05() {
$this->assertFalse(Cache::has($key));
}
}
/**
* @test
*/
public function test06() {
$key = 'bbuu';
$this->assertTrue(Cache::isEnabled());
Cache::setEnabled(false);
$data = Cache::get($key, function () {
return 'This is a test.';
});
$this->assertEquals('This is a test.', $data);
$this->assertNull(Cache::get($key));
$this->assertFalse(Cache::isEnabled());
}
/**
* @test
*/
public function testSet00() {
$key = 'new_cool_key';
Cache::setEnabled(true);
$this->assertTrue(Cache::isEnabled());
$this->assertTrue(Cache::set($key, 'This is a test.', 60, false));
$this->assertEquals('This is a test.', Cache::get($key));
$item = Cache::getItem($key);
$this->assertEquals(60, $item->getTTL());

$this->assertFalse(Cache::set($key, 'This is a test.', 60, false));
$this->assertEquals('This is a test.', Cache::get($key));
$item = Cache::getItem($key);
$this->assertEquals(60, $item->getTTL());

$this->assertTrue(Cache::set($key, 'This is a test 2.', 660, true));
$this->assertEquals('This is a test 2.', Cache::get($key));
$item = Cache::getItem($key);
$this->assertEquals(660, $item->getTTL());
}
/**
* @test
*/
public function testSetTTL00() {
$key = 'new_cool_key2';
Cache::setEnabled(true);
$this->assertTrue(Cache::isEnabled());
$this->assertTrue(Cache::set($key, 'This is a test.', 60, false));
$item = Cache::getItem($key);
$this->assertEquals(60, $item->getTTL());
Cache::setTTL($key, 700);

$item = Cache::getItem($key);
$this->assertEquals(700, $item->getTTL());
}
/**
* @test
*/
public function testSetTTL01() {
$key = 'not exist cool';
$this->assertFalse(Cache::setTTL($key, 700));
}
}

0 comments on commit 277fed8

Please sign in to comment.