|
18 | 18 |
|
19 | 19 | use Cake\Core\Configure; |
20 | 20 | use Cake\Log\Log; |
| 21 | +use Cake\Queue\QueueManager; |
21 | 22 | use Cake\TestSuite\ConsoleIntegrationTestTrait; |
22 | 23 | use Cake\TestSuite\TestCase; |
| 24 | +use TestApp\WelcomeMailer; |
23 | 25 | use TestApp\WelcomeMailerListener; |
24 | 26 |
|
25 | 27 | /** |
@@ -149,4 +151,43 @@ public function testQueueProcessesWithLogger() |
149 | 151 | $this->assertNotEmpty($log->read()); |
150 | 152 | $this->assertEquals($log->read()[0], 'debug Max Iterations: 0'); |
151 | 153 | } |
| 154 | + |
| 155 | + /** |
| 156 | + * Start up the worker queue, push a job, and see that it processes |
| 157 | + * |
| 158 | + * @runInSeparateProcess |
| 159 | + */ |
| 160 | + public function testQueueProcessesJob() |
| 161 | + { |
| 162 | + Configure::write([ |
| 163 | + 'Queue' => [ |
| 164 | + 'default' => [ |
| 165 | + 'queue' => 'default', |
| 166 | + 'url' => 'file:///' . TMP . DS . 'queue', |
| 167 | + ], |
| 168 | + ], |
| 169 | + ]); |
| 170 | + |
| 171 | + Log::setConfig('debug', [ |
| 172 | + 'className' => 'Array', |
| 173 | + 'levels' => ['notice', 'info', 'debug'], |
| 174 | + ]); |
| 175 | + |
| 176 | + $this->exec('worker --max-runtime=3 --logger=debug --verbose'); |
| 177 | + |
| 178 | + $callable = [WelcomeMailer::class, 'welcome']; |
| 179 | + $arguments = []; |
| 180 | + $options = ['config' => 'default']; |
| 181 | + |
| 182 | + QueueManager::push($callable, $arguments, $options); |
| 183 | + |
| 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 | + } |
| 192 | + } |
152 | 193 | } |
0 commit comments