@@ -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 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param int|string $ttl |
71 | 71 | * @return bool |
72 | 72 | */ |
73 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
73 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
74 | 74 | { |
75 | 75 | if (!empty($this->getCache($cacheKey, $namespace))) { |
76 | 76 | return true; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param string|int $ttl |
161 | 161 | * @return CacheDataFormatter|mixed |
162 | 162 | */ |
163 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
163 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
164 | 164 | { |
165 | 165 | $cacheData = $this->cacheStore->getCache($cacheKey, $namespace, $ttl); |
166 | 166 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | { |
194 | 194 | $cacheData = $this->getCache($cacheKey, $namespace); |
195 | 195 | |
196 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
196 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
197 | 197 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
198 | 198 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
199 | 199 | return true; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param string|int $ttl |
218 | 218 | * @return void |
219 | 219 | */ |
220 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
220 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
221 | 221 | { |
222 | 222 | $data = CacheerHelper::prepareForStorage($cacheData, $this->compression, $this->encryptionKey); |
223 | 223 | $this->cacheStore->putCache($cacheKey, $data, $namespace, $ttl); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param string $namespace |
242 | 242 | * @return void |
243 | 243 | */ |
244 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
244 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
245 | 245 | { |
246 | 246 | $this->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
247 | 247 | |
@@ -258,11 +258,11 @@ discard block |
||
258 | 258 | * @param Closure $callback |
259 | 259 | * @return mixed |
260 | 260 | */ |
261 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
261 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
262 | 262 | { |
263 | 263 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
264 | 264 | |
265 | - if(!empty($cachedData)) { |
|
265 | + if (!empty($cachedData)) { |
|
266 | 266 | return $cachedData; |
267 | 267 | } |
268 | 268 |