1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Tests\Happyr\ElasticaDsn; |
6
|
|
|
|
7
|
|
|
use Happyr\ElasticaDsn\ClientFactory; |
8
|
|
|
use Nyholm\NSA; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class ClientFactoryTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @dataProvider getServers |
15
|
|
|
*/ |
16
|
|
|
public function testGetConfig($servers, array $options, array $expected) |
17
|
|
|
{ |
18
|
|
|
$output = NSA::invokeMethod(ClientFactory::class, 'doGetConfig', $servers, $options); |
19
|
|
|
$this->assertEquals($expected, $output); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getServers() |
23
|
|
|
{ |
24
|
|
|
yield [['elasticsearch:localhost'], [], ['servers' => [['host' => 'localhost', 'port' => 9200]]]]; |
25
|
|
|
yield [['elasticsearch://localhost'], [], ['servers' => [['host' => 'localhost', 'port' => 9200]]]]; |
26
|
|
|
yield [['elasticsearch://example.com'], [], ['servers' => [['host' => 'example.com', 'port' => 9200]]]]; |
27
|
|
|
yield [['elasticsearch://localhost:1234'], [], ['servers' => [['host' => 'localhost', 'port' => 1234]]]]; |
28
|
|
|
|
29
|
|
|
yield [['elasticsearch://foo:bar@localhost:1234'], [], [ |
30
|
|
|
'username' => 'foo', |
31
|
|
|
'password' => 'bar', |
32
|
|
|
'servers' => [['host' => 'localhost', 'port' => 1234]], |
33
|
|
|
]]; |
34
|
|
|
|
35
|
|
|
yield [['elasticsearch:?host[localhost]&host[localhost:9201]&host[127.0.0.1:9202]'], [], [ |
36
|
|
|
'servers' => [ |
37
|
|
|
['host' => 'localhost', 'port' => 9200], |
38
|
|
|
['host' => 'localhost', 'port' => 9201], |
39
|
|
|
['host' => '127.0.0.1', 'port' => 9202], |
40
|
|
|
], |
41
|
|
|
]]; |
42
|
|
|
yield [['elasticsearch:?host[localhost]&host[localhost:9201]&host[127.0.0.1:9202]', 'elasticsearch:localhost:1234'], [], [ |
43
|
|
|
'servers' => [ |
44
|
|
|
['host' => 'localhost', 'port' => 9200], |
45
|
|
|
['host' => 'localhost', 'port' => 9201], |
46
|
|
|
['host' => '127.0.0.1', 'port' => 9202], |
47
|
|
|
['host' => 'localhost', 'port' => 1234], |
48
|
|
|
], |
49
|
|
|
]]; |
50
|
|
|
|
51
|
|
|
yield [['elasticsearch:foo:bar@?host[localhost:9201]'], [], [ |
52
|
|
|
'username' => 'foo', |
53
|
|
|
'password' => 'bar', |
54
|
|
|
'servers' => [['host' => 'localhost', 'port' => 9201]], |
55
|
|
|
]]; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|