diff --git a/src/Plugin.php b/src/Plugin.php index 20cfd91..d761d4b 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -50,6 +50,13 @@ class Plugin extends BasePlugin */ public function bootstrap(PluginApplicationInterface $app): void { + if (!Configure::read('Queue')) { + throw new \InvalidArgumentException( + 'Missing `Queue` configuration key, please check the CakePHP Queue documentation' . + ' to complete the plugin setup.' + ); + } + foreach (Configure::read('Queue') as $key => $data) { if (QueueManager::getConfig($key) === null) { QueueManager::setConfig($key, $data); diff --git a/tests/TestCase/PluginTest.php b/tests/TestCase/PluginTest.php new file mode 100644 index 0000000..9a8eb87 --- /dev/null +++ b/tests/TestCase/PluginTest.php @@ -0,0 +1,55 @@ +expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Missing `Queue` configuration key, please check the CakePHP Queue documentation to complete the plugin setup'); + Configure::delete('Queue'); + $plugin = new Plugin(); + $app = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock(); + $plugin->bootstrap($app); + } + + /** + * Test Plugin bootstrap with config + * + * @return void + */ + public function testBootstrapWithConfig() + { + $queueConfig = [ + 'url' => 'null:', + 'queue' => 'default', + 'logger' => 'stdout', + ]; + Configure::write('Queue', ['default' => $queueConfig]); + $plugin = new Plugin(); + $app = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock(); + $plugin->bootstrap($app); + $queueConfig['url'] = [ + 'transport' => 'null:', + 'client' => [ + 'router_topic' => 'default', + 'router_queue' => 'default', + 'default_queue' => 'default', + ], + ]; + $this->assertEquals($queueConfig, QueueManager::getConfig('default')); + } +}