Skip to content

Commit 0145be3

Browse files
authored
Merge pull request #3 from hmerritt/v1.0.1
Added unit tests for Cache functions
2 parents 3eb94dc + 18aeb9e commit 0145be3

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"php-coveralls/php-coveralls": "^2.2"
2121
},
2222
"scripts": {
23-
"test": "php vendor/phpunit/phpunit/phpunit",
24-
"test-coverage": "php vendor/phpunit/phpunit/phpunit --coverage-clover build/logs/clover.xml"
23+
"test": "php vendor/phpunit/phpunit/phpunit"
2524
},
2625
"autoload": {
2726
"psr-4": {

src/Cache.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ public function add(string $key, $value)
4343
return true;
4444
}
4545

46-
/**
47-
* Counts all files in the cache
48-
*
49-
* @return int
50-
*/
51-
public function count(): int
52-
{
53-
return $this->cache->count();
54-
}
55-
5646
/**
5747
* Deletes an item from the cache
5848
*

tests/CacheTest.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,40 @@
77

88
class CacheTest extends TestCase {
99

10-
public function testCache()
10+
public function testAddToCache()
1111
{
1212
$cache = new Cache;
13-
$cache_testStore = [
13+
$testData = [
1414
"title" => "Interstellar"
1515
];
1616

17-
$cache->add("test", $cache_testStore);
18-
$cache_testFile = $cache->get("test");
17+
$cache->add("test", $testData);
18+
$testFile = $cache->get("test");
1919

20-
$this->assertEquals($cache_testStore, $cache_testFile->film);
20+
$this->assertEquals($testData, $testFile->film);
21+
22+
$cache->delete("test");
23+
}
24+
25+
public function testHasCache()
26+
{
27+
$cache = new Cache;
28+
$cache->add("testHas", [ "test" => "has" ]);
29+
30+
$this->assertEquals(true, $cache->has("testHas"));
31+
$this->assertEquals(false, $cache->has("testHasNot"));
32+
33+
$cache->delete("testHas");
34+
}
35+
36+
public function testDeleteFromCache()
37+
{
38+
$cache = new Cache;
39+
$cache->add("testHas", [ "test" => "has" ]);
40+
41+
$this->assertEquals(true, $cache->has("testHas"));
42+
$cache->delete("testHas");
43+
$this->assertEquals(false, $cache->has("testHas"));
2144
}
2245

2346
}

0 commit comments

Comments
 (0)