diff --git a/composer.json b/composer.json index 657ec47..1f7353f 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "require-dev": { "cakephp/cakephp-codesniffer": "^4.0", "phpunit/phpunit": "^8.5 || ^9.3", - "cakephp/bake": "^2.0" + "cakephp/bake": "^2.0", + "enqueue/fs": "^0.9" }, "autoload": { "psr-4": { diff --git a/tests/TestCase/Command/WorkerCommandTest.php b/tests/TestCase/Command/WorkerCommandTest.php index 008fce0..92032dc 100644 --- a/tests/TestCase/Command/WorkerCommandTest.php +++ b/tests/TestCase/Command/WorkerCommandTest.php @@ -18,8 +18,10 @@ use Cake\Core\Configure; use Cake\Log\Log; +use Cake\Queue\QueueManager; use Cake\TestSuite\ConsoleIntegrationTestTrait; use Cake\TestSuite\TestCase; +use TestApp\WelcomeMailer; use TestApp\WelcomeMailerListener; /** @@ -149,4 +151,43 @@ public function testQueueProcessesWithLogger() $this->assertNotEmpty($log->read()); $this->assertEquals($log->read()[0], 'debug Max Iterations: 0'); } + + /** + * Start up the worker queue, push a job, and see that it processes + * + * @runInSeparateProcess + */ + public function testQueueProcessesJob() + { + Configure::write([ + 'Queue' => [ + 'default' => [ + 'queue' => 'default', + 'url' => 'file:///' . TMP . DS . 'queue', + ], + ], + ]); + + Log::setConfig('debug', [ + 'className' => 'Array', + 'levels' => ['notice', 'info', 'debug'], + ]); + + $this->exec('worker --max-runtime=3 --logger=debug --verbose'); + + $callable = [WelcomeMailer::class, 'welcome']; + $arguments = []; + $options = ['config' => 'default']; + + QueueManager::push($callable, $arguments, $options); + + $log = Log::engine('debug'); + $this->assertIsArray($log->read()); + $this->assertNotEmpty($log->read()); + foreach ($log->read() as $line) { + if (stripos($line, 'Welcome mail sent') !== false) { + $this->assertTrue(true); + } + } + } } diff --git a/tests/app/TestApp/WelcomeMailer.php b/tests/app/TestApp/WelcomeMailer.php index 740fae6..0169e07 100644 --- a/tests/app/TestApp/WelcomeMailer.php +++ b/tests/app/TestApp/WelcomeMailer.php @@ -3,6 +3,7 @@ namespace TestApp; +use Cake\Log\Log; use Cake\Mailer\Mailer; use Cake\Queue\Mailer\QueueTrait; @@ -16,6 +17,7 @@ public function getName() public function welcome() { - // Do nothing. + $debug = Log::engine('debug'); + $debug->info('Welcome mail sent'); } }