-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathInfoTest.php
126 lines (109 loc) · 3.9 KB
/
InfoTest.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
use cebe\openapi\Reader;
use cebe\openapi\spec\Contact;
use cebe\openapi\spec\Info;
use cebe\openapi\spec\License;
/**
* @covers \cebe\openapi\spec\Info
* @covers \cebe\openapi\spec\Contact
* @covers \cebe\openapi\spec\License
*/
class InfoTest extends \PHPUnit\Framework\TestCase
{
public function testRead()
{
/** @var $info Info */
$info = Reader::readFromYaml(<<<'YAML'
title: Sample Pet Store App
description: This is a sample server for a pet store.
termsOfService: http://example.com/terms/
contact:
name: API Support
url: http://www.example.com/support
email: [email protected]
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.1
x-extra-var: foo
YAML
, Info::class);
$result = $info->validate();
$this->assertEquals([], $info->getErrors());
$this->assertTrue($result);
$this->assertEquals('Sample Pet Store App', $info->title);
$this->assertEquals('This is a sample server for a pet store.', $info->description);
$this->assertEquals('http://example.com/terms/', $info->termsOfService);
$this->assertEquals('1.0.1', $info->version);
$this->assertInstanceOf(Contact::class, $info->contact);
$this->assertEquals('API Support', $info->contact->name);
$this->assertEquals('http://www.example.com/support', $info->contact->url);
$this->assertEquals('[email protected]', $info->contact->email);
$this->assertInstanceOf(License::class, $info->license);
$this->assertEquals('Apache 2.0', $info->license->name);
$this->assertEquals('https://www.apache.org/licenses/LICENSE-2.0.html', $info->license->url);
$this->assertEquals('foo', $info->getExtensions()['x-extra-var']);
$this->assertEquals('foo', $info->getExtension('x-extra-var'));
$this->assertEquals('foo', $info->getExtension('extra-var'));
$this->assertNull($info->getExtension('another-var'));
}
public function testReadInvalid()
{
/** @var $info Info */
$info = Reader::readFromYaml(<<<'YAML'
description: This is a sample server for a pet store.
termsOfService: http://example.com/terms/
contact:
name: API Support
url: http://www.example.com/support
email: [email protected]
YAML
, Info::class);
$result = $info->validate();
$this->assertEquals([
'Info is missing required property: title',
'Info is missing required property: version',
], $info->getErrors());
$this->assertFalse($result);
}
public function testReadInvalidContact()
{
/** @var $info Info */
$info = Reader::readFromYaml(<<<'YAML'
title: test
version: 1.0
contact:
name: API Support
url: www.example.com/support
email: support.example.com
YAML
, Info::class);
$result = $info->validate();
$this->assertEquals([
'Contact::$email does not seem to be a valid email address: support.example.com',
'Contact::$url does not seem to be a valid URL: www.example.com/support',
], $info->getErrors());
$this->assertFalse($result);
$this->assertInstanceOf(Contact::class, $info->contact);
$this->assertNull($info->license);
}
public function testReadInvalidLicense()
{
/** @var $info Info */
$info = Reader::readFromYaml(<<<'YAML'
title: test
version: 1.0
license:
url: www.apache.org/licenses/LICENSE-2.0.html
YAML
, Info::class);
$result = $info->validate();
$this->assertEquals([
'License is missing required property: name',
'License::$url does not seem to be a valid URL: www.apache.org/licenses/LICENSE-2.0.html',
], $info->getErrors());
$this->assertFalse($result);
$this->assertInstanceOf(License::class, $info->license);
$this->assertNull($info->contact);
}
}