Passed
Branch docker-environment (b360d6)
by Ralf
20:05 queued 07:20
created

ConnectionFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
/**
3
 * User: zach
4
 * Date: 9/20/13
5
 * Time: 12:39 PM
6
 */
7
8
use Elasticsearch\Connections\ConnectionFactory;
9
use Mockery as m;
10
11
/**
12
 * Class ConnectionFactoryTest
13
 * @package Elasticsearch\Tests\Endpoints
14
 * @author  Zachary Tong <[email protected]>
15
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
16
 * @link    http://elasticsearch.org
17
 */
18
class ConnectionFactoryTest extends \PHPUnit_Framework_TestCase
19
{
20
    public function tearDown() {
21
        m::close();
22
    }
23
24
    public function testCreate()
25
    {
26
        $mockConnection = m::mock('\Elasticsearch\Connections\AbstractConnection');
27
        $mockFunction = function($hostDetails, $params, $log, $trace) use ($mockConnection) {
28
            return $mockConnection;
29
        };
30
31
        // Eww...
32
        $mockPimple = m::mock('\Pimple\Container')
33
                      ->shouldReceive('offsetGet')->with('connection')->andReturn($mockFunction)->getMock()
34
                      ->shouldReceive('offsetGet')->with('connectionParamsShared')->andReturn(array())->getMock()
35
                      ->shouldReceive('offsetGet')->with('logObject')->andReturn(array())->getMock()
36
                      ->shouldReceive('offsetGet')->with('traceObject')->andReturn(array())->getMock();
37
38
        $hostDetails = array(
39
            'host' => 'localhost',
40
            'port' => 9200
41
        );
42
43
        $factory = new ConnectionFactory($mockPimple);
44
        $connection = $factory->create($hostDetails);
45
46
        $this->assertEquals($mockConnection, $connection);
47
    }
48
}