@@ -24,23 +24,23 @@ protected function tearDown(): void
2424 {
2525 // Clear cache after each test
2626 Cache::flush ();
27-
27+
2828 parent ::tearDown ();
2929 }
3030
3131 public function test_it_does_not_cache_by_default_in_tests ()
3232 {
3333 // Ensure we're in testing environment
3434 $ this ->assertEquals ('testing ' , app ()->environment ());
35-
35+
3636 // Make request
3737 $ response = $ this ->getJson ('/api/restify/posts ' );
3838 $ response ->assertOk ();
39-
39+
4040 // Make another request - should not be cached
4141 $ response2 = $ this ->getJson ('/api/restify/posts ' );
4242 $ response2 ->assertOk ();
43-
43+
4444 // Verify cache is empty (no cache keys should exist)
4545 $ this ->assertEmpty ($ this ->getCacheKeys ());
4646 }
@@ -50,11 +50,11 @@ public function test_it_can_enable_cache_in_tests_with_config()
5050 // Enable caching in tests
5151 config (['restify.repositories.cache.enabled ' => true ]);
5252 config (['restify.repositories.cache.enable_in_tests ' => true ]);
53-
53+
5454 // Make request
5555 $ response = $ this ->getJson ('/api/restify/posts ' );
5656 $ response ->assertOk ();
57-
57+
5858 // Verify cache key was created
5959 $ this ->assertNotEmpty ($ this ->getCacheKeys ());
6060 }
@@ -64,11 +64,11 @@ public function test_it_respects_global_cache_disabled_setting()
6464 // Disable caching globally
6565 config (['restify.repositories.cache.enabled ' => false ]);
6666 config (['restify.repositories.cache.enable_in_tests ' => true ]);
67-
67+
6868 // Make request
6969 $ response = $ this ->getJson ('/api/restify/posts ' );
7070 $ response ->assertOk ();
71-
71+
7272 // Verify no cache key was created
7373 $ this ->assertEmpty ($ this ->getCacheKeys ());
7474 }
@@ -77,19 +77,19 @@ public function test_it_generates_different_cache_keys_for_different_parameters(
7777 {
7878 config (['restify.repositories.cache.enabled ' => true ]);
7979 config (['restify.repositories.cache.enable_in_tests ' => true ]);
80-
80+
8181 // Clear any existing cache
8282 Cache::flush ();
83-
83+
8484 // Make request with different parameters
8585 $ this ->getJson ('/api/restify/posts?search=test ' );
8686 $ keys1 = $ this ->getCacheKeys ();
87-
87+
8888 Cache::flush ();
89-
89+
9090 $ this ->getJson ('/api/restify/posts?search=different ' );
9191 $ keys2 = $ this ->getCacheKeys ();
92-
92+
9393 // Keys should be different for different search terms
9494 $ this ->assertNotEquals ($ keys1 , $ keys2 );
9595 }
@@ -98,19 +98,19 @@ public function test_it_generates_different_cache_keys_for_different_users()
9898 {
9999 config (['restify.repositories.cache.enabled ' => true ]);
100100 config (['restify.repositories.cache.enable_in_tests ' => true ]);
101-
101+
102102 // Make request as first user
103103 $ this ->authenticate ();
104104 $ this ->getJson ('/api/restify/posts ' );
105105 $ keys1 = $ this ->getCacheKeys ();
106-
106+
107107 Cache::flush ();
108-
108+
109109 // Make request as different user
110110 $ this ->authenticate (\Binaryk \LaravelRestify \Tests \Fixtures \User \User::factory ()->create ());
111111 $ this ->getJson ('/api/restify/posts ' );
112112 $ keys2 = $ this ->getCacheKeys ();
113-
113+
114114 // Keys should be different for different users
115115 $ this ->assertNotEquals ($ keys1 , $ keys2 );
116116 }
@@ -119,15 +119,15 @@ public function test_it_can_clear_cache_programmatically()
119119 {
120120 config (['restify.repositories.cache.enabled ' => true ]);
121121 config (['restify.repositories.cache.enable_in_tests ' => true ]);
122-
122+
123123 // Make request to populate cache
124124 $ this ->getJson ('/api/restify/posts ' );
125125 $ this ->assertNotEmpty ($ this ->getCacheKeys ());
126-
126+
127127 // Clear cache using Laravel's flush for simplicity in tests
128128 // In production, the repository's clearCache method would be more targeted
129129 Cache::flush ();
130-
130+
131131 // Verify cache is cleared
132132 $ this ->assertEmpty ($ this ->getCacheKeys ());
133133 }
@@ -136,20 +136,20 @@ public function test_it_caches_responses_when_enabled()
136136 {
137137 config (['restify.repositories.cache.enabled ' => true ]);
138138 config (['restify.repositories.cache.enable_in_tests ' => true ]);
139-
139+
140140 // Make first request
141141 $ response1 = $ this ->getJson ('/api/restify/posts ' );
142142 $ response1 ->assertOk ();
143143 $ data1 = $ response1 ->json ();
144-
144+
145145 // Verify cache was created
146146 $ this ->assertNotEmpty ($ this ->getCacheKeys ());
147-
147+
148148 // Make second request - should get cached response
149149 $ response2 = $ this ->getJson ('/api/restify/posts ' );
150150 $ response2 ->assertOk ();
151151 $ data2 = $ response2 ->json ();
152-
152+
153153 // Data should be identical
154154 $ this ->assertEquals ($ data1 , $ data2 );
155155 }
@@ -158,22 +158,22 @@ public function test_it_respects_repository_specific_cache_settings()
158158 {
159159 config (['restify.repositories.cache.enabled ' => true ]);
160160 config (['restify.repositories.cache.enable_in_tests ' => true ]);
161-
161+
162162 // Disable cache for specific repository
163163 PostRepository::disableCache ();
164-
164+
165165 // Make request
166166 $ this ->getJson ('/api/restify/posts ' );
167-
167+
168168 // Verify no cache key was created
169169 $ this ->assertEmpty ($ this ->getCacheKeys ());
170-
170+
171171 // Re-enable cache
172172 PostRepository::enableCache ();
173-
173+
174174 // Make request
175175 $ this ->getJson ('/api/restify/posts ' );
176-
176+
177177 // Verify cache key was created
178178 $ this ->assertNotEmpty ($ this ->getCacheKeys ());
179179 }
@@ -182,16 +182,16 @@ public function test_it_includes_pagination_in_cache_key()
182182 {
183183 config (['restify.repositories.cache.enabled ' => true ]);
184184 config (['restify.repositories.cache.enable_in_tests ' => true ]);
185-
185+
186186 // Make request with different page numbers
187187 $ this ->getJson ('/api/restify/posts?page=1 ' );
188188 $ keys1 = $ this ->getCacheKeys ();
189-
189+
190190 Cache::flush ();
191-
191+
192192 $ this ->getJson ('/api/restify/posts?page=2 ' );
193193 $ keys2 = $ this ->getCacheKeys ();
194-
194+
195195 // Keys should be different for different pages
196196 $ this ->assertNotEquals ($ keys1 , $ keys2 );
197197 }
@@ -200,16 +200,16 @@ public function test_it_includes_filters_in_cache_key()
200200 {
201201 config (['restify.repositories.cache.enabled ' => true ]);
202202 config (['restify.repositories.cache.enable_in_tests ' => true ]);
203-
203+
204204 // Make request with filters
205205 $ this ->getJson ('/api/restify/posts?title=test ' );
206206 $ keys1 = $ this ->getCacheKeys ();
207-
207+
208208 Cache::flush ();
209-
209+
210210 $ this ->getJson ('/api/restify/posts?title=different ' );
211211 $ keys2 = $ this ->getCacheKeys ();
212-
212+
213213 // Keys should be different for different filters
214214 $ this ->assertNotEquals ($ keys1 , $ keys2 );
215215 }
@@ -218,16 +218,16 @@ public function test_it_can_set_custom_cache_ttl()
218218 {
219219 config (['restify.repositories.cache.enabled ' => true ]);
220220 config (['restify.repositories.cache.enable_in_tests ' => true ]);
221-
221+
222222 // Set custom TTL
223223 PostRepository::cacheTtl (60 ); // 1 minute
224-
224+
225225 // Make request
226226 $ this ->getJson ('/api/restify/posts ' );
227-
227+
228228 // Verify cache exists
229229 $ this ->assertNotEmpty ($ this ->getCacheKeys ());
230-
230+
231231 // Verify TTL is set (this is hard to test precisely without time manipulation)
232232 // We'll just verify the cache exists for now
233233 }
@@ -238,34 +238,35 @@ public function test_it_can_set_custom_cache_ttl()
238238 protected function getCacheKeys (): array
239239 {
240240 $ store = Cache::getStore ();
241-
241+
242242 if (method_exists ($ store , 'getRedis ' )) {
243243 try {
244244 $ redis = $ store ->getRedis ();
245+
245246 return $ redis ->keys ('*restify* ' ) ?: [];
246247 } catch (\Exception $ e ) {
247248 // Fall back for non-Redis stores
248249 }
249250 }
250-
251+
251252 // For array store (used in tests), we need to inspect the internal array
252253 if (get_class ($ store ) === 'Illuminate\Cache\ArrayStore ' ) {
253254 $ reflection = new \ReflectionClass ($ store );
254255 $ storage = $ reflection ->getProperty ('storage ' );
255256 $ storage ->setAccessible (true );
256257 $ storageArray = $ storage ->getValue ($ store );
257-
258+
258259 return array_filter (array_keys ($ storageArray ), function ($ key ) {
259260 return str_contains ($ key , 'restify ' );
260261 });
261262 }
262-
263+
263264 // Fallback - check for typical patterns (with error handling for database stores)
264265 $ patterns = [
265266 'restify:repository:posts:index ' ,
266- 'laravel_cache:restify:repository:posts:index '
267+ 'laravel_cache:restify:repository:posts:index ' ,
267268 ];
268-
269+
269270 try {
270271 foreach ($ patterns as $ pattern ) {
271272 if (Cache::has ($ pattern )) {
@@ -276,7 +277,7 @@ protected function getCacheKeys(): array
276277 // Silently fail if cache store doesn't exist (e.g., database cache table missing)
277278 return [];
278279 }
279-
280+
280281 return [];
281282 }
282- }
283+ }
0 commit comments