-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathRdKafkaConnectionFactoryConfigTest.php
91 lines (76 loc) · 2.39 KB
/
RdKafkaConnectionFactoryConfigTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Enqueue\RdKafka\Tests;
use Enqueue\RdKafka\RdKafkaConnectionFactory;
use Enqueue\Test\ClassExtensionTrait;
use Enqueue\Test\ReadAttributeTrait;
use PHPUnit\Framework\TestCase;
/**
* The class contains the factory tests dedicated to configuration.
*/
class RdKafkaConnectionFactoryConfigTest extends TestCase
{
use ClassExtensionTrait;
use ReadAttributeTrait;
public function testThrowNeitherArrayStringNorNullGivenAsConfig()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The config must be either an array of options, a DSN string or null');
new RdKafkaConnectionFactory(new \stdClass());
}
public function testThrowIfSchemeIsNotSupported()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The given DSN scheme "http" is not supported. Could be "kafka" only.');
new RdKafkaConnectionFactory('http://example.com');
}
/**
* @dataProvider provideConfigs
*/
public function testShouldParseConfigurationAsExpected($config, $expectedConfig)
{
$factory = new RdKafkaConnectionFactory($config);
$config = $this->readAttribute($factory, 'config');
$this->assertNotEmpty($config['global']['group.id']);
$config['global']['group.id'] = 'group-id';
$this->assertSame($expectedConfig, $config);
}
public static function provideConfigs()
{
yield [
null,
[
'global' => [
'group.id' => 'group-id',
'metadata.broker.list' => 'localhost:9092',
],
],
];
yield [
'kafka:',
[
'global' => [
'group.id' => 'group-id',
'metadata.broker.list' => 'localhost:9092',
],
],
];
yield [
'kafka://user:pass@host:10000/db',
[
'global' => [
'group.id' => 'group-id',
'metadata.broker.list' => 'host:10000',
],
],
];
yield [
[],
[
'global' => [
'group.id' => 'group-id',
'metadata.broker.list' => 'localhost:9092',
],
],
];
}
}