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\ClientInterface as HttpClientInterface; |
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(HttpClientInterface::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
|
|
|
$this->client |
76
|
|
|
->expects($this->once()) |
77
|
|
|
->method('setDefaultOption') |
78
|
|
|
->with('timeout', 4); |
79
|
|
|
|
80
|
|
|
$this->server->setTimeout('4'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @covers ::setHTTPHeader |
85
|
|
|
*/ |
86
|
|
|
public function testSetHTTPHeader() |
87
|
|
|
{ |
88
|
|
|
$schema = 'my_schema'; |
89
|
|
|
$schemaHeader = 'Default-Schema'; |
90
|
|
|
|
91
|
|
|
$this->client |
92
|
|
|
->expects($this->once()) |
93
|
|
|
->method('setDefaultOption') |
94
|
|
|
->with('headers/'.$schemaHeader, $schema); |
95
|
|
|
|
96
|
|
|
$this->server->setHttpHeader($schemaHeader, $schema); |
97
|
|
|
|
98
|
|
|
$server = new Server('http://localhost:4200/_sql', []); |
99
|
|
|
$reflection = new ReflectionClass($server); |
100
|
|
|
$property = $reflection->getProperty('client'); |
101
|
|
|
$property->setAccessible(true); |
102
|
|
|
|
103
|
|
|
$server->setHttpHeader($schemaHeader, $schema); |
104
|
|
|
$internalClient = $property->getValue($server); |
105
|
|
|
$header = $internalClient->getDefaultOption('headers/'.$schemaHeader); |
106
|
|
|
|
107
|
|
|
$this->assertEquals($schema, $header); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |