Skip to content

Commit ed4c6d8

Browse files
committed
[client] udpdate config.
1 parent db6dfcd commit ed4c6d8

File tree

2 files changed

+192
-6
lines changed

2 files changed

+192
-6
lines changed

pkg/enqueue/Client/Config.php

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@ class Config
77
const PARAMETER_TOPIC_NAME = 'enqueue.topic_name';
88
const PARAMETER_COMMAND_NAME = 'enqueue.command_name';
99
const PARAMETER_PROCESSOR_NAME = 'enqueue.processor_name';
10+
11+
/**
12+
* @deprecated
13+
*/
1014
const PARAMETER_PROCESSOR_QUEUE_NAME = 'enqueue.processor_queue_name';
15+
16+
/**
17+
* @deprecated
18+
*/
1119
const DEFAULT_PROCESSOR_QUEUE_NAME = 'default';
20+
21+
/**
22+
* @deprecated
23+
*/
1224
const COMMAND_TOPIC = '__command__';
1325

1426
/**
@@ -48,12 +60,29 @@ class Config
4860

4961
public function __construct(string $prefix, string $appName, string $routerTopicName, string $routerQueueName, string $defaultProcessorQueueName, string $routerProcessorName, array $transportConfig = [])
5062
{
51-
$this->prefix = $prefix;
52-
$this->appName = $appName;
53-
$this->routerTopicName = $routerTopicName;
54-
$this->routerQueueName = $routerQueueName;
55-
$this->defaultProcessorQueueName = $defaultProcessorQueueName;
56-
$this->routerProcessorName = $routerProcessorName;
63+
$this->prefix = trim($prefix);
64+
$this->appName = trim($appName);
65+
66+
$this->routerTopicName = trim($routerTopicName);
67+
if (empty($this->routerTopicName)) {
68+
throw new \InvalidArgumentException('Router topic is empty.');
69+
}
70+
71+
$this->routerQueueName = trim($routerQueueName);
72+
if (empty($this->routerQueueName)) {
73+
throw new \InvalidArgumentException('Router queue is empty.');
74+
}
75+
76+
$this->defaultProcessorQueueName = trim($defaultProcessorQueueName);
77+
if (empty($this->defaultProcessorQueueName)) {
78+
throw new \InvalidArgumentException('Default processor queue name is empty.');
79+
}
80+
81+
$this->routerProcessorName = trim($routerProcessorName);
82+
if (empty($this->routerProcessorName)) {
83+
throw new \InvalidArgumentException('Router processor name is empty.');
84+
}
85+
5786
$this->transportConfig = $transportConfig;
5887
}
5988

@@ -62,6 +91,11 @@ public function getPrefix(): string
6291
return $this->prefix;
6392
}
6493

94+
public function getSeparator(): string
95+
{
96+
return '.';
97+
}
98+
6599
public function getAppName(): string
66100
{
67101
return $this->appName;
@@ -87,16 +121,27 @@ public function getRouterProcessorName(): string
87121
return $this->routerProcessorName;
88122
}
89123

124+
/**
125+
* @deprecated
126+
*/
90127
public function createTransportRouterTopicName(string $name): string
91128
{
92129
return strtolower(implode('.', array_filter([trim($this->prefix), trim($name)])));
93130
}
94131

132+
/**
133+
* @deprecated
134+
*/
95135
public function createTransportQueueName(string $name): string
96136
{
97137
return strtolower(implode('.', array_filter([trim($this->prefix), trim($this->appName), trim($name)])));
98138
}
99139

140+
/**
141+
* @deprecated
142+
*
143+
* @param null|mixed $default
144+
*/
100145
public function getTransportOption(string $name, $default = null)
101146
{
102147
return array_key_exists($name, $this->transportConfig) ? $this->transportConfig[$name] : $default;

pkg/enqueue/Tests/Client/ConfigTest.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,68 @@
77

88
class ConfigTest extends TestCase
99
{
10+
public function testShouldReturnPrefixSetInConstructor()
11+
{
12+
$config = new Config(
13+
'thePrefix',
14+
'aApp',
15+
'aRouterTopicName',
16+
'aRouterQueueName',
17+
'aDefaultQueueName',
18+
'aRouterProcessorName'
19+
);
20+
21+
$this->assertEquals('thePrefix', $config->getPrefix());
22+
}
23+
24+
/**
25+
* @dataProvider provideEmptyStrings
26+
*/
27+
public function testShouldTrimReturnPrefixSetInConstructor(string $empty)
28+
{
29+
$config = new Config(
30+
$empty,
31+
'aApp',
32+
'aRouterTopicName',
33+
'aRouterQueueName',
34+
'aDefaultQueueName',
35+
'aRouterProcessorName'
36+
);
37+
38+
$this->assertSame('', $config->getPrefix());
39+
}
40+
41+
public function testShouldReturnAppNameSetInConstructor()
42+
{
43+
$config = new Config(
44+
'aPrefix',
45+
'theApp',
46+
'aRouterTopicName',
47+
'aRouterQueueName',
48+
'aDefaultQueueName',
49+
'aRouterProcessorName'
50+
);
51+
52+
$this->assertEquals('theApp', $config->getAppName());
53+
}
54+
55+
/**
56+
* @dataProvider provideEmptyStrings
57+
*/
58+
public function testShouldTrimReturnAppNameSetInConstructor(string $empty)
59+
{
60+
$config = new Config(
61+
'aPrefix',
62+
$empty,
63+
'aRouterTopicName',
64+
'aRouterQueueName',
65+
'aDefaultQueueName',
66+
'aRouterProcessorName'
67+
);
68+
69+
$this->assertSame('', $config->getAppName());
70+
}
71+
1072
public function testShouldReturnRouterProcessorNameSetInConstructor()
1173
{
1274
$config = new Config(
@@ -142,4 +204,83 @@ public function testShouldCreateDefaultConfig()
142204
$this->assertSame('default', $config->getRouterQueueName());
143205
$this->assertSame('router', $config->getRouterTopicName());
144206
}
207+
208+
/**
209+
* @dataProvider provideEmptyStrings
210+
*/
211+
public function testThrowIfRouterTopicNameIsEmpty(string $empty)
212+
{
213+
$this->expectException(\InvalidArgumentException::class);
214+
$this->expectExceptionMessage('Router topic is empty.');
215+
new Config(
216+
'',
217+
'',
218+
$empty,
219+
'aRouterQueueName',
220+
'aDefaultQueueName',
221+
'aRouterProcessorName'
222+
);
223+
}
224+
225+
/**
226+
* @dataProvider provideEmptyStrings
227+
*/
228+
public function testThrowIfRouterQueueNameIsEmpty(string $empty)
229+
{
230+
$this->expectException(\InvalidArgumentException::class);
231+
$this->expectExceptionMessage('Router queue is empty.');
232+
new Config(
233+
'',
234+
'',
235+
'aRouterTopicName',
236+
$empty,
237+
'aDefaultQueueName',
238+
'aRouterProcessorName'
239+
);
240+
}
241+
242+
/**
243+
* @dataProvider provideEmptyStrings
244+
*/
245+
public function testThrowIfDefaultQueueNameIsEmpty(string $empty)
246+
{
247+
$this->expectException(\InvalidArgumentException::class);
248+
$this->expectExceptionMessage('Default processor queue name is empty.');
249+
new Config(
250+
'',
251+
'',
252+
'aRouterTopicName',
253+
'aRouterQueueName',
254+
$empty,
255+
'aRouterProcessorName'
256+
);
257+
}
258+
259+
/**
260+
* @dataProvider provideEmptyStrings
261+
*/
262+
public function testThrowIfRouterProcessorNameIsEmpty(string $empty)
263+
{
264+
$this->expectException(\InvalidArgumentException::class);
265+
$this->expectExceptionMessage('Router processor name is empty.');
266+
new Config(
267+
'',
268+
'',
269+
'aRouterTopicName',
270+
'aRouterQueueName',
271+
'aDefaultQueueName',
272+
$empty
273+
);
274+
}
275+
276+
public function provideEmptyStrings()
277+
{
278+
yield [''];
279+
280+
yield [' '];
281+
282+
yield [' '];
283+
284+
yield ["\t"];
285+
}
145286
}

0 commit comments

Comments
 (0)