Completed
Push — b/update_guzzle ( 884993...d79266 )
by
unknown
08:42 queued 04:43
created

ServerTest::testInitialOptions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
/**
3
 * Created by IntelliJ IDEA.
4
 * User: christian
5
 * Date: 15/01/16
6
 * Time: 08:19
7
 */
8
9
namespace CrateTest\PDO\Http;
10
11
use Crate\PDO\Exception\UnsupportedException;
12
use Crate\PDO\Http\Server;
13
use GuzzleHttp\Client as HttpClient;
14
use PHPUnit_Framework_TestCase;
15
use ReflectionClass;
16
17
/**
18
 * Class ServerTest
19
 *
20
 * @coversDefaultClass \Crate\PDO\Http\Server
21
 * @covers ::<!public>
22
 *
23
 * @group unit
24
 */
25
class ServerTest extends PHPUnit_Framework_TestCase
26
{
27
28
    /**
29
     * @var Server $client
30
     */
31
    private $server;
32
33
    /**
34
     * @var \PHPUnit_Framework_MockObject_MockObject
35
     */
36
    private $client;
37
38
    /**
39
     * @covers ::__construct
40
     */
41
    protected function setUp()
42
    {
43
        $this->server = new Server('http://localhost:4200/_sql', []);
44
        $this->client = $this->getMock(HttpClient::class);
45
46
        $reflection = new ReflectionClass($this->server);
47
        $property = $reflection->getProperty('client');
48
        $property->setAccessible(true);
49
        $property->setValue($this->server, $this->client);
50
    }
51
52
    /**
53
     * @covers ::getServerInfo
54
     */
55
    public function testGetServerInfo()
56
    {
57
        $this->setExpectedException(UnsupportedException::class);
58
        $this->server->getServerInfo();
59
    }
60
61
    /**
62
     * @covers ::getServerVersion
63
     */
64
    public function testGetServerVersion()
65
    {
66
        $this->setExpectedException(UnsupportedException::class);
67
        $this->server->getServerVersion();
68
    }
69
70
    /**
71
     * @covers ::setTimeout
72
     */
73
    public function testSetTimeout()
74
    {
75
        $body = ['stmt' => 'select * from sys.cluster',
76
                 'args' => []];
77
        $args = [
78
            null, // uri
79
            ['json' => $body,
80
             'headers' => [],
81
             'timeout' => 4
82
            ]
83
        ];
84
        $this->client
85
            ->expects($this->once())
86
            ->method('__call')
87
            ->with('post', $args);
88
        $this->server->setTimeout('4');
89
        $this->server->doRequest($body);
90
    }
91
92
    /**
93
     * @covers ::setHTTPHeader
94
     */
95
    public function testSetHTTPHeader()
96
    {
97
        $schema = 'my_schema';
98
        $schemaHeader = 'Default-Schema';
99
        $this->server->setHttpHeader($schemaHeader, $schema);
100
101
102
        $body = ['stmt' => 'select * from sys.cluster',
103
                 'args' => []];
104
        $args = [
105
            null, // uri
106
            ['json' => $body,
107
             'headers' => [$schemaHeader => $schema],
108
            ]
109
        ];
110
        $this->client
111
            ->expects($this->once())
112
            ->method('__call')
113
            ->with('post', $args);
114
        $this->server->doRequest($body);
115
    }
116
117
    public function testInitialOptions()
118
    {
119
        $this->server = new Server('http://localhost:4200/_sql', ['timeout' => 3]);
120
        $this->client = $this->getMock(HttpClient::class);
121
122
        $reflection = new ReflectionClass($this->server);
123
        $property = $reflection->getProperty('client');
124
        $property->setAccessible(true);
125
        $property->setValue($this->server, $this->client);
126
127
        $body = ['stmt' => 'select * from sys.cluster',
128
                 'args' => []];
129
        $args = [
130
            null,
131
            ['json' => $body,
132
             'headers' => [],
133
             'timeout' => 3
134
            ]
135
        ];
136
137
        $this->client
138
            ->expects($this->once())
139
            ->method('__call')
140
            ->with('post', $args);
141
        $this->server->doRequest($body);
142
    }
143
}
144