-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCacheDatabaseTest.php
More file actions
149 lines (113 loc) · 3.76 KB
/
CacheDatabaseTest.php
File metadata and controls
149 lines (113 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace Bow\Tests\Cache;
use Bow\Cache\Cache;
use Bow\Database\Database;
use Bow\Tests\Config\TestingConfiguration;
class CacheDatabaseTest extends \PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
$config = TestingConfiguration::getConfig();
Database::configure($config["database"]);
Database::statement("DROP TABLE IF EXISTS caches;");
Database::statement("
CREATE TABLE IF NOT EXISTS caches (
key_name varchar(500) not null primary key,
data text null,
expire datetime null
)");
Cache::configure($config["cache"]);
Cache::store("database");
}
public function test_create_cache()
{
$result = Cache::add('name', 'Dakia');
$this->assertEquals($result, true);
}
public function test_get_cache()
{
$this->assertEquals(Cache::get('name'), 'Dakia');
}
public function test_add_with_callback_cache()
{
$result = Cache::add('lastname', fn() => 'Franck');
$result = $result && Cache::add('age', fn() => 25, 20000);
$this->assertEquals($result, true);
}
public function test_get_callback_cache()
{
$this->assertEquals(Cache::get('lastname'), 'Franck');
$this->assertEquals(Cache::get('age'), 25);
}
public function test_add_array_cache()
{
$result = Cache::add('address', [
'tel' => "49929598",
'city' => "Abidjan",
'country' => "Cote d'ivoire"
]);
$this->assertEquals($result, true);
}
public function test_get_array_cache()
{
$result = Cache::get('address');
$this->assertEquals(true, is_array($result));
$this->assertEquals(count($result), 3);
$this->assertArrayHasKey('tel', $result);
$this->assertArrayHasKey('city', $result);
$this->assertArrayHasKey('country', $result);
}
public function test_has()
{
$first_result = Cache::has('name');
$other_result = Cache::has('jobs');
$this->assertEquals(true, $first_result);
$this->assertEquals(false, $other_result);
}
public function test_forget()
{
$result = Cache::forget('name');
$this->assertEquals(true, $result);
$this->assertEquals(Cache::get('name', false), false);
}
public function test_forget_empty()
{
$this->expectExceptionMessage("The key name is not found");
$result = Cache::forget('name');
}
public function test_time_of_empty()
{
$result = Cache::timeOf('lastname');
$this->assertIsString($result);
}
public function test_time_of_empty_2()
{
$result = Cache::timeOf('address');
$this->assertIsString($result);
}
public function test_time_of_empty_3()
{
$result = Cache::timeOf('age');
$this->assertIsString($result);
}
public function test_can_add_many_data_at_the_same_time_in_the_cache()
{
$result = Cache::addMany(['name' => 'Doe', 'first_name' => 'John']);
$this->assertEquals($result, true);
}
public function test_can_retrieve_multiple_cache_stored()
{
Cache::addMany(['name' => 'Doe', 'first_name' => 'John']);
$this->assertEquals(Cache::get('name'), 'Doe');
$this->assertEquals(Cache::get('first_name'), 'John');
}
public function test_clear_cache()
{
Cache::addMany(['name' => 'Doe', 'first_name' => 'John']);
$this->assertEquals(Cache::get('first_name'), 'John');
$this->assertEquals(Cache::get('name'), 'Doe');
Cache::clear();
$this->assertNull(Cache::get('name'));
$this->assertNull(Cache::get('first_name'));
}
}