@@ -146,10 +146,7 @@ public function testQueueProcessesWithLogger()
146146 ]);
147147
148148 $ this ->exec ('worker --max-runtime=1 --logger=debug --verbose ' );
149- $ log = Log::engine ('debug ' );
150- $ this ->assertIsArray ($ log ->read ());
151- $ this ->assertNotEmpty ($ log ->read ());
152- $ this ->assertEquals ($ log ->read ()[0 ], 'debug Max Iterations: 0 ' );
149+ $ this ->assertDebugLogContains ('debug Max Iterations: 0 ' );
153150 }
154151
155152 /**
@@ -159,36 +156,30 @@ public function testQueueProcessesWithLogger()
159156 */
160157 public function testQueueProcessesJob ()
161158 {
159+ $ config = [
160+ 'queue ' => 'default ' ,
161+ 'url ' => 'file:/// ' . TMP . DS . 'queue ' ,
162+ ];
162163 Configure::write ([
163- 'Queue ' => [
164- 'default ' => [
165- 'queue ' => 'default ' ,
166- 'url ' => 'file:/// ' . TMP . DS . 'queue ' ,
167- ],
168- ],
164+ 'Queue ' => ['default ' => $ config ],
169165 ]);
170166
171167 Log::setConfig ('debug ' , [
172168 'className ' => 'Array ' ,
173169 'levels ' => ['notice ' , 'info ' , 'debug ' ],
174170 ]);
175171
176- $ this ->exec ('worker --max-runtime=3 --logger=debug --verbose ' );
177-
178172 $ callable = [WelcomeMailer::class, 'welcome ' ];
179173 $ arguments = [];
180174 $ options = ['config ' => 'default ' ];
181175
176+ QueueManager::setConfig ('default ' , $ config );
182177 QueueManager::push ($ callable , $ arguments , $ options );
178+ QueueManager::drop ('default ' );
183179
184- $ log = Log::engine ('debug ' );
185- $ this ->assertIsArray ($ log ->read ());
186- $ this ->assertNotEmpty ($ log ->read ());
187- foreach ($ log ->read () as $ line ) {
188- if (stripos ($ line , 'Welcome mail sent ' ) !== false ) {
189- $ this ->assertTrue (true );
190- }
191- }
180+ $ this ->exec ('worker --max-runtime=3 --logger=debug --verbose ' );
181+
182+ $ this ->assertDebugLogContains ('Welcome mail sent ' );
192183 }
193184
194185 /**
@@ -198,35 +189,74 @@ public function testQueueProcessesJob()
198189 */
199190 public function testQueueProcessesJobWithProcessor ()
200191 {
192+ $ config = [
193+ 'queue ' => 'default ' ,
194+ 'url ' => 'file:/// ' . TMP . DS . 'queue ' ,
195+ ];
201196 Configure::write ([
202- 'Queue ' => [
203- 'default ' => [
204- 'queue ' => 'default ' ,
205- 'url ' => 'file:/// ' . TMP . DS . 'queue ' ,
206- ],
207- ],
197+ 'Queue ' => ['default ' => $ config ],
208198 ]);
209-
210199 Log::setConfig ('debug ' , [
211200 'className ' => 'Array ' ,
212201 'levels ' => ['notice ' , 'info ' , 'debug ' ],
213202 ]);
214203
204+ $ callable = [WelcomeMailer::class, 'welcome ' ];
205+ $ arguments = [];
206+ $ options = ['config ' => 'default ' ];
207+
208+ QueueManager::setConfig ('default ' , $ config );
209+ QueueManager::push ($ callable , $ arguments , $ options );
210+ QueueManager::drop ('default ' );
211+
215212 $ this ->exec ('worker --max-runtime=3 --processor=processor-name --logger=debug --verbose ' );
216213
214+ $ this ->assertDebugLogContains ('Welcome mail sent ' );
215+ }
216+
217+ /**
218+ * Test non-default queue name
219+ *
220+ * @runInSeparateProcess
221+ */
222+ public function testQueueProcessesJobWithOtherQueue ()
223+ {
224+ $ config = [
225+ 'queue ' => 'other ' ,
226+ 'url ' => 'file:/// ' . TMP . DS . 'queue ' ,
227+ ];
228+ Configure::write ([
229+ 'Queue ' => ['other ' => $ config ],
230+ ]);
231+
232+ Log::setConfig ('debug ' , [
233+ 'className ' => 'Array ' ,
234+ 'levels ' => ['notice ' , 'info ' , 'debug ' ],
235+ ]);
236+
217237 $ callable = [WelcomeMailer::class, 'welcome ' ];
218238 $ arguments = [];
219- $ options = ['config ' => 'default ' ];
239+ $ options = ['config ' => 'other ' ];
220240
241+ QueueManager::setConfig ('other ' , $ config );
221242 QueueManager::push ($ callable , $ arguments , $ options );
243+ QueueManager::drop ('other ' );
244+
245+ $ this ->exec ('worker --config=other --max-runtime=3 --processor=processor-name --logger=debug --verbose ' );
222246
247+ $ this ->assertDebugLogContains ('Welcome mail sent ' );
248+ }
249+
250+ protected function assertDebugLogContains ($ expected ): void
251+ {
223252 $ log = Log::engine ('debug ' );
224- $ this ->assertIsArray ($ log ->read ());
225- $ this ->assertNotEmpty ($ log ->read ());
253+ $ found = false ;
226254 foreach ($ log ->read () as $ line ) {
227- if (stripos ($ line , 'Welcome mail sent ' ) !== false ) {
228- $ this ->assertTrue (true );
255+ if (strpos ($ line , $ expected ) !== false ) {
256+ $ found = true ;
257+ break ;
229258 }
230259 }
260+ $ this ->assertTrue ($ found , "Did not find ` {$ expected }` in logs. " );
231261 }
232262}
0 commit comments