|
| 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