Completed
Push — h/multiple-servers ( 562c3a )
by Christian
06:27
created

ServerTest::testSetHTTPHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 16
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\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
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<GuzzleHttp\ClientInterface>.

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.

Loading history...
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
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<GuzzleHttp\ClientInterface>.

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.

Loading history...
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
}