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
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
$this->client = new Client('http://example.com:8001/'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* tear down |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function tearDown() |
43
|
|
|
{ |
44
|
|
|
$this->client = null; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* test api when valid |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
* |
52
|
|
|
* @dataProvider validApiNameProvider |
53
|
|
|
*/ |
54
|
|
|
public function testApiWhenValid($name, $class) |
55
|
|
|
{ |
56
|
|
|
$this->assertInstanceOf($class, $this->client->api($name)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* test api when invalid |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
* |
64
|
|
|
* @expectedException \InvalidArgumentException |
65
|
|
|
* @expectedExceptionMessage Undefined api instance called: something |
66
|
|
|
*/ |
67
|
|
|
public function testApiWhenInvalid() |
68
|
|
|
{ |
69
|
|
|
$this->client->api('something'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* valid api name provider |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function validApiNameProvider() |
78
|
|
|
{ |
79
|
|
|
yield ['api', '\Unikorp\KongAdminApi\Api\Api']; |
80
|
|
|
yield ['cluster', '\Unikorp\KongAdminApi\Api\Cluster']; |
81
|
|
|
yield ['consumer', '\Unikorp\KongAdminApi\Api\Consumer']; |
82
|
|
|
yield ['information', '\Unikorp\KongAdminApi\Api\Information']; |
83
|
|
|
yield ['plugin', '\Unikorp\KongAdminApi\Api\Plugin']; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|