@@ -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_diretory() |
|
29 | - { |
|
28 | + public function test_it_can_set_cache_diretory() |
|
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 | } |
@@ -11,103 +11,103 @@ |
||
11 | 11 | */ |
12 | 12 | class FileOptionBuilder |
13 | 13 | { |
14 | - /** @param null|string $cacheDir */ |
|
15 | - private ?string $cacheDir = null; |
|
14 | + /** @param null|string $cacheDir */ |
|
15 | + private ?string $cacheDir = null; |
|
16 | 16 | |
17 | - /** @param null|string $expirationTime */ |
|
18 | - private ?string $expirationTime = null; |
|
17 | + /** @param null|string $expirationTime */ |
|
18 | + private ?string $expirationTime = null; |
|
19 | 19 | |
20 | - /** @param null|string $flushAfter */ |
|
21 | - private ?string $flushAfter = null; |
|
20 | + /** @param null|string $flushAfter */ |
|
21 | + private ?string $flushAfter = null; |
|
22 | 22 | |
23 | - /** @param array $options */ |
|
24 | - private array $options = []; |
|
23 | + /** @param array $options */ |
|
24 | + private array $options = []; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param string $cacheDir |
|
28 | - * @return $this |
|
29 | - */ |
|
30 | - public function dir(string $cacheDir) |
|
31 | - { |
|
26 | + /** |
|
27 | + * @param string $cacheDir |
|
28 | + * @return $this |
|
29 | + */ |
|
30 | + public function dir(string $cacheDir) |
|
31 | + { |
|
32 | 32 | $this->cacheDir = $cacheDir; |
33 | 33 | return $this; |
34 | - } |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param ?string $expirationTime |
|
38 | - * @return $this|TimeBuilder |
|
39 | - */ |
|
40 | - public function expirationTime(?string $expirationTime = null) |
|
41 | - { |
|
36 | + /** |
|
37 | + * @param ?string $expirationTime |
|
38 | + * @return $this|TimeBuilder |
|
39 | + */ |
|
40 | + public function expirationTime(?string $expirationTime = null) |
|
41 | + { |
|
42 | 42 | |
43 | 43 | if (!is_null($expirationTime)) { |
44 | - $this->expirationTime = $expirationTime; |
|
45 | - return $this; |
|
44 | + $this->expirationTime = $expirationTime; |
|
45 | + return $this; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | return new TimeBuilder(function ($formattedTime){ |
49 | - $this->expirationTime = $formattedTime; |
|
49 | + $this->expirationTime = $formattedTime; |
|
50 | 50 | }, $this); |
51 | - } |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param ?string $flushAfter |
|
55 | - * @return $this|TimeBuilder |
|
56 | - */ |
|
57 | - public function flushAfter(?string $flushAfter = null) |
|
58 | - { |
|
53 | + /** |
|
54 | + * @param ?string $flushAfter |
|
55 | + * @return $this|TimeBuilder |
|
56 | + */ |
|
57 | + public function flushAfter(?string $flushAfter = null) |
|
58 | + { |
|
59 | 59 | |
60 | 60 | if (!is_null($flushAfter)) { |
61 | - $this->flushAfter = mb_strtolower($flushAfter, 'UTF-8'); |
|
62 | - return $this; |
|
61 | + $this->flushAfter = mb_strtolower($flushAfter, 'UTF-8'); |
|
62 | + return $this; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | return new TimeBuilder(function ($formattedTime){ |
66 | - $this->flushAfter = $formattedTime; |
|
66 | + $this->flushAfter = $formattedTime; |
|
67 | 67 | }, $this); |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function build() |
|
74 | - { |
|
70 | + /** |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function build() |
|
74 | + { |
|
75 | 75 | return $this->validated(); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - private function validated() |
|
82 | - { |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + private function validated() |
|
82 | + { |
|
83 | 83 | foreach ($this->properties() as $key => $value) { |
84 | 84 | if ($this->isValidAndNotNull($value)) { |
85 | 85 | $this->options[$key] = $value; |
86 | 86 | } |
87 | 87 | } |
88 | 88 | return $this->options; |
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param mixed $data |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - private function isValidAndNotNull(mixed $data) |
|
96 | - { |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param mixed $data |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + private function isValidAndNotNull(mixed $data) |
|
96 | + { |
|
97 | 97 | return !empty($data) ? true : false; |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - private function properties() |
|
104 | - { |
|
100 | + /** |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + private function properties() |
|
104 | + { |
|
105 | 105 | $properties = [ |
106 | - 'cacheDir' => $this->cacheDir, |
|
107 | - 'expirationTime' => $this->expirationTime, |
|
108 | - 'flushAfter' => $this->flushAfter |
|
106 | + 'cacheDir' => $this->cacheDir, |
|
107 | + 'expirationTime' => $this->expirationTime, |
|
108 | + 'flushAfter' => $this->flushAfter |
|
109 | 109 | ]; |
110 | 110 | |
111 | 111 | return $properties; |
112 | - } |
|
112 | + } |
|
113 | 113 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | return $this; |
46 | 46 | } |
47 | 47 | |
48 | - return new TimeBuilder(function ($formattedTime){ |
|
48 | + return new TimeBuilder(function($formattedTime) { |
|
49 | 49 | $this->expirationTime = $formattedTime; |
50 | 50 | }, $this); |
51 | 51 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | return $this; |
63 | 63 | } |
64 | 64 | |
65 | - return new TimeBuilder(function ($formattedTime){ |
|
65 | + return new TimeBuilder(function($formattedTime) { |
|
66 | 66 | $this->flushAfter = $formattedTime; |
67 | 67 | }, $this); |
68 | 68 | } |
@@ -13,91 +13,91 @@ |
||
13 | 13 | class TimeBuilder |
14 | 14 | { |
15 | 15 | |
16 | - /** @param string $unit */ |
|
17 | - private string $unit; |
|
16 | + /** @param string $unit */ |
|
17 | + private string $unit; |
|
18 | 18 | |
19 | - /** @param int $value */ |
|
20 | - private int $value; |
|
19 | + /** @param int $value */ |
|
20 | + private int $value; |
|
21 | 21 | |
22 | - /** @param Closure $callback */ |
|
23 | - private Closure $callback; |
|
22 | + /** @param Closure $callback */ |
|
23 | + private Closure $callback; |
|
24 | 24 | |
25 | - /** @param FileOptionBuilder */ |
|
26 | - private $builder = null; |
|
25 | + /** @param FileOptionBuilder */ |
|
26 | + private $builder = null; |
|
27 | 27 | |
28 | - public function __construct(Closure $callback, $builder) |
|
29 | - { |
|
28 | + public function __construct(Closure $callback, $builder) |
|
29 | + { |
|
30 | 30 | $this->callback = $callback; |
31 | 31 | $this->builder = $builder; |
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @param int $value |
|
36 | - * @return FileOptionBuilder|mixed |
|
37 | - */ |
|
38 | - public function second(int $value) |
|
39 | - { |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @param int $value |
|
36 | + * @return FileOptionBuilder|mixed |
|
37 | + */ |
|
38 | + public function second(int $value) |
|
39 | + { |
|
40 | 40 | return $this->setTime($value, "seconds"); |
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param int $value |
|
45 | - * @return FileOptionBuilder|mixed |
|
46 | - */ |
|
47 | - public function minute(int $value) |
|
48 | - { |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param int $value |
|
45 | + * @return FileOptionBuilder|mixed |
|
46 | + */ |
|
47 | + public function minute(int $value) |
|
48 | + { |
|
49 | 49 | return $this->setTime($value, "minutes"); |
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @param int $value |
|
54 | - * @return FileOptionBuilder|mixed |
|
55 | - */ |
|
56 | - public function hour(int $value) |
|
57 | - { |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @param int $value |
|
54 | + * @return FileOptionBuilder|mixed |
|
55 | + */ |
|
56 | + public function hour(int $value) |
|
57 | + { |
|
58 | 58 | return $this->setTime($value, "hours"); |
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param int $value |
|
63 | - * @return FileOptionBuilder|mixed |
|
64 | - */ |
|
65 | - public function day(int $value) |
|
66 | - { |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param int $value |
|
63 | + * @return FileOptionBuilder|mixed |
|
64 | + */ |
|
65 | + public function day(int $value) |
|
66 | + { |
|
67 | 67 | return $this->setTime($value, "days"); |
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param int $value |
|
72 | - * @return FileOptionBuilder|mixed |
|
73 | - */ |
|
74 | - public function week(int $value) |
|
75 | - { |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param int $value |
|
72 | + * @return FileOptionBuilder|mixed |
|
73 | + */ |
|
74 | + public function week(int $value) |
|
75 | + { |
|
76 | 76 | return $this->setTime($value, "weeks"); |
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param int $value |
|
81 | - * @return FileOptionBuilder|mixed |
|
82 | - */ |
|
83 | - public function month(int $value) |
|
84 | - { |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param int $value |
|
81 | + * @return FileOptionBuilder|mixed |
|
82 | + */ |
|
83 | + public function month(int $value) |
|
84 | + { |
|
85 | 85 | return $this->setTime($value, "months"); |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param int $value |
|
91 | - * @param string $unit |
|
92 | - * @return FileOptionBuilder |
|
93 | - */ |
|
94 | - private function setTime(int $value, string $unit) |
|
95 | - { |
|
89 | + /** |
|
90 | + * @param int $value |
|
91 | + * @param string $unit |
|
92 | + * @return FileOptionBuilder |
|
93 | + */ |
|
94 | + private function setTime(int $value, string $unit) |
|
95 | + { |
|
96 | 96 | |
97 | 97 | $this->value = $value; |
98 | 98 | $this->unit = $unit; |
99 | - ($this->callback)("{$value} {$unit}"); |
|
99 | + ($this->callback)("{$value} {$unit}"); |
|
100 | 100 | return $this->builder; |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | { |
259 | 259 | $this->cache->flushCache(); |
260 | 260 | |
261 | - $value = $this->cache->remember('remember_test_key', 60, function () { |
|
261 | + $value = $this->cache->remember('remember_test_key', 60, function() { |
|
262 | 262 | return 'valor_teste'; |
263 | 263 | }); |
264 | 264 | |
265 | 265 | $this->assertEquals('valor_teste', $value); |
266 | 266 | |
267 | - $cachedValue = $this->cache->remember('remember_test_key', 60, function (){ |
|
267 | + $cachedValue = $this->cache->remember('remember_test_key', 60, function() { |
|
268 | 268 | return 'novo_valor'; |
269 | 269 | }); |
270 | 270 | |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | { |
277 | 277 | $this->cache->flushCache(); |
278 | 278 | |
279 | - $value = $this->cache->rememberForever('remember_forever_key', function () { |
|
279 | + $value = $this->cache->rememberForever('remember_forever_key', function() { |
|
280 | 280 | return 'valor_eterno'; |
281 | 281 | }); |
282 | 282 | $this->assertEquals('valor_eterno', $value); |
283 | 283 | |
284 | - $cachedValue = $this->cache->rememberForever('remember_forever_key', function () { |
|
284 | + $cachedValue = $this->cache->rememberForever('remember_forever_key', function() { |
|
285 | 285 | return 'novo_valor'; |
286 | 286 | }); |
287 | 287 |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | |
233 | 233 | public function test_remember_saves_and_recover_values() |
234 | 234 | { |
235 | - $value = $this->cache->remember('remember_test_key', 60, function () { |
|
235 | + $value = $this->cache->remember('remember_test_key', 60, function() { |
|
236 | 236 | return 'valor_teste'; |
237 | 237 | }); |
238 | 238 | |
239 | 239 | $this->assertEquals('valor_teste', $value); |
240 | 240 | |
241 | - $cachedValue = $this->cache->remember('remember_test_key', 60, function (){ |
|
241 | + $cachedValue = $this->cache->remember('remember_test_key', 60, function() { |
|
242 | 242 | return 'novo_valor'; |
243 | 243 | }); |
244 | 244 | |
@@ -249,12 +249,12 @@ discard block |
||
249 | 249 | public function test_remember_forever_saves_value_indefinitely() |
250 | 250 | { |
251 | 251 | |
252 | - $value = $this->cache->rememberForever('remember_forever_key', function () { |
|
252 | + $value = $this->cache->rememberForever('remember_forever_key', function() { |
|
253 | 253 | return 'valor_eterno'; |
254 | 254 | }); |
255 | 255 | $this->assertEquals('valor_eterno', $value); |
256 | 256 | |
257 | - $cachedValue = $this->cache->rememberForever('remember_forever_key', function () { |
|
257 | + $cachedValue = $this->cache->rememberForever('remember_forever_key', function() { |
|
258 | 258 | return 'novo_valor'; |
259 | 259 | }); |
260 | 260 |
@@ -7,27 +7,27 @@ discard block |
||
7 | 7 | class RedisCacheStoreTest extends TestCase |
8 | 8 | { |
9 | 9 | |
10 | - /** @var Cacheer */ |
|
11 | - private $cache; |
|
10 | + /** @var Cacheer */ |
|
11 | + private $cache; |
|
12 | 12 | |
13 | - protected function setUp(): void |
|
14 | - { |
|
13 | + protected function setUp(): void |
|
14 | + { |
|
15 | 15 | $this->cache = new Cacheer(); |
16 | 16 | $this->cache->setDriver()->useRedisDriver(); |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - protected function tearDown(): void |
|
20 | - { |
|
19 | + protected function tearDown(): void |
|
20 | + { |
|
21 | 21 | $this->cache->flushCache(); |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function testUsingRedisDriverSetsProperInstance() |
|
25 | - { |
|
24 | + public function testUsingRedisDriverSetsProperInstance() |
|
25 | + { |
|
26 | 26 | $this->assertInstanceOf(RedisCacheStore::class, $this->cache->cacheStore); |
27 | - } |
|
27 | + } |
|
28 | 28 | |
29 | - public function testPutCacheInRedis() |
|
30 | - { |
|
29 | + public function testPutCacheInRedis() |
|
30 | + { |
|
31 | 31 | $cacheKey = 'test_key'; |
32 | 32 | $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer']; |
33 | 33 | |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | $this->assertNotEmpty($this->cache->getCache($cacheKey)); |
38 | 38 | $this->assertEquals($cacheData, $this->cache->getCache($cacheKey)); |
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - public function testGetCacheFromRedis() |
|
43 | - { |
|
42 | + public function testGetCacheFromRedis() |
|
43 | + { |
|
44 | 44 | $cacheKey = 'test_key'; |
45 | 45 | $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer']; |
46 | 46 | |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $data = $this->cache->getCache($cacheKey); |
52 | 52 | $this->assertNotEmpty($data); |
53 | 53 | $this->assertEquals($cacheData, $data); |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - public function testExpiredCacheInRedis() |
|
57 | - { |
|
56 | + public function testExpiredCacheInRedis() |
|
57 | + { |
|
58 | 58 | $cacheKey = 'expired_key'; |
59 | 59 | $cacheData = ['name' => 'Expired User', 'email' => '[email protected]']; |
60 | 60 | |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | $this->assertEquals("Cache stored successfully", $this->cache->getMessage()); |
65 | 65 | $this->assertEmpty($this->cache->getCache($cacheKey)); |
66 | 66 | $this->assertFalse($this->cache->isSuccess()); |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - public function testOverwriteExistingCacheInRedis() |
|
70 | - { |
|
69 | + public function testOverwriteExistingCacheInRedis() |
|
70 | + { |
|
71 | 71 | $cacheKey = 'overwrite_key'; |
72 | 72 | $initialCacheData = ['name' => 'Initial Data', 'email' => '[email protected]']; |
73 | 73 | $newCacheData = ['name' => 'New Data', 'email' => '[email protected]']; |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | $this->cache->appendCache($cacheKey, $newCacheData); |
79 | 79 | $this->assertEquals("Cache appended successfully", $this->cache->getMessage()); |
80 | 80 | $this->assertEquals($newCacheData, $this->cache->getCache($cacheKey)); |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - public function testPutManyCacheItemsInRedis() |
|
84 | - { |
|
85 | - $items = [ |
|
83 | + public function testPutManyCacheItemsInRedis() |
|
84 | + { |
|
85 | + $items = [ |
|
86 | 86 | [ |
87 | 87 | 'cacheKey' => 'user_1_profile', |
88 | 88 | 'cacheData' => [ |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | foreach ($items as $item) { |
108 | 108 | $this->assertEquals($item['cacheData'], $this->cache->getCache($item['cacheKey'])); |
109 | 109 | } |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - public function testAppendCacheWithNamespaceInRedis() |
|
112 | + public function testAppendCacheWithNamespaceInRedis() |
|
113 | 113 | { |
114 | 114 | $cacheKey = 'test_append_key_ns'; |
115 | 115 | $namespace = 'test_namespace'; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $this->assertEquals($expectedData, $cachedData); |
133 | 133 | } |
134 | 134 | |
135 | - public function testDataOutputShouldBeOfTypeArray() |
|
135 | + public function testDataOutputShouldBeOfTypeArray() |
|
136 | 136 | { |
137 | 137 | |
138 | 138 | $this->cache->useFormatter(); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $this->assertJson($cacheOutput); |
179 | 179 | } |
180 | 180 | |
181 | - public function testClearCacheDataFromRedis() |
|
181 | + public function testClearCacheDataFromRedis() |
|
182 | 182 | { |
183 | 183 | $cacheKey = 'test_key'; |
184 | 184 | $data = 'test_data'; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $this->assertEmpty($this->cache->getCache($cacheKey)); |
194 | 194 | } |
195 | 195 | |
196 | - public function testFlushCacheDataFromRedis() |
|
196 | + public function testFlushCacheDataFromRedis() |
|
197 | 197 | { |
198 | 198 | $key1 = 'test_key1'; |
199 | 199 | $data1 = 'test_data1'; |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | $this->assertEquals("Cache flushed successfully", $this->cache->getMessage()); |
213 | 213 | } |
214 | 214 | |
215 | - public function testHasCacheFromRedis() |
|
216 | - { |
|
215 | + public function testHasCacheFromRedis() |
|
216 | + { |
|
217 | 217 | $cacheKey = 'test_key'; |
218 | 218 | $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer']; |
219 | 219 | |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | |
222 | 222 | $this->assertEquals("Cache stored successfully", $this->cache->getMessage()); |
223 | 223 | $this->assertTrue($this->cache->isSuccess()); |
224 | - } |
|
224 | + } |
|
225 | 225 | |
226 | - public function testRenewCacheFromRedis() |
|
227 | - { |
|
226 | + public function testRenewCacheFromRedis() |
|
227 | + { |
|
228 | 228 | $cacheKey = 'expired_key'; |
229 | 229 | $cacheData = ['name' => 'Expired User', 'email' => '[email protected]']; |
230 | 230 | |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | $this->cache->renewCache($cacheKey, 7200); |
240 | 240 | $this->assertTrue($this->cache->isSuccess()); |
241 | 241 | $this->assertNotEmpty($this->cache->getCache($cacheKey)); |
242 | - } |
|
242 | + } |
|
243 | 243 | |
244 | 244 | public function testRenewCacheWithNamespaceFromRedis() |
245 | - { |
|
245 | + { |
|
246 | 246 | $cacheKey = 'expired_key'; |
247 | 247 | $namespace = 'expired_namespace'; |
248 | 248 | $cacheData = ['name' => 'Expired User', 'email' => '[email protected]']; |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | $this->cache->renewCache($cacheKey, 7200, $namespace); |
257 | 257 | $this->assertTrue($this->cache->isSuccess()); |
258 | 258 | $this->assertNotEmpty($this->cache->getCache($cacheKey, $namespace)); |
259 | - } |
|
259 | + } |
|
260 | 260 | |
261 | - public function test_remember_saves_and_recover_values() |
|
261 | + public function test_remember_saves_and_recover_values() |
|
262 | 262 | { |
263 | 263 | $this->cache->flushCache(); |
264 | 264 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | |
296 | - public function test_get_and_forget() |
|
296 | + public function test_get_and_forget() |
|
297 | 297 | { |
298 | 298 | $cacheKey = 'cache_key_test'; |
299 | 299 | $this->cache->putCache($cacheKey, 10); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $this->assertNull($noCacheData); |
315 | 315 | } |
316 | 316 | |
317 | - public function test_store_if_not_present_with_add_function() |
|
317 | + public function test_store_if_not_present_with_add_function() |
|
318 | 318 | { |
319 | 319 | $existentKey = 'cache_key_test'; |
320 | 320 | |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | |
339 | 339 | } |
340 | 340 | |
341 | - public function test_increment_function() { |
|
341 | + public function test_increment_function() { |
|
342 | 342 | |
343 | 343 | $cacheKey = 'test_increment'; |
344 | 344 | $cacheData = 2025; |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | { |
259 | 259 | $this->cache->flushCache(); |
260 | 260 | |
261 | - $value = $this->cache->remember('remember_test_key', 60, function () { |
|
261 | + $value = $this->cache->remember('remember_test_key', 60, function() { |
|
262 | 262 | return 'valor_teste'; |
263 | 263 | }); |
264 | 264 | |
265 | 265 | $this->assertEquals('valor_teste', $value); |
266 | 266 | |
267 | - $cachedValue = $this->cache->remember('remember_test_key', 60, function (){ |
|
267 | + $cachedValue = $this->cache->remember('remember_test_key', 60, function() { |
|
268 | 268 | return 'novo_valor'; |
269 | 269 | }); |
270 | 270 | |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | { |
277 | 277 | $this->cache->flushCache(); |
278 | 278 | |
279 | - $value = $this->cache->rememberForever('remember_forever_key', function () { |
|
279 | + $value = $this->cache->rememberForever('remember_forever_key', function() { |
|
280 | 280 | return 'valor_eterno'; |
281 | 281 | }); |
282 | 282 | $this->assertEquals('valor_eterno', $value); |
283 | 283 | |
284 | - $cachedValue = $this->cache->rememberForever('remember_forever_key', function () { |
|
284 | + $cachedValue = $this->cache->rememberForever('remember_forever_key', function() { |
|
285 | 285 | return 'novo_valor'; |
286 | 286 | }); |
287 | 287 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param int|string $ttl |
45 | 45 | * @return mixed |
46 | 46 | */ |
47 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
47 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
48 | 48 | { |
49 | 49 | |
50 | 50 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $expirationTime = $cacheData['expirationTime'] ?? 0; |
60 | 60 | $now = time(); |
61 | 61 | |
62 | - if($expirationTime !== 0 && $now >= $expirationTime) { |
|
62 | + if ($expirationTime !== 0 && $now >= $expirationTime) { |
|
63 | 63 | list($np, $key) = explode(':', $arrayStoreKey); |
64 | 64 | $this->clearCache($key, $np); |
65 | 65 | $this->setMessage("cacheKey: {$key} has expired.", false); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param int|string $ttl |
80 | 80 | * @return bool |
81 | 81 | */ |
82 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
82 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
83 | 83 | { |
84 | 84 | |
85 | 85 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | * @param string $namespace |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
|
162 | + public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = '') |
|
163 | 163 | { |
164 | 164 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
165 | 165 | |
166 | 166 | if (isset($this->arrayStore[$arrayStoreKey])) { |
167 | - $ttlSeconds = is_numeric($ttl) ? (int) $ttl : strtotime($ttl) - time(); |
|
167 | + $ttlSeconds = is_numeric($ttl) ? (int)$ttl : strtotime($ttl) - time(); |
|
168 | 168 | $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds; |
169 | 169 | $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true); |
170 | 170 | $this->logger->debug("{$this->getMessage()} from array driver."); |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | class ArrayCacheStore implements CacheerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $arrayStore |
|
18 | - */ |
|
19 | - private array $arrayStore = []; |
|
16 | + /** |
|
17 | + * @param array $arrayStore |
|
18 | + */ |
|
19 | + private array $arrayStore = []; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @param boolean |
@@ -33,26 +33,26 @@ discard block |
||
33 | 33 | */ |
34 | 34 | private $logger = null; |
35 | 35 | |
36 | - public function __construct(string $logPath) |
|
37 | - { |
|
36 | + public function __construct(string $logPath) |
|
37 | + { |
|
38 | 38 | $this->logger = new CacheLogger($logPath); |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $cacheKey |
|
43 | - * @param string $namespace |
|
44 | - * @param int|string $ttl |
|
45 | - * @return mixed |
|
46 | - */ |
|
47 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
48 | - { |
|
41 | + /** |
|
42 | + * @param string $cacheKey |
|
43 | + * @param string $namespace |
|
44 | + * @param int|string $ttl |
|
45 | + * @return mixed |
|
46 | + */ |
|
47 | + public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
48 | + { |
|
49 | 49 | |
50 | 50 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
51 | 51 | |
52 | 52 | if (!$this->has($cacheKey, $namespace)) { |
53 | - $this->setMessage("cacheData not found, does not exists or expired", false); |
|
54 | - $this->logger->debug("{$this->getMessage()} from array driver."); |
|
55 | - return false; |
|
53 | + $this->setMessage("cacheData not found, does not exists or expired", false); |
|
54 | + $this->logger->debug("{$this->getMessage()} from array driver."); |
|
55 | + return false; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $cacheData = $this->arrayStore[$arrayStoreKey]; |
@@ -60,102 +60,102 @@ discard block |
||
60 | 60 | $now = time(); |
61 | 61 | |
62 | 62 | if($expirationTime !== 0 && $now >= $expirationTime) { |
63 | - list($np, $key) = explode(':', $arrayStoreKey); |
|
64 | - $this->clearCache($key, $np); |
|
65 | - $this->setMessage("cacheKey: {$key} has expired.", false); |
|
66 | - $this->logger->debug("{$this->getMessage()} from array driver."); |
|
67 | - return false; |
|
63 | + list($np, $key) = explode(':', $arrayStoreKey); |
|
64 | + $this->clearCache($key, $np); |
|
65 | + $this->setMessage("cacheKey: {$key} has expired.", false); |
|
66 | + $this->logger->debug("{$this->getMessage()} from array driver."); |
|
67 | + return false; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $this->setMessage("Cache retrieved successfully", true); |
71 | 71 | $this->logger->debug("{$this->getMessage()} from array driver."); |
72 | 72 | return $this->serialize($cacheData['cacheData'], false); |
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param string $cacheKey |
|
77 | - * @param mixed $cacheData |
|
78 | - * @param string $namespace |
|
79 | - * @param int|string $ttl |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
83 | - { |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param string $cacheKey |
|
77 | + * @param mixed $cacheData |
|
78 | + * @param string $namespace |
|
79 | + * @param int|string $ttl |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
83 | + { |
|
84 | 84 | |
85 | 85 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
86 | 86 | |
87 | 87 | $this->arrayStore[$arrayStoreKey] = [ |
88 | - 'cacheData' => serialize($cacheData), |
|
89 | - 'expirationTime' => time() + $ttl |
|
88 | + 'cacheData' => serialize($cacheData), |
|
89 | + 'expirationTime' => time() + $ttl |
|
90 | 90 | ]; |
91 | 91 | |
92 | 92 | $this->setMessage("Cache stored successfully", true); |
93 | 93 | $this->logger->debug("{$this->getMessage()} from Array driver."); |
94 | 94 | return true; |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @param array $items |
|
99 | - * @param string $namespace |
|
100 | - * @param int $batchSize |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - public function putMany(array $items, string $namespace = '', int $batchSize = 100) |
|
104 | - { |
|
97 | + /** |
|
98 | + * @param array $items |
|
99 | + * @param string $namespace |
|
100 | + * @param int $batchSize |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + public function putMany(array $items, string $namespace = '', int $batchSize = 100) |
|
104 | + { |
|
105 | 105 | |
106 | 106 | $chunks = array_chunk($items, $batchSize, true); |
107 | 107 | |
108 | 108 | foreach ($chunks as $chunk) { |
109 | - foreach ($chunk as $key => $data) { |
|
110 | - $this->putCache($data['cacheKey'], $data['cacheData'], $namespace); |
|
109 | + foreach ($chunk as $key => $data) { |
|
110 | + $this->putCache($data['cacheKey'], $data['cacheData'], $namespace); |
|
111 | + } |
|
111 | 112 | } |
112 | - } |
|
113 | 113 | $this->setMessage("{$this->getMessage()}", $this->isSuccess()); |
114 | 114 | $this->logger->debug("{$this->getMessage()} from Array driver."); |
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $cacheKey |
|
119 | - * @param mixed $cacheData |
|
120 | - * @param string $namespace |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
|
124 | - { |
|
125 | - $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
|
126 | - |
|
127 | - if (!$this->has($cacheKey, $namespace)) { |
|
128 | - $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false); |
|
129 | - $this->logger->debug("{$this->getMessage()} from array driver."); |
|
130 | - return false; |
|
131 | - } |
|
132 | - |
|
133 | - $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData); |
|
134 | - $this->setMessage("Cache appended successfully", true); |
|
135 | - return true; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $cacheKey |
|
142 | - * @param string $namespace |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function has(string $cacheKey, string $namespace = '') |
|
146 | - { |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $cacheKey |
|
119 | + * @param mixed $cacheData |
|
120 | + * @param string $namespace |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
|
124 | + { |
|
125 | + $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
|
126 | + |
|
127 | + if (!$this->has($cacheKey, $namespace)) { |
|
128 | + $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false); |
|
129 | + $this->logger->debug("{$this->getMessage()} from array driver."); |
|
130 | + return false; |
|
131 | + } |
|
132 | + |
|
133 | + $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData); |
|
134 | + $this->setMessage("Cache appended successfully", true); |
|
135 | + return true; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $cacheKey |
|
142 | + * @param string $namespace |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function has(string $cacheKey, string $namespace = '') |
|
146 | + { |
|
147 | 147 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
148 | 148 | return isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime']; |
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $cacheKey |
|
153 | - * @param int|string $ttl |
|
154 | - * @param string $namespace |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
|
158 | - { |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $cacheKey |
|
153 | + * @param int|string $ttl |
|
154 | + * @param string $namespace |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
|
158 | + { |
|
159 | 159 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
160 | 160 | |
161 | 161 | if (isset($this->arrayStore[$arrayStoreKey])) { |
@@ -163,33 +163,33 @@ discard block |
||
163 | 163 | $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds; |
164 | 164 | $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true); |
165 | 165 | $this->logger->debug("{$this->getMessage()} from array driver."); |
166 | - } |
|
167 | - } |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * @param string $cacheKey |
|
171 | - * @param string $namespace |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - public function clearCache(string $cacheKey, string $namespace = '') |
|
175 | - { |
|
169 | + /** |
|
170 | + * @param string $cacheKey |
|
171 | + * @param string $namespace |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + public function clearCache(string $cacheKey, string $namespace = '') |
|
175 | + { |
|
176 | 176 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
177 | 177 | unset($this->arrayStore[$arrayStoreKey]); |
178 | 178 | $this->setMessage("Cache cleared successfully", true); |
179 | 179 | $this->logger->debug("{$this->getMessage()} from array driver."); |
180 | 180 | |
181 | - } |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public function flushCache() |
|
187 | - { |
|
183 | + /** |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public function flushCache() |
|
187 | + { |
|
188 | 188 | unset($this->arrayStore); |
189 | 189 | $this->arrayStore = []; |
190 | 190 | $this->setMessage("Cache flushed successfully", true); |
191 | 191 | $this->logger->debug("{$this->getMessage()} from array driver."); |
192 | - } |
|
192 | + } |
|
193 | 193 | |
194 | 194 | /** |
195 | 195 | * @param string $message |
@@ -219,24 +219,24 @@ discard block |
||
219 | 219 | return $this->success; |
220 | 220 | } |
221 | 221 | |
222 | - /** |
|
223 | - * @param string $cacheKey |
|
224 | - * @param string $namespace |
|
225 | - * @return string |
|
226 | - */ |
|
227 | - private function buildArrayKey(string $cacheKey, string $namespace = '') |
|
228 | - { |
|
222 | + /** |
|
223 | + * @param string $cacheKey |
|
224 | + * @param string $namespace |
|
225 | + * @return string |
|
226 | + */ |
|
227 | + private function buildArrayKey(string $cacheKey, string $namespace = '') |
|
228 | + { |
|
229 | 229 | return !empty($namespace) ? ($namespace . ':' . $cacheKey) : $cacheKey; |
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param mixed $data |
|
234 | - * @param bool $serialize |
|
235 | - * @return mixed |
|
236 | - */ |
|
237 | - private function serialize(mixed $data, bool $serialize = true) |
|
238 | - { |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param mixed $data |
|
234 | + * @param bool $serialize |
|
235 | + * @return mixed |
|
236 | + */ |
|
237 | + private function serialize(mixed $data, bool $serialize = true) |
|
238 | + { |
|
239 | 239 | return $serialize ? serialize($data) : unserialize($data); |
240 | - } |
|
240 | + } |
|
241 | 241 | |
242 | 242 | } |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | { |
259 | 259 | $this->cache->flushCache(); |
260 | 260 | |
261 | - $value = $this->cache->remember('remember_test_key', 60, function () { |
|
261 | + $value = $this->cache->remember('remember_test_key', 60, function() { |
|
262 | 262 | return 'valor_teste'; |
263 | 263 | }); |
264 | 264 | |
265 | 265 | $this->assertEquals('valor_teste', $value); |
266 | 266 | |
267 | - $cachedValue = $this->cache->remember('remember_test_key', 60, function (){ |
|
267 | + $cachedValue = $this->cache->remember('remember_test_key', 60, function() { |
|
268 | 268 | return 'novo_valor'; |
269 | 269 | }); |
270 | 270 | |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | { |
277 | 277 | $this->cache->flushCache(); |
278 | 278 | |
279 | - $value = $this->cache->rememberForever('remember_forever_key', function () { |
|
279 | + $value = $this->cache->rememberForever('remember_forever_key', function() { |
|
280 | 280 | return 'valor_eterno'; |
281 | 281 | }); |
282 | 282 | $this->assertEquals('valor_eterno', $value); |
283 | 283 | |
284 | - $cachedValue = $this->cache->rememberForever('remember_forever_key', function () { |
|
284 | + $cachedValue = $this->cache->rememberForever('remember_forever_key', function() { |
|
285 | 285 | return 'novo_valor'; |
286 | 286 | }); |
287 | 287 |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | class ArrayCacheStoreTest extends TestCase |
8 | 8 | { |
9 | 9 | |
10 | - private $cache; |
|
10 | + private $cache; |
|
11 | 11 | |
12 | - protected function setUp(): void |
|
13 | - { |
|
12 | + protected function setUp(): void |
|
13 | + { |
|
14 | 14 | $this->cache = new Cacheer(); |
15 | 15 | $this->cache->setDriver()->useArrayDriver(); |
16 | 16 | $this->cache->setConfig()->setTimeZone('America/Toronto'); |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - protected function tearDown(): void |
|
20 | - { |
|
19 | + protected function tearDown(): void |
|
20 | + { |
|
21 | 21 | $this->cache->flushCache(); |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | 24 | public function testUsingArrayDriverSetsProperInstance() |
25 | - { |
|
25 | + { |
|
26 | 26 | $this->assertInstanceOf(ArrayCacheStore::class, $this->cache->cacheStore); |
27 | - } |
|
27 | + } |
|
28 | 28 | |
29 | - public function testPutAndGetCacheInArray() |
|
30 | - { |
|
31 | - $cacheKey = 'test_key'; |
|
32 | - $cacheData = ['name' => 'John Doe', 'email' => '[email protected]']; |
|
29 | + public function testPutAndGetCacheInArray() |
|
30 | + { |
|
31 | + $cacheKey = 'test_key'; |
|
32 | + $cacheData = ['name' => 'John Doe', 'email' => '[email protected]']; |
|
33 | 33 | |
34 | - $this->cache->putCache($cacheKey, $cacheData, '', 3600); |
|
34 | + $this->cache->putCache($cacheKey, $cacheData, '', 3600); |
|
35 | 35 | |
36 | - $result = $this->cache->getCache($cacheKey); |
|
36 | + $result = $this->cache->getCache($cacheKey); |
|
37 | 37 | |
38 | - $this->assertNotEmpty($result); |
|
39 | - $this->assertEquals($cacheData, $result); |
|
40 | - } |
|
38 | + $this->assertNotEmpty($result); |
|
39 | + $this->assertEquals($cacheData, $result); |
|
40 | + } |
|
41 | 41 | |
42 | - public function testExpiredCacheInArray() |
|
43 | - { |
|
42 | + public function testExpiredCacheInArray() |
|
43 | + { |
|
44 | 44 | $cacheKey = 'expired_key'; |
45 | 45 | $cacheData = ['name' => 'Expired User', 'email' => '[email protected]']; |
46 | 46 | |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | $this->assertEquals("Cache stored successfully", $this->cache->getMessage()); |
51 | 51 | $this->assertEmpty($this->cache->getCache($cacheKey)); |
52 | 52 | $this->assertFalse($this->cache->isSuccess()); |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - public function testOverwriteExistingCacheInArray() |
|
57 | - { |
|
56 | + public function testOverwriteExistingCacheInArray() |
|
57 | + { |
|
58 | 58 | $cacheKey = 'overwrite_key'; |
59 | 59 | $initialCacheData = ['name' => 'Initial Data', 'email' => '[email protected]']; |
60 | 60 | $newCacheData = ['name' => 'New Data', 'email' => '[email protected]']; |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | $this->cache->appendCache($cacheKey, $newCacheData); |
66 | 66 | $this->assertEquals("Cache appended successfully", $this->cache->getMessage()); |
67 | 67 | $this->assertEquals($newCacheData, $this->cache->getCache($cacheKey)); |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - public function testPutManyCacheItemsInArray() |
|
72 | - { |
|
73 | - $items = [ |
|
71 | + public function testPutManyCacheItemsInArray() |
|
72 | + { |
|
73 | + $items = [ |
|
74 | 74 | [ |
75 | 75 | 'cacheKey' => 'user_1_profile', |
76 | 76 | 'cacheData' => [ |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | |
97 | 97 | $this->assertEquals($item['cacheData'], $this->cache->getCache($item['cacheKey'])); |
98 | 98 | } |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - public function testHasCacheFromArray() |
|
102 | - { |
|
101 | + public function testHasCacheFromArray() |
|
102 | + { |
|
103 | 103 | $cacheKey = 'test_key'; |
104 | 104 | $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer']; |
105 | 105 | |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | |
111 | 111 | $this->cache->has($cacheKey); |
112 | 112 | $this->assertTrue($this->cache->isSuccess()); |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | public function testRenewCacheFromArray() |
116 | - { |
|
116 | + { |
|
117 | 117 | $cacheKey = 'expired_key'; |
118 | 118 | $cacheData = ['name' => 'Expired User', 'email' => '[email protected]']; |
119 | 119 | |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | $this->cache->renewCache($cacheKey, 7200); |
129 | 129 | $this->assertTrue($this->cache->isSuccess()); |
130 | 130 | $this->assertNotEmpty($this->cache->getCache($cacheKey)); |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - public function testRenewCacheWithNamespaceFromArray() |
|
134 | - { |
|
133 | + public function testRenewCacheWithNamespaceFromArray() |
|
134 | + { |
|
135 | 135 | $cacheKey = 'expired_key'; |
136 | 136 | $namespace = 'expired_namespace'; |
137 | 137 | $cacheData = ['name' => 'Expired User', 'email' => '[email protected]']; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $this->cache->renewCache($cacheKey, 7200, $namespace); |
146 | 146 | $this->assertTrue($this->cache->isSuccess()); |
147 | 147 | $this->assertNotEmpty($this->cache->getCache($cacheKey, $namespace)); |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | 150 | public function testClearCacheDataFromArray() |
151 | 151 | { |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $this->assertEquals("Cache flushed successfully", $this->cache->getMessage()); |
182 | 182 | } |
183 | 183 | |
184 | - public function test_remember_saves_and_recover_values() |
|
184 | + public function test_remember_saves_and_recover_values() |
|
185 | 185 | { |
186 | 186 | $this->cache->flushCache(); |
187 | 187 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | |
219 | - public function test_get_and_forget() |
|
219 | + public function test_get_and_forget() |
|
220 | 220 | { |
221 | 221 | $cacheKey = 'cache_key_test'; |
222 | 222 | $this->cache->putCache($cacheKey, 10); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $this->assertNull($noCacheData); |
238 | 238 | } |
239 | 239 | |
240 | - public function test_store_if_not_present_with_add_function() |
|
240 | + public function test_store_if_not_present_with_add_function() |
|
241 | 241 | { |
242 | 242 | $existentKey = 'cache_key_test'; |
243 | 243 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | |
262 | 262 | } |
263 | 263 | |
264 | - public function test_increment_function() { |
|
264 | + public function test_increment_function() { |
|
265 | 265 | |
266 | 266 | $cacheKey = 'test_increment'; |
267 | 267 | $cacheData = 2025; |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | - * @param string $cacheKey |
|
135 | - * @param int $amount |
|
136 | - * @param string $namespace |
|
137 | - * @return bool |
|
138 | - */ |
|
134 | + * @param string $cacheKey |
|
135 | + * @param int $amount |
|
136 | + * @param string $namespace |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | 139 | public function increment(string $cacheKey, int $amount = 1, string $namespace = '') |
140 | 140 | { |
141 | 141 | $cacheData = $this->getCache($cacheKey, $namespace); |
@@ -150,20 +150,20 @@ discard block |
||
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
153 | - * @param string $cacheKey |
|
154 | - * @param int $amount |
|
155 | - * @param string $namespace |
|
156 | - * @return bool |
|
157 | - */ |
|
153 | + * @param string $cacheKey |
|
154 | + * @param int $amount |
|
155 | + * @param string $namespace |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | 158 | public function decrement(string $cacheKey, int $amount = 1, string $namespace = '') |
159 | 159 | { |
160 | - return $this->increment($cacheKey, ($amount * -1), $namespace); |
|
160 | + return $this->increment($cacheKey, ($amount * -1), $namespace); |
|
161 | 161 | } |
162 | 162 | /** |
163 | - * @param string $cacheKey |
|
164 | - * @param mixed $cacheData |
|
165 | - * @return void |
|
166 | - */ |
|
163 | + * @param string $cacheKey |
|
164 | + * @param mixed $cacheData |
|
165 | + * @return void |
|
166 | + */ |
|
167 | 167 | public function forever(string $cacheKey, mixed $cacheData) |
168 | 168 | { |
169 | 169 | $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000); |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
174 | - * @param string $cacheKey |
|
175 | - * @param int|string $ttl |
|
176 | - * @param Closure $callback |
|
177 | - * @return mixed |
|
178 | - */ |
|
174 | + * @param string $cacheKey |
|
175 | + * @param int|string $ttl |
|
176 | + * @param Closure $callback |
|
177 | + * @return mixed |
|
178 | + */ |
|
179 | 179 | public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
180 | 180 | { |
181 | 181 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
@@ -192,20 +192,20 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
195 | - * @param string $cacheKey |
|
196 | - * @param Closure $callback |
|
197 | - * @return mixed |
|
198 | - */ |
|
195 | + * @param string $cacheKey |
|
196 | + * @param Closure $callback |
|
197 | + * @return mixed |
|
198 | + */ |
|
199 | 199 | public function rememberForever(string $cacheKey, Closure $callback) |
200 | 200 | { |
201 | 201 | return $this->remember($cacheKey, 31536000 * 1000, $callback); |
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
205 | - * @param string $cacheKey |
|
206 | - * @param string $namespace |
|
207 | - * @return mixed |
|
208 | - */ |
|
205 | + * @param string $cacheKey |
|
206 | + * @param string $namespace |
|
207 | + * @return mixed |
|
208 | + */ |
|
209 | 209 | public function getAndForget(string $cacheKey, string $namespace = '') |
210 | 210 | { |
211 | 211 | $cachedData = $this->getCache($cacheKey, $namespace); |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | - * @param string $cacheKey |
|
223 | - * @param mixed $cacheData |
|
224 | - * @param string $namespace |
|
225 | - * @param int|string $ttl |
|
226 | - * @return bool |
|
227 | - */ |
|
222 | + * @param string $cacheKey |
|
223 | + * @param mixed $cacheData |
|
224 | + * @param string $namespace |
|
225 | + * @param int|string $ttl |
|
226 | + * @return bool |
|
227 | + */ |
|
228 | 228 | public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
229 | 229 | { |
230 | 230 | if (!empty($this->getCache($cacheKey, $namespace))) { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param string|int $ttl |
58 | 58 | * @return CacheDataFormatter|mixed |
59 | 59 | */ |
60 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
60 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
61 | 61 | { |
62 | 62 | $cacheData = $this->cacheStore->getCache($cacheKey, $namespace, $ttl); |
63 | 63 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param string|int $ttl |
72 | 72 | * @return void |
73 | 73 | */ |
74 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
74 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
75 | 75 | { |
76 | 76 | $this->cacheStore->putCache($cacheKey, $cacheData, $namespace, $ttl); |
77 | 77 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param string $namespace |
118 | 118 | * @return mixed |
119 | 119 | */ |
120 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
120 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
121 | 121 | { |
122 | 122 | $renewedCache = $this->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
123 | 123 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | { |
141 | 141 | $cacheData = $this->getCache($cacheKey, $namespace); |
142 | 142 | |
143 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
143 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
144 | 144 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
145 | 145 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
146 | 146 | return true; |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | * @param Closure $callback |
177 | 177 | * @return mixed |
178 | 178 | */ |
179 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
179 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
180 | 180 | { |
181 | 181 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
182 | 182 | |
183 | - if(!empty($cachedData)) { |
|
183 | + if (!empty($cachedData)) { |
|
184 | 184 | return $cachedData; |
185 | 185 | } |
186 | 186 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param int|string $ttl |
226 | 226 | * @return bool |
227 | 227 | */ |
228 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
228 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
229 | 229 | { |
230 | 230 | if (!empty($this->getCache($cacheKey, $namespace))) { |
231 | 231 | return true; |