forked from cebe/php-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerTest.php
More file actions
83 lines (73 loc) · 2.39 KB
/
Copy pathServerTest.php
File metadata and controls
83 lines (73 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use cebe\openapi\Reader;
use cebe\openapi\spec\Server;
use cebe\openapi\spec\ServerVariable;
/**
* @covers \cebe\openapi\spec\Server
* @covers \cebe\openapi\spec\ServerVariable
*/
class ServerTest extends \PHPUnit\Framework\TestCase
{
public function testRead()
{
/** @var $server Server */
$server = Reader::readFromJson(<<<JSON
{
"url": "https://{username}.gigantic-server.com:{port}/{basePath}",
"description": "The production API server",
"variables": {
"username": {
"default": "demo",
"description": "this value is assigned by the service provider, in this example `gigantic-server.com`"
},
"port": {
"enum": [
"8443",
"443"
],
"default": "8443"
},
"basePath": {
"default": "v2"
}
}
}
JSON
, Server::class);
$result = $server->validate();
$this->assertEquals([], $server->getErrors());
$this->assertTrue($result);
$this->assertEquals('https://{username}.gigantic-server.com:{port}/{basePath}', $server->url);
$this->assertEquals('The production API server', $server->description);
$this->assertCount(3, $server->variables);
$this->assertEquals('demo', $server->variables['username']->default);
$this->assertEquals('this value is assigned by the service provider, in this example `gigantic-server.com`', $server->variables['username']->description);
$this->assertEquals('8443', $server->variables['port']->default);
/** @var $server Server */
$server = Reader::readFromJson(<<<JSON
{
"description": "The production API server"
}
JSON
, Server::class);
$result = $server->validate();
$this->assertEquals(['Server is missing required property: url'], $server->getErrors());
$this->assertFalse($result);
/** @var $server Server */
$server = Reader::readFromJson(<<<JSON
{
"url": "https://{username}.gigantic-server.com:{port}/{basePath}",
"description": "The production API server",
"variables": {
"username": {
"description": "this value is assigned by the service provider, in this example `gigantic-server.com`"
}
}
}
JSON
, Server::class);
$result = $server->validate();
$this->assertEquals(['ServerVariable is missing required property: default'], $server->getErrors());
$this->assertFalse($result);
}
}