Completed
Push — master ( b6d0f2...cf05e5 )
by Tobias
02:18
created

ClientFactoryTest::testGetConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 3
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:example.com'], [], ['servers' => [['host' => 'example.com', 'port' => 9200]]]];
26
        yield [['elasticsearch:localhost:1234'], [], ['servers' => [['host' => 'localhost', 'port' => 1234]]]];
27
28
        yield [['elasticsearch:foo:bar@localhost:1234'], [], [
29
            'username' => 'foo',
30
            'password' => 'bar',
31
            'servers' => [['host' => 'localhost', 'port' => 1234]],
32
        ]];
33
34
        yield [['elasticsearch:?host[localhost]&host[localhost:9201]&host[127.0.0.1:9202]'], [], [
35
            'servers' => [
36
                ['host' => 'localhost', 'port' => 9200],
37
                ['host' => 'localhost', 'port' => 9201],
38
                ['host' => '127.0.0.1', 'port' => 9202],
39
            ],
40
        ]];
41
        yield [['elasticsearch:?host[localhost]&host[localhost:9201]&host[127.0.0.1:9202]', 'elasticsearch:localhost:1234'], [], [
42
            'servers' => [
43
                ['host' => 'localhost', 'port' => 9200],
44
                ['host' => 'localhost', 'port' => 9201],
45
                ['host' => '127.0.0.1', 'port' => 9202],
46
                ['host' => 'localhost', 'port' => 1234],
47
            ],
48
        ]];
49
50
        yield [['elasticsearch:foo:bar@?host[localhost:9201]'], [], [
51
            'username' => 'foo',
52
            'password' => 'bar',
53
            'servers' => [['host' => 'localhost', 'port' => 9201]],
54
        ]];
55
    }
56
}
57