summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/AbstractTransportTest.php
blob: 20573cc7336b738ef2ed522d69a217b95d169a05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Elastica\Test\Transport;

use Elastica\Connection;
use Elastica\Transport\AbstractTransport;
use Elastica\Transport\Http;

class AbstractTransportTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Return transport configuration and the expected HTTP method.
     *
     * @return array[]
     */
    public function getValidDefinitions()
    {
        $connection = new Connection();

        return array(
            array('Http'),
            array(array('type' => 'Http')),
            array(array('type' => new Http())),
            array(new Http()),
        );
    }

    /**
     * @group unit
     * @dataProvider getValidDefinitions
     */
    public function testCanCreateTransportInstances($transport)
    {
        $connection = new Connection();
        $params = array();
        $transport = AbstractTransport::create($transport, $connection, $params);
        $this->assertInstanceOf('Elastica\Transport\AbstractTransport', $transport);
        $this->assertSame($connection, $transport->getConnection());
    }

    public function getInvalidDefinitions()
    {
        return array(
            array(array('transport' => 'Http')),
            array('InvalidTransport'),
        );
    }

    /**
     * @group unit
     * @dataProvider getInvalidDefinitions
     * @expectedException Elastica\Exception\InvalidException
     * @expectedExceptionMessage Invalid transport
     */
    public function testThrowsExecptionOnInvalidTransportDefinition($transport)
    {
        AbstractTransport::create($transport, new Connection());
    }

    /**
     * @group unit
     */
    public function testCanInjectParamsWhenUsingArray()
    {
        $connection = new Connection();
        $params = array(
            'param1' => 'some value',
            'param3' => 'value3',
        );

        $transport = AbstractTransport::create(array(
            'type' => 'Http',
            'param1' => 'value1',
            'param2' => 'value2',
        ), $connection, $params);

        $this->assertSame('value1', $transport->getParam('param1'));
        $this->assertSame('value2', $transport->getParam('param2'));
        $this->assertSame('value3', $transport->getParam('param3'));
    }
}