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

ConfigurationTest::testProcessManyConnections()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 23

Duplication

Lines 41
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 41
loc 41
rs 8.8571
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
3
namespace Tests\GBProd\ElasticaBundle\DependencyInjection;
4
5
use GBProd\ElasticaBundle\DependencyInjection\Configuration;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
use Symfony\Component\Config\Definition\Processor;
8
9
/**
10
 * Tests for Configuration
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14
class ConfigurationTest extends \PHPUnit_Framework_TestCase
15
{
16
    private $configuration;
17
18
    public function setUp()
19
    {
20
        $this->configuration = new Configuration();
21
    }
22
23
    public function testEmptyConfiguration()
24
    {
25
        $processed = $this->process([]);
26
27
        $this->assertEquals([
28
            'clients' => []
29
        ], $processed);
30
    }
31
32
    protected function process(array $config)
33
    {
34
        $processor = new Processor();
35
36
        return $processor->processConfiguration(
37
            $this->configuration,
38
            $config
39
        );
40
    }
41
42
    public function testProcessOneClient()
43
    {
44
        $processed = $this->process([
45
            [
46
                'clients' => [
47
                    'default' => [
48
                        'host' => '127.0.0.1',
49
                        'port' => '9200',
50
                    ]
51
                ]
52
            ]
53
        ]);
54
55
        $this->assertArrayHasKey('connections', $processed['clients']['default']);
56
        $this->assertEquals(
57
            '127.0.0.1',
58
            $processed['clients']['default']['connections'][0]['host']
59
        );
60
        $this->assertEquals(
61
            '9200',
62
            $processed['clients']['default']['connections'][0]['port']
63
        );
64
    }
65
66 View Code Duplication
    public function testProcessTwoClients()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $processed = $this->process([
69
            [
70
                'clients' => [
71
                    'default' => [
72
                        'host' => '127.0.0.1',
73
                        'port' => '9200',
74
                    ],
75
                    'my_client' => [
76
                        'host' => '192.168.0.100',
77
                        'port' => '9201',
78
                    ]
79
                ]
80
            ]
81
        ]);
82
83
        $this->assertArrayHasKey('connections', $processed['clients']['default']);
84
        $this->assertEquals(
85
            '127.0.0.1',
86
            $processed['clients']['default']['connections'][0]['host']
87
        );
88
        $this->assertEquals(
89
            '9200',
90
            $processed['clients']['default']['connections'][0]['port']
91
        );
92
93
        $this->assertArrayHasKey('connections', $processed['clients']['my_client']);
94
        $this->assertEquals(
95
            '192.168.0.100',
96
            $processed['clients']['my_client']['connections'][0]['host']
97
        );
98
        $this->assertEquals(
99
            '9201',
100
            $processed['clients']['my_client']['connections'][0]['port']
101
        );
102
    }
103
104 View Code Duplication
    public function testProcessManyConnections()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
    {
106
        $processed = $this->process([
107
            [
108
                'clients' => [
109
                    'default' => [
110
                        'connections' => [
111
                            [
112
                                'host' => '127.0.0.1',
113
                                'port' => '9200',
114
                            ],
115
                            [
116
                                'host' => '192.168.0.100',
117
                                'port' => '9201',
118
                            ],
119
                        ]
120
                    ],
121
                ]
122
            ]
123
        ]);
124
125
        $this->assertArrayHasKey('connections', $processed['clients']['default']);
126
        $this->assertEquals(
127
            '127.0.0.1',
128
            $processed['clients']['default']['connections'][0]['host']
129
        );
130
        $this->assertEquals(
131
            '9200',
132
            $processed['clients']['default']['connections'][0]['port']
133
        );
134
135
        $this->assertArrayHasKey('connections', $processed['clients']['default']);
136
        $this->assertEquals(
137
            '192.168.0.100',
138
            $processed['clients']['default']['connections'][1]['host']
139
        );
140
        $this->assertEquals(
141
            '9201',
142
            $processed['clients']['default']['connections'][1]['port']
143
        );
144
    }
145
146
147
    public function testProcessAddDefaultValuesForConnections()
148
    {
149
        $processed = $this->process([
150
            [
151
                'clients' => [
152
                    'default' => [
153
                        'connections' => [
154
                            [
155
                                'host' => '127.0.0.1',
156
                                'port' => '9200',
157
                            ]
158
                        ]
159
                    ],
160
                ]
161
            ]
162
        ]);
163
164
        $this->assertArrayHasKey('connections', $processed['clients']['default']);
165
        $this->assertNull($processed['clients']['default']['connections'][0]['path']);
166
        $this->assertNull($processed['clients']['default']['connections'][0]['url']);
167
        $this->assertNull($processed['clients']['default']['connections'][0]['proxy']);
168
        $this->assertNull($processed['clients']['default']['connections'][0]['transport']);
169
        $this->assertNull($processed['clients']['default']['connections'][0]['timeout']);
170
        $this->assertTrue($processed['clients']['default']['connections'][0]['persistent']);
171
    }
172
}