Skip to content

Commit 81d3315

Browse files
committed
Implement exception if missing Queue config key. Fixes #102
1 parent 05cd2e1 commit 81d3315

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/Plugin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class Plugin extends BasePlugin
5050
*/
5151
public function bootstrap(PluginApplicationInterface $app): void
5252
{
53+
if (!Configure::read('Queue')) {
54+
throw new \InvalidArgumentException(
55+
'Missing `Queue` configuration key, please check the CakePHP Queue documentation' .
56+
' to complete the plugin setup.'
57+
);
58+
}
59+
5360
foreach (Configure::read('Queue') as $key => $data) {
5461
if (QueueManager::getConfig($key) === null) {
5562
QueueManager::setConfig($key, $data);

tests/TestCase/PluginTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Cake\Queue\Test\TestCase;
5+
6+
use Cake\Core\Configure;
7+
use Cake\Queue\Plugin;
8+
use Cake\Queue\QueueManager;
9+
use Cake\TestSuite\TestCase;
10+
use TestApp\Application;
11+
12+
class PluginTest extends TestCase
13+
{
14+
/**
15+
* Test Plugin bootstrap with no config
16+
*
17+
* @return void
18+
*/
19+
public function testBootstrapNoConfig()
20+
{
21+
$this->expectException(\InvalidArgumentException::class);
22+
$this->expectExceptionMessage('Missing `Queue` configuration key, please check the CakePHP Queue documentation to complete the plugin setup');
23+
Configure::delete('Queue');
24+
$plugin = new Plugin();
25+
$app = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
26+
$plugin->bootstrap($app);
27+
}
28+
29+
/**
30+
* Test Plugin bootstrap with config
31+
*
32+
* @return void
33+
*/
34+
public function testBootstrapWithConfig()
35+
{
36+
$queueConfig = [
37+
'url' => 'null:',
38+
'queue' => 'default',
39+
'logger' => 'stdout',
40+
];
41+
Configure::write('Queue', ['default' => $queueConfig]);
42+
$plugin = new Plugin();
43+
$app = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
44+
$plugin->bootstrap($app);
45+
$queueConfig['url'] = [
46+
'transport' => 'null:',
47+
'client' => [
48+
'router_topic' => 'default',
49+
'router_queue' => 'default',
50+
'default_queue' => 'default',
51+
],
52+
];
53+
$this->assertEquals($queueConfig, QueueManager::getConfig('default'));
54+
}
55+
}

0 commit comments

Comments
 (0)