1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ApiDefinitionTest |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\ProxyBundle\Tests\Definition; |
7
|
|
|
|
8
|
|
|
use Graviton\ProxyBundle\Definition\ApiDefinition; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* test api definition |
12
|
|
|
* |
13
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
14
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
15
|
|
|
* @link http://swisscom.ch |
16
|
|
|
*/ |
17
|
|
|
class ApiDefinitionTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* test add endpoint |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function testAddEndpoints() |
25
|
|
|
{ |
26
|
|
|
$host = "localhost:8000"; |
27
|
|
|
$basePath = "/v2/default/path"; |
28
|
|
|
$endpoints = ["/user", "/group", "/user/uploadImage"]; |
29
|
|
|
|
30
|
|
|
$sut = new ApiDefinition(); |
31
|
|
|
$sut->setBasePath($basePath); |
32
|
|
|
$sut->setHost($host); |
33
|
|
|
foreach ($endpoints as $endpoint) { |
34
|
|
|
$sut->addEndpoint($endpoint); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$apiEndpoints = $sut->getEndpoints(false, null); |
38
|
|
|
|
39
|
|
|
$this->assertEquals($host, $sut->getHost()); |
40
|
|
|
$this->assertCount(3, $apiEndpoints); |
41
|
|
|
foreach ($endpoints as $id => $endpoint) { |
42
|
|
|
$this->assertTrue($sut->hasEndpoint($endpoint)); |
43
|
|
|
$this->assertEquals($basePath.$endpoint, $apiEndpoints[$id]); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* test endpoint definition without base path,but with host |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function testGetEntpointWithoutPath() |
53
|
|
|
{ |
54
|
|
|
$endpoint = "/this/is/an/endpoint"; |
55
|
|
|
$prefix = "/testapi"; |
56
|
|
|
$host = "blabla.talk:8080"; |
57
|
|
|
|
58
|
|
|
$sut = new ApiDefinition(); |
59
|
|
|
$sut->addEndpoint($endpoint); |
60
|
|
|
|
61
|
|
|
$this->assertEquals($endpoint, $sut->getEndpoints(false)[0]); |
62
|
|
|
$this->assertEquals($endpoint, $sut->getEndpoints(true)[0]); |
63
|
|
|
|
64
|
|
|
$sut->setHost($host); |
65
|
|
|
$this->assertEquals($endpoint, $sut->getEndpoints(false)[0]); |
66
|
|
|
$this->assertEquals($host.$endpoint, $sut->getEndpoints(true)[0]); |
67
|
|
|
$this->assertEquals($prefix.$endpoint, $sut->getEndpoints(false, $prefix)[0]); |
68
|
|
|
$this->assertEquals($host.$prefix.$endpoint, $sut->getEndpoints(true, $prefix)[0]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* test schema |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function testAddSchema() |
77
|
|
|
{ |
78
|
|
|
$endpoint = "test/schema/endpoint"; |
79
|
|
|
$testschema = new \stdClass(); |
80
|
|
|
$testschema->name = "test123"; |
81
|
|
|
$testschema->description = "This is a description"; |
82
|
|
|
|
83
|
|
|
$sut = new ApiDefinition(); |
84
|
|
|
$sut->addSchema($endpoint, $testschema); |
85
|
|
|
$schema = $sut->getSchema($endpoint); |
86
|
|
|
|
87
|
|
|
$this->assertInstanceOf("\stdClass", $schema); |
88
|
|
|
$this->assertEquals($testschema->name, $schema->name); |
89
|
|
|
$this->assertEquals($testschema->description, $schema->description); |
90
|
|
|
$this->assertInstanceOf("\stdClass", $sut->getSchema("blablabla/endpoint")); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|