Skip to content

Commit 7240c2d

Browse files
authored
Merge pull request #22 from cakephp/more-tests
Add more tests.
2 parents dc1bc8b + 58883b2 commit 7240c2d

2 files changed

Lines changed: 98 additions & 2 deletions

File tree

src/QueueManager.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ public static function setConfig($key, $config = null): void
9090

9191
if (isset(static::$_config[$key])) {
9292
/** @psalm-suppress PossiblyInvalidArgument */
93-
throw new BadMethodCallException(sprintf('Cannot reconfigure existing key "%s"', $key));
93+
throw new BadMethodCallException(sprintf('Cannot reconfigure existing key `%s`', $key));
9494
}
9595

9696
if (empty($config['url'])) {
97-
throw new BadMethodCallException('Must specify "url" key');
97+
throw new BadMethodCallException('Must specify `url` key.');
9898
}
9999

100100
/** @psalm-suppress InvalidPropertyAssignmentValue */
@@ -112,6 +112,17 @@ public static function getConfig(string $key)
112112
return static::$_config[$key] ?? null;
113113
}
114114

115+
/**
116+
* Remove a configured queue adapter.
117+
*
118+
* @param string $key The config name to drop.
119+
* @return void
120+
*/
121+
public static function drop(string $key): void
122+
{
123+
unset(static::$_clients[$key], static::$_config[$key]);
124+
}
125+
115126
/**
116127
* Get a queueing engine
117128
*
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)