Completed
Push — master ( 98f353...32973a )
by GBProd
04:02
created

ElasticaExtensionTest::testCreateClients()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace Tests\GBProd\ElasticaBundle\DependencyInjection;
4
5
use GBProd\ElasticaBundle\DependencyInjection\ElasticaExtension;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8
9
/**
10
 * Tests for ElasticaExtension
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14
class ElasticaExtensionTest extends \PHPUnit_Framework_TestCase
15
{
16
    private $extension;
17
18
    private $container;
19
20
    protected function setUp()
21
    {
22
        $this->extension = new ElasticaExtension();
23
        $this->container = new ContainerBuilder();
24
     }
25
26
    public function testCreateClients()
27
    {
28
        $config = [
29
            [
30
                'clients' => [
31
                    'default' => [
32
                        'host' => '127.0.0.1',
33
                        'port' => '9200',
34
                    ]
35
                ]
36
            ]
37
        ];
38
39
        $this->extension->load($config, $this->container);
40
41
        $this->assertTrue($this->container->has('elastica.default_client'));
42
43
        $clientDefinition = $this->container->getDefinition('elastica.default_client');
44
        $this->assertEquals(\Elastica\Client::class, $clientDefinition->getClass());
45
        $argument = $clientDefinition->getArgument(0);
46
        $this->assertEquals('127.0.0.1', $argument['connections'][0]['host']);
47
        $this->assertEquals('9200', $argument['connections'][0]['port']);
48
    }
49
50
    public function testCreateManyClients()
51
    {
52
        $config = [
53
            [
54
                'clients' => [
55
                    'default' => [
56
                        'host' => '127.0.0.1',
57
                        'port' => '9200',
58
                    ],
59
                    'my_client' => [
60
                        'host' => '192.168.0.100',
61
                        'port' => '9201',
62
                    ]
63
                ]
64
            ]
65
        ];
66
67
        $this->extension->load($config, $this->container);
68
69
        $this->assertTrue($this->container->has('elastica.default_client'));
70
        $this->assertTrue($this->container->has('elastica.my_client_client'));
71
    }
72
}
73