GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#2)
by VEBER
02:53
created

ClientTest::testApiWhenValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the KongAdminApi package.
5
 *
6
 * (c) Unikorp <https://github.com/unikorp>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Unikorp\KongAdminApi\Tests;
13
14
use Unikorp\KongAdminApi\Client;
15
16
/**
17
 * @author VEBER Arnaud <https://github.com/VEBERArnaud>
18
 */
19
class ClientTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * client
23
     * @var \Unikorp\KongAdminApi\Client
24
     */
25
    private $client = null;
26
27
    /**
28
     * set up
29
     *
30
     * @return void
31
     *
32
     * @coversNothing
33
     */
34
    public function setUp()
35
    {
36
        // set up new `client`
37
        $this->client = new Client('http://example.com:8001');
38
    }
39
40
    /**
41
     * tear down
42
     *
43
     * @return void
44
     *
45
     * @coversNothing
46
     */
47
    public function tearDown()
48
    {
49
        // tear down `client`
50
        $this->client = null;
51
    }
52
53
    /**
54
     * test constructor set http client
55
     *
56
     * @return void
57
     *
58
     * @covers \Unikorp\KongAdminApi\Client::__construct
59
     */
60 View Code Duplication
    public function testConstructorSetHttpClient()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        // reflect `client`
63
        $reflectionClass = new \ReflectionClass($this->client);
64
65
        // set `http client` property from `client` accessible
66
        $reflectionProperty = $reflectionClass->getProperty('httpClient');
67
        $reflectionProperty->setAccessible(true);
68
69
        // asserts
70
        $this->assertInstanceOf('\Http\Client\HttpClient', $reflectionProperty->getValue($this->client));
71
    }
72
73
    /**
74
     * test constructor set message factory
75
     *
76
     * @return void
77
     *
78
     * @covers \Unikorp\KongAdminApi\Client::__construct
79
     */
80 View Code Duplication
    public function testConstructorSetMessageFactory()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        // reflect `client`
83
        $reflectionClass = new \ReflectionClass($this->client);
84
85
        // set `message factory` property from `client` accessible
86
        $reflectionProperty = $reflectionClass->getProperty('messageFactory');
87
        $reflectionProperty->setAccessible(true);
88
89
        // asserts
90
        $this->assertInstanceOf('\Http\Message\MessageFactory', $reflectionProperty->getValue($this->client));
91
    }
92
93
    /**
94
     * test constructor add host plugin
95
     *
96
     * @return void
97
     *
98
     * @covers \Unikorp\KongAdminApi\Client::__construct
99
     */
100
    public function testConstructorAddHostPlugin()
101
    {
102
        // reflect `client`
103
        $reflectionClass = new \ReflectionClass($this->client);
104
105
        // set `plugins` property from `client` accessible
106
        $reflectionProperty = $reflectionClass->getProperty('plugins');
107
        $reflectionProperty->setAccessible(true);
108
109
        // get `host plugin`
110
        $hostPlugin = $reflectionProperty->getValue($this->client)[0];
111
112
        // reflect `host plugin`
113
        $reflectionClass = new \ReflectionClass($hostPlugin);
114
115
        // set `host` property from `host plugin` accessible
116
        $reflectionProperty = $reflectionClass->getProperty('host');
117
        $reflectionProperty->setAccessible(true);
118
119
        // get `host`
120
        $host = $reflectionProperty->getValue($hostPlugin);
121
122
        // asserts
123
        $this->assertInstanceOf('\Http\Client\Common\Plugin\addHostPlugin', $hostPlugin);
124
        $this->assertSame('http://example.com:8001', (string) $host);
125
    }
126
127
    /**
128
     * test api when valid
129
     *
130
     * @param string $name
131
     * @param string $class
132
     *
133
     * @return void
134
     *
135
     * @covers \Unikorp\KongAdminApi\Client::api
136
     * @dataProvider validApiNameProvider
137
     */
138
    public function testApiWhenValid($name, $class)
139
    {
140
        // assert
141
        $this->assertInstanceOf($class, $this->client->api($name));
142
    }
143
144
    /**
145
     * test api when invalid
146
     *
147
     * @return void
148
     *
149
     * @covers \Unikorp\KongAdminApi\Client::api
150
     * @expectedException \InvalidArgumentException
151
     * @expectedExceptionMessage Undefined api instance called: something
152
     */
153
    public function testApiWhenInvalid()
154
    {
155
        $this->client->api('something');
156
    }
157
158
    /**
159
     * test add plugin
160
     *
161
     * @return void
162
     *
163
     * @covers \Unikorp\KongAdminApi\Client::addPlugin
164
     */
165
    public function testAddPlugin()
166
    {
167
        // mock `plugin`
168
        $plugin = $this->createMock('\Http\Client\Common\Plugin');
169
170
        // set `plugins` property from `client` accessible
171
        $reflectionClass = new \ReflectionClass($this->client);
172
        $reflectionProperty = $reflectionClass->getProperty('plugins');
173
        $reflectionProperty->setAccessible(true);
174
175
        // add `plugin`
176
        $this->client->addPlugin($plugin);
177
178
        // assert
179
        $this->assertContains($plugin, $reflectionProperty->getValue($this->client));
180
    }
181
182
    /**
183
     * test get http client
184
     *
185
     * @return void
186
     *
187
     * @covers \Unikorp\KongAdminApi\Client::getHttpClient
188
     */
189
    public function testGetHttpClient()
190
    {
191
        $this->assertInstanceOf('\Http\Client\Common\HttpMethodsClient', $this->client->getHttpClient());
192
    }
193
194
    /**
195
     * valid api name provider
196
     *
197
     * @return array
198
     */
199
    public function validApiNameProvider()
200
    {
201
        yield ['api', '\Unikorp\KongAdminApi\Api\Api'];
202
        yield ['cluster', '\Unikorp\KongAdminApi\Api\Cluster'];
203
        yield ['consumer', '\Unikorp\KongAdminApi\Api\Consumer'];
204
        yield ['information', '\Unikorp\KongAdminApi\Api\Information'];
205
        yield ['plugin', '\Unikorp\KongAdminApi\Api\Plugin'];
206
    }
207
}
208