Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 55 additions & 0 deletions tests/TestCase/PluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace Cake\Queue\Test\TestCase;

use Cake\Core\Configure;
use Cake\Queue\Plugin;
use Cake\Queue\QueueManager;
use Cake\TestSuite\TestCase;
use TestApp\Application;

class PluginTest extends TestCase
{
/**
* Test Plugin bootstrap with no config
*
* @return void
*/
public function testBootstrapNoConfig()
{
$this->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'));
}
}