|
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 HttpClientInterface |
|
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
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @covers ::getServerInfo |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testGetServerInfo() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->setExpectedException(UnsupportedException::class); |
|
60
|
|
|
$this->server->getServerInfo(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @covers ::getServerVersion |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testGetServerVersion() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->setExpectedException(UnsupportedException::class); |
|
69
|
|
|
$this->server->getServerVersion(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @covers ::setTimeout |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testSetTimeout() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->client |
|
|
|
|
|
|
78
|
|
|
->expects($this->once()) |
|
79
|
|
|
->method('setDefaultOption') |
|
80
|
|
|
->with('timeout', 4); |
|
81
|
|
|
|
|
82
|
|
|
$this->server->setTimeout('4'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @covers ::setHTTPHeader |
|
87
|
|
|
*/ |
|
88
|
|
|
public function testSetHTTPHeader() |
|
89
|
|
|
{ |
|
90
|
|
|
$schema = 'my_schema'; |
|
91
|
|
|
$schemaHeader = 'Default-Schema'; |
|
92
|
|
|
|
|
93
|
|
|
$this->client |
|
|
|
|
|
|
94
|
|
|
->expects($this->once()) |
|
95
|
|
|
->method('setDefaultOption') |
|
96
|
|
|
->with('headers/'.$schemaHeader, $schema); |
|
97
|
|
|
|
|
98
|
|
|
$this->server->setHttpHeader($schemaHeader, $schema); |
|
99
|
|
|
|
|
100
|
|
|
$server = new Server('http://localhost:4200/_sql', []); |
|
101
|
|
|
$reflection = new ReflectionClass($server); |
|
102
|
|
|
$property = $reflection->getProperty('client'); |
|
103
|
|
|
$property->setAccessible(true); |
|
104
|
|
|
|
|
105
|
|
|
$server->setHttpHeader($schemaHeader, $schema); |
|
106
|
|
|
$internalClient = $property->getValue($server); |
|
107
|
|
|
$header = $internalClient->getDefaultOption('headers/'.$schemaHeader); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals($schema, $header); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.