@@ -7,26 +7,26 @@ discard block |
||
7 | 7 | class OptionBuildTest extends TestCase |
8 | 8 | { |
9 | 9 | |
10 | - private $cache; |
|
11 | - private $cacheDir; |
|
10 | + private $cache; |
|
11 | + private $cacheDir; |
|
12 | 12 | |
13 | - protected function setUp(): void |
|
14 | - { |
|
13 | + protected function setUp(): void |
|
14 | + { |
|
15 | 15 | $this->cacheDir = __DIR__ . '/cache'; |
16 | 16 | if (!file_exists($this->cacheDir) || !is_dir($this->cacheDir)) { |
17 | - mkdir($this->cacheDir, 0755, true); |
|
17 | + mkdir($this->cacheDir, 0755, true); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | $this->cache = new Cacheer(); |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - protected function tearDown(): void |
|
24 | - { |
|
23 | + protected function tearDown(): void |
|
24 | + { |
|
25 | 25 | $this->cache->flushCache(); |
26 | - } |
|
26 | + } |
|
27 | 27 | |
28 | - public function test_it_can_set_cache_directory() |
|
29 | - { |
|
28 | + public function test_it_can_set_cache_directory() |
|
29 | + { |
|
30 | 30 | $cacheDir = __DIR__ . "/cache"; |
31 | 31 | |
32 | 32 | $options = OptionBuilder::forFile() |
@@ -35,23 +35,23 @@ discard block |
||
35 | 35 | |
36 | 36 | $this->assertArrayHasKey('cacheDir', $options); |
37 | 37 | $this->assertEquals($cacheDir, $options['cacheDir']); |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - public function test_it_can_set_expiration_time() |
|
41 | + public function test_it_can_set_expiration_time() |
|
42 | 42 | { |
43 | 43 | |
44 | - $options = OptionBuilder::forFile() |
|
45 | - ->expirationTime('2 hours') |
|
46 | - ->build(); |
|
44 | + $options = OptionBuilder::forFile() |
|
45 | + ->expirationTime('2 hours') |
|
46 | + ->build(); |
|
47 | 47 | |
48 | - $this->assertArrayHasKey('expirationTime', $options); |
|
49 | - $this->assertEquals('2 hours', $options['expirationTime']); |
|
48 | + $this->assertArrayHasKey('expirationTime', $options); |
|
49 | + $this->assertEquals('2 hours', $options['expirationTime']); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function test_it_can_set_flush_after() |
53 | 53 | { |
54 | - $options = OptionBuilder::forFile() |
|
54 | + $options = OptionBuilder::forFile() |
|
55 | 55 | ->flushAfter('11 seconds') |
56 | 56 | ->build(); |
57 | 57 | |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | |
62 | 62 | public function test_it_can_set_multiple_options_together() |
63 | 63 | { |
64 | - $cacheDir = __DIR__ . "/cache"; |
|
64 | + $cacheDir = __DIR__ . "/cache"; |
|
65 | 65 | |
66 | - $options = OptionBuilder::forFile() |
|
66 | + $options = OptionBuilder::forFile() |
|
67 | 67 | ->dir($cacheDir) |
68 | 68 | ->expirationTime('1 day') |
69 | 69 | ->flushAfter('30 minutes') |
@@ -76,41 +76,41 @@ discard block |
||
76 | 76 | ], $options); |
77 | 77 | } |
78 | 78 | |
79 | - public function test_it_allows_setting_expiration_time_with_timebuilder() |
|
79 | + public function test_it_allows_setting_expiration_time_with_timebuilder() |
|
80 | 80 | { |
81 | - $options = OptionBuilder::forFile()->expirationTime()->week(1)->build(); |
|
82 | - $this->assertArrayHasKey('expirationTime', $options); |
|
83 | - $this->assertEquals('1 weeks', $options['expirationTime']); |
|
81 | + $options = OptionBuilder::forFile()->expirationTime()->week(1)->build(); |
|
82 | + $this->assertArrayHasKey('expirationTime', $options); |
|
83 | + $this->assertEquals('1 weeks', $options['expirationTime']); |
|
84 | 84 | } |
85 | 85 | |
86 | - public function test_it_allows_setting_flush_after_with_timebuilder() |
|
87 | - { |
|
86 | + public function test_it_allows_setting_flush_after_with_timebuilder() |
|
87 | + { |
|
88 | 88 | $options = OptionBuilder::forFile()->flushAfter()->second(10)->build(); |
89 | 89 | $this->assertArrayHasKey('flushAfter', $options); |
90 | 90 | $this->assertEquals('10 seconds', $options['flushAfter']); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - public function test_it_can_set_multiple_options_together_with_timebuilder() |
|
94 | - { |
|
93 | + public function test_it_can_set_multiple_options_together_with_timebuilder() |
|
94 | + { |
|
95 | 95 | $cacheDir = __DIR__ . "/cache"; |
96 | 96 | $options = OptionBuilder::forFile() |
97 | - ->dir($cacheDir) |
|
98 | - ->expirationTime()->week(1) |
|
99 | - ->flushAfter()->minute(10) |
|
100 | - ->build(); |
|
97 | + ->dir($cacheDir) |
|
98 | + ->expirationTime()->week(1) |
|
99 | + ->flushAfter()->minute(10) |
|
100 | + ->build(); |
|
101 | 101 | |
102 | 102 | $this->assertEquals([ |
103 | 103 | 'cacheDir' => $cacheDir, |
104 | 104 | 'expirationTime' => '1 weeks', |
105 | 105 | 'flushAfter' => '10 minutes', |
106 | 106 | ], $options); |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - public function test_it_returns_empty_array_when_no_options_are_set() |
|
110 | - { |
|
109 | + public function test_it_returns_empty_array_when_no_options_are_set() |
|
110 | + { |
|
111 | 111 | $options = OptionBuilder::forFile()->build(); |
112 | 112 | $this->assertIsArray($options); |
113 | 113 | $this->assertEmpty($options); |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param int|string $ttl |
70 | 70 | * @return bool |
71 | 71 | */ |
72 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
72 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
73 | 73 | { |
74 | 74 | if (!empty($this->getCache($cacheKey, $namespace))) { |
75 | 75 | return true; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param string|int $ttl |
160 | 160 | * @return CacheDataFormatter|mixed |
161 | 161 | */ |
162 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
162 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
163 | 163 | { |
164 | 164 | $cacheData = $this->cacheStore->getCache($cacheKey, $namespace, $ttl); |
165 | 165 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | { |
193 | 193 | $cacheData = $this->getCache($cacheKey, $namespace); |
194 | 194 | |
195 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
195 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
196 | 196 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
197 | 197 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
198 | 198 | return true; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @param string|int $ttl |
217 | 217 | * @return void |
218 | 218 | */ |
219 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
219 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
220 | 220 | { |
221 | 221 | $data = $this->prepareForStorage($cacheData); |
222 | 222 | $this->cacheStore->putCache($cacheKey, $data, $namespace, $ttl); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @param string $namespace |
241 | 241 | * @return mixed |
242 | 242 | */ |
243 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
243 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
244 | 244 | { |
245 | 245 | $renewedCache = $this->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
246 | 246 | |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | * @param Closure $callback |
260 | 260 | * @return mixed |
261 | 261 | */ |
262 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
262 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
263 | 263 | { |
264 | 264 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
265 | 265 | |
266 | - if(!empty($cachedData)) { |
|
266 | + if (!empty($cachedData)) { |
|
267 | 267 | return $cachedData; |
268 | 268 | } |
269 | 269 |