55use Illuminate \Support \Facades \Config ;
66use Illuminate \Support \Facades \DB ;
77use Illuminate \Support \Facades \Cache ;
8- use Carbon \Carbon ;
98use Illuminate \Support \Facades \Redis ;
109use Mockery ;
1110use Padosoft \SuperCacheInvalidate \Helpers \SuperCacheInvalidationHelper ;
@@ -25,37 +24,26 @@ public function test_process_events_with_associated_identifiers_within_window():
2524 // Mock data
2625 $ now = now ();
2726 $ events = collect ([
28- (object )[
29- 'id ' => 1 ,
30- 'type ' => 'key ' ,
31- 'identifier ' => 'article_ID:7 ' ,
32- 'reason ' => 'Article 7 removed ' ,
33- 'connection_name ' => 'default ' ,
34- 'shard ' => 0 ,
35- 'priority ' => 0 ,
36- 'event_time ' => $ now ,
37- 'partition_key ' => 0 ,
38- ],
39- ]);
40-
41- /*
42- $associations = collect([
43- (object)[
44- 'event_id' => 1,
45- 'associated_type' => 'tag',
46- 'associated_identifier' => 'plp:sport',
47- 'connection_name' => 'default',
48- ],
49- ]);
50- */
51-
52- Config::set ('super_cache_invalidate.invalidation_window ' , 1 );
27+ (object )[
28+ 'id ' => 1 ,
29+ 'type ' => 'key ' ,
30+ 'identifier ' => 'article_ID:7 ' ,
31+ 'reason ' => 'Article 7 removed ' ,
32+ 'connection_name ' => 'default ' ,
33+ 'shard ' => 0 ,
34+ 'priority ' => 0 ,
35+ 'event_time ' => $ now ,
36+ 'partition_key ' => 0 ,
37+ ],
38+ ]);
39+
40+ Config::set ('super_cache_invalidate.invalidation_window ' , 0 );
5341
5442 // Recupera il valore di configurazione per verificare che sia stato impostato
5543 $ value = config ('super_cache_invalidate.invalidation_window ' );
5644
5745 // Asserzione
58- $ this ->assertEquals (1 , $ value );
46+ $ this ->assertEquals (0 , $ value );
5947
6048 $ partitionCache_invalidation_events = $ this ->helper ->getCacheInvalidationEventsUnprocessedPartitionName (0 , 0 );
6149
@@ -72,6 +60,11 @@ public function test_process_events_with_associated_identifiers_within_window():
7260 ->andReturnSelf ()
7361 ;
7462
63+ DB ::shouldReceive ('select ' )
64+ ->once ()
65+ ->with (['id ' , 'type ' , 'identifier ' , 'connection_name ' , 'partition_key ' , 'event_time ' ])
66+ ->andReturnSelf ();
67+
7568 DB ::shouldReceive ('where ' )
7669 ->once ()
7770 ->with ('processed ' , '= ' , 0 )
@@ -118,65 +111,11 @@ public function test_process_events_with_associated_identifiers_within_window():
118111 ->once ()
119112 ->andReturn ($ events )
120113 ;
121- //DB::shouldReceive('table->raw->where->where->where->where->where->orderBy->limit->get')
122- // ->andReturn($events)
123- //;
124-
125- /*
126- DB::shouldReceive('table->whereIn->get->groupBy')
127- ->andReturn($associations)
128- ;
129- */
130-
131- // Mock last invalidation times
132- DB ::shouldReceive ('select ' )
133- ->andReturn ([
134- (object )[
135- 'identifier_type ' => 'key ' ,
136- 'identifier ' => 'article_ID:7 ' ,
137- 'last_invalidated ' => Carbon::now ()->subSeconds (120 )->toDateTimeString (),
138- ],
139- //(object)[
140- // 'identifier_type' => 'tag',
141- // 'identifier' => 'plp:sport',
142- // 'last_invalidated' => Carbon::now()->subSeconds(180)->toDateTimeString(),
143- //],
144- ])
145- ;
146- // Mock DB::statement
147- DB ::shouldReceive ('statement ' )
148- ->once ()
149- ->with ('SET FOREIGN_KEY_CHECKS=0; ' )
150- ->andReturn (true );
151-
152-
153- DB ::shouldReceive ('statement ' )
154- ->once ()
155- ->with ('SET UNIQUE_CHECKS=0; ' )
156- ->andReturn (true );
157-
158-
159- // Mock update or insert
160- DB ::shouldReceive ('table ' )
161- ->once ()
162- ->with ('cache_invalidation_timestamps ' )
163- ->andReturnSelf ();
164-
165- DB ::shouldReceive ('updateOrInsert ' )
166- ->once ()
167- ->andReturn (true );
168-
169- DB ::shouldReceive ('statement ' )
170- ->once ()
171- ->with ('SET FOREIGN_KEY_CHECKS=1; ' )
172- ->andReturn (true );
173-
174114
175- DB ::shouldReceive ('statement ' )
176- ->once ()
177- ->with ('SET UNIQUE_CHECKS=1; ' )
178- ->andReturn (true );
179- //DB::shouldReceive('beginTransaction')->once();
115+ //DB::shouldReceive('toArray')
116+ // ->once()
117+ // ->andReturn($events->toArray())
118+ //;
180119
181120 // CHIAVE
182121 // Mock Cache
@@ -225,44 +164,52 @@ public function test_process_events_with_associated_identifiers_within_window():
225164
226165 // Mock DB::statement
227166 DB ::shouldReceive ('statement ' )
228- ->atLeast ()->once ()
229- ->with ('SET FOREIGN_KEY_CHECKS=0; ' )
230- ->andReturn (true );
167+ ->atLeast ()->once ()
168+ ->with ('SET FOREIGN_KEY_CHECKS=0; ' )
169+ ->andReturn (true )
170+ ;
231171
232172 DB ::shouldReceive ('statement ' )
233173 ->atLeast ()->once ()
234- ->with ('SET UNIQUE_CHECKS=0; ' )
235- ->andReturn (true );
174+ ->with ('SET UNIQUE_CHECKS=0; ' )
175+ ->andReturn (true )
176+ ;
236177
237178 // Mock the DB facade
238179 DB ::shouldReceive ('table ' )
239- ->once ()
240- ->with ('cache_invalidation_events ' )
241- ->andReturnSelf ();
180+ ->once ()
181+ ->with ('cache_invalidation_events ' )
182+ ->andReturnSelf ()
183+ ;
242184
243185 DB ::shouldReceive ('whereIn ' )
244- ->once ()
245- ->andReturnSelf ();
186+ ->once ()
187+ ->andReturnSelf ()
188+ ;
246189
247190 DB ::shouldReceive ('whereIn ' )
248- ->once ()
249- ->andReturnSelf ();
191+ ->once ()
192+ ->andReturnSelf ()
193+ ;
250194
251195 DB ::shouldReceive ('update ' )
252- ->once ()
253- ->andReturn (1 ); // Simulate the number of rows updated
196+ ->once ()
197+ ->andReturn (1 ) // Simulate the number of rows updated
198+ ;
254199
255200
256201 // Mock DB::statement
257202 DB ::shouldReceive ('statement ' )
258203 ->atLeast ()->once ()
259- ->with ('SET FOREIGN_KEY_CHECKS=1; ' )
260- ->andReturn (true );
204+ ->with ('SET FOREIGN_KEY_CHECKS=1; ' )
205+ ->andReturn (true )
206+ ;
261207
262208 DB ::shouldReceive ('statement ' )
263209 ->atLeast ()->once ()
264- ->with ('SET UNIQUE_CHECKS=1; ' )
265- ->andReturn (true );
210+ ->with ('SET UNIQUE_CHECKS=1; ' )
211+ ->andReturn (true )
212+ ;
266213
267214 //DB::shouldReceive('commit')->once();
268215 Redis::connection ('default ' )->del ('shard_lock:0_0 ' );
0 commit comments