|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) |
| 6 | + * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
| 7 | + * |
| 8 | + * Licensed under The MIT License |
| 9 | + * For full copyright and license information, please see the LICENSE.txt |
| 10 | + * Redistributions of files must retain the above copyright notice. |
| 11 | + * |
| 12 | + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
| 13 | + * @link http://cakephp.org CakePHP(tm) Project |
| 14 | + * @since 0.1.0 |
| 15 | + * @license http://www.opensource.org/licenses/mit-license.php MIT License |
| 16 | + */ |
| 17 | +namespace Queue\Test\TestCase; |
| 18 | + |
| 19 | +use BadMethodCallException; |
| 20 | +use Cake\Log\Log; |
| 21 | +use Cake\TestSuite\TestCase; |
| 22 | +use Enqueue\SimpleClient\SimpleClient; |
| 23 | +use LogicException; |
| 24 | +use Queue\QueueManager; |
| 25 | + |
| 26 | +/** |
| 27 | + * QueueManager test |
| 28 | + */ |
| 29 | +class QueueManagerTest extends TestCase |
| 30 | +{ |
| 31 | + public function tearDown(): void |
| 32 | + { |
| 33 | + parent::tearDown(); |
| 34 | + QueueManager::drop('test'); |
| 35 | + Log::drop('test'); |
| 36 | + } |
| 37 | + |
| 38 | + public function testSetConfig() |
| 39 | + { |
| 40 | + $result = QueueManager::setConfig('test', [ |
| 41 | + 'url' => 'null:', |
| 42 | + ]); |
| 43 | + $this->assertNull($result); |
| 44 | + |
| 45 | + $config = QueueManager::getConfig('test'); |
| 46 | + $this->assertSame('null:', $config['url']); |
| 47 | + } |
| 48 | + |
| 49 | + public function testSetConfigInvalidValue() |
| 50 | + { |
| 51 | + $this->expectException(LogicException::class); |
| 52 | + QueueManager::setConfig('test', null); |
| 53 | + } |
| 54 | + |
| 55 | + public function testSetConfigNoUrl() |
| 56 | + { |
| 57 | + $this->expectException(BadMethodCallException::class); |
| 58 | + $this->expectExceptionMessage('Must specify `url`'); |
| 59 | + QueueManager::setConfig('test', ['queue' => 'test']); |
| 60 | + } |
| 61 | + |
| 62 | + public function testSetConfigOverwrite() |
| 63 | + { |
| 64 | + QueueManager::setConfig('test', [ |
| 65 | + 'url' => 'null:', |
| 66 | + ]); |
| 67 | + $this->expectException(BadMethodCallException::class); |
| 68 | + $this->expectExceptionMessage('Cannot reconfigure'); |
| 69 | + QueueManager::setConfig('test', [ |
| 70 | + 'url' => 'redis:', |
| 71 | + ]); |
| 72 | + } |
| 73 | + |
| 74 | + public function testEngine() |
| 75 | + { |
| 76 | + QueueManager::setConfig('test', [ |
| 77 | + 'queue' => 'default', |
| 78 | + 'url' => 'null:', |
| 79 | + ]); |
| 80 | + $engine = QueueManager::engine('test'); |
| 81 | + $this->assertInstanceOf(SimpleClient::class, $engine); |
| 82 | + |
| 83 | + $this->assertSame($engine, QueueManager::engine('test')); |
| 84 | + } |
| 85 | +} |
0 commit comments