8
8
use App \BookWithCustomKey ;
9
9
use App \Product ;
10
10
use Illuminate \Support \Facades \Artisan ;
11
+ use Illuminate \Support \Facades \Bus ;
12
+ use Matchish \ScoutElasticSearch \Jobs \Import ;
13
+ use Matchish \ScoutElasticSearch \Jobs \QueueableJob ;
11
14
use stdClass ;
12
15
use Symfony \Component \Console \Output \BufferedOutput ;
13
16
use Tests \IntegrationTestCase ;
@@ -19,11 +22,11 @@ public function test_import_entites(): void
19
22
$ dispatcher = Product::getEventDispatcher ();
20
23
Product::unsetEventDispatcher ();
21
24
22
- $ productsAmount = rand (1 , 5 );
25
+ $ productsAmount = random_int (1 , 5 );
23
26
24
27
factory (Product::class, $ productsAmount )->create ();
25
28
26
- $ productsUnsearchableAmount = rand (1 , 5 );
29
+ $ productsUnsearchableAmount = random_int (1 , 5 );
27
30
factory (Product::class, $ productsUnsearchableAmount )->states (['archive ' ])->create ();
28
31
29
32
Product::setEventDispatcher ($ dispatcher );
@@ -50,7 +53,7 @@ public function test_import_entites_in_queue(): void
50
53
$ dispatcher = Product::getEventDispatcher ();
51
54
Product::unsetEventDispatcher ();
52
55
53
- $ productsAmount = rand (1 , 5 );
56
+ $ productsAmount = random_int (1 , 5 );
54
57
factory (Product::class, $ productsAmount )->create ();
55
58
56
59
Product::setEventDispatcher ($ dispatcher );
@@ -134,7 +137,7 @@ public function test_remove_old_index_after_switching_to_new(): void
134
137
$ dispatcher = Product::getEventDispatcher ();
135
138
Product::unsetEventDispatcher ();
136
139
137
- $ productsAmount = rand (1 , 5 );
140
+ $ productsAmount = random_int (1 , 5 );
138
141
139
142
factory (Product::class, $ productsAmount )->create ();
140
143
@@ -145,7 +148,7 @@ public function test_remove_old_index_after_switching_to_new(): void
145
148
$ this ->assertFalse ($ this ->elasticsearch ->indices ()->exists (['index ' => 'products_old ' ])->asBool (), 'Old index must be deleted ' );
146
149
}
147
150
148
- public function test_progress_report ()
151
+ public function test_progress_report (): void
149
152
{
150
153
$ output = new BufferedOutput ();
151
154
Artisan::call ('scout:import ' , ['searchable ' => [Product::class, Book::class]], $ output );
@@ -165,7 +168,7 @@ public function test_progress_report()
165
168
trim ($ output [30 ]));
166
169
}
167
170
168
- public function test_progress_report_in_queue ()
171
+ public function test_progress_report_in_queue (): void
169
172
{
170
173
$ this ->app ['config ' ]->set ('scout.queue ' , ['connection ' => 'sync ' , 'queue ' => 'scout ' ]);
171
174
@@ -177,4 +180,92 @@ public function test_progress_report_in_queue()
177
180
$ this ->assertContains (trans ('scout::import.start ' , ['searchable ' => Product::class]), $ output );
178
181
$ this ->assertContains ('[OK] ' .trans ('scout::import.done.queue ' , ['searchable ' => Product::class]), $ output );
179
182
}
183
+
184
+ public function test_queue_timeout_configuration (): void
185
+ {
186
+ Bus::fake ([
187
+ QueueableJob::class,
188
+ ]);
189
+
190
+ $ this ->app ['config ' ]->set ('scout.queue ' , ['connection ' => 'sync ' , 'queue ' => 'scout ' ]);
191
+ $ this ->app ['config ' ]->set ('elasticsearch.queue.timeout ' , 2 );
192
+
193
+ $ output = new BufferedOutput ();
194
+ Artisan::call ('scout:import ' , [], $ output );
195
+
196
+ $ output = array_map ('trim ' , explode ("\n" , $ output ->fetch ()));
197
+
198
+ $ this ->assertContains (trans ('scout::import.start ' , ['searchable ' => Product::class]), $ output );
199
+ $ this ->assertContains ('[OK] ' .trans ('scout::import.done.queue ' , ['searchable ' => Product::class]), $ output );
200
+
201
+ Bus::assertDispatched (function (QueueableJob $ job ) {
202
+ return $ job ->timeout === 2 ;
203
+ });
204
+ }
205
+
206
+ public function test_chained_queue_timeout_configuration (): void
207
+ {
208
+ Bus::fake ([
209
+ Import::class,
210
+ ]);
211
+
212
+ $ this ->app ['config ' ]->set ('scout.queue ' , ['connection ' => 'sync ' , 'queue ' => 'scout ' ]);
213
+ $ this ->app ['config ' ]->set ('elasticsearch.queue.timeout ' , 2 );
214
+
215
+ $ output = new BufferedOutput ();
216
+ Artisan::call ('scout:import ' , [], $ output );
217
+
218
+ $ output = array_map ('trim ' , explode ("\n" , $ output ->fetch ()));
219
+
220
+ $ this ->assertContains (trans ('scout::import.start ' , ['searchable ' => Product::class]), $ output );
221
+ $ this ->assertContains ('[OK] ' .trans ('scout::import.done.queue ' , ['searchable ' => Product::class]), $ output );
222
+
223
+ Bus::assertDispatched (function (Import $ job ) {
224
+ return $ job ->timeout === 2 ;
225
+ });
226
+ }
227
+
228
+ public function test_chained_queue_timeout_configuration_with_null_value (): void
229
+ {
230
+ Bus::fake ([
231
+ Import::class,
232
+ ]);
233
+
234
+ $ this ->app ['config ' ]->set ('scout.queue ' , ['connection ' => 'sync ' , 'queue ' => 'scout ' ]);
235
+ $ this ->app ['config ' ]->set ('elasticsearch.queue.timeout ' , null );
236
+
237
+ $ output = new BufferedOutput ();
238
+ Artisan::call ('scout:import ' , [], $ output );
239
+
240
+ $ output = array_map ('trim ' , explode ("\n" , $ output ->fetch ()));
241
+
242
+ $ this ->assertContains (trans ('scout::import.start ' , ['searchable ' => Product::class]), $ output );
243
+ $ this ->assertContains ('[OK] ' .trans ('scout::import.done.queue ' , ['searchable ' => Product::class]), $ output );
244
+
245
+ Bus::assertDispatched (function (Import $ job ) {
246
+ return $ job ->timeout === null ;
247
+ });
248
+ }
249
+
250
+ public function test_chained_queue_timeout_configuration_with_empty_string (): void
251
+ {
252
+ Bus::fake ([
253
+ Import::class,
254
+ ]);
255
+
256
+ $ this ->app ['config ' ]->set ('scout.queue ' , ['connection ' => 'sync ' , 'queue ' => 'scout ' ]);
257
+ $ this ->app ['config ' ]->set ('elasticsearch.queue.timeout ' , '' );
258
+
259
+ $ output = new BufferedOutput ();
260
+ Artisan::call ('scout:import ' , [], $ output );
261
+
262
+ $ output = array_map ('trim ' , explode ("\n" , $ output ->fetch ()));
263
+
264
+ $ this ->assertContains (trans ('scout::import.start ' , ['searchable ' => Product::class]), $ output );
265
+ $ this ->assertContains ('[OK] ' .trans ('scout::import.done.queue ' , ['searchable ' => Product::class]), $ output );
266
+
267
+ Bus::assertDispatched (function (Import $ job ) {
268
+ return $ job ->timeout === null ;
269
+ });
270
+ }
180
271
}
0 commit comments