/
GeneratorTest.php
139 lines (104 loc) · 3.94 KB
/
GeneratorTest.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
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace Tests;
use L5Swagger\Generator;
use L5Swagger\Exceptions\L5SwaggerException;
class GeneratorTest extends TestCase
{
/** @test **/
public function itThrowsExceptionIfDocumatationDirIsNotWritable()
{
$this->setAnnotationsPath();
mkdir(config('l5-swagger.paths.docs'), 0555);
chmod(config('l5-swagger.paths.docs'), 0555);
$this->expectException(L5SwaggerException::class);
Generator::generateDocs();
chmod(config('l5-swagger.paths.docs'), 0777);
}
/** @test */
public function canGenerateApiJsonFile()
{
$this->setAnnotationsPath();
Generator::generateDocs();
$this->assertTrue(file_exists($this->jsonDocsFile()));
$this->assertTrue(file_exists($this->yamlDocsFile()));
$this->get(route('l5-swagger.docs'))
->assertSee('L5 Swagger')
->assertSee('my-default-host.com')
->assertStatus(200);
$this->get(route('l5-swagger.docs', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('L5 Swagger')
->assertSee('my-default-host.com')
->assertStatus(200);
}
/** @test */
public function canGenerateApiJsonFileWithChangedBasePath()
{
if ($this->isOpenApi() == true) {
$this->markTestSkipped('only for openApi 2.0');
}
$this->setAnnotationsPath();
$cfg = config('l5-swagger');
$cfg['paths']['base'] = '/new_path/is/here';
config(['l5-swagger' => $cfg]);
Generator::generateDocs();
$this->assertTrue(file_exists($this->jsonDocsFile()));
$this->get(route('l5-swagger.docs'))
->assertSee('L5 Swagger')
->assertSee('new_path')
->assertStatus(200);
$this->get(route('l5-swagger.docs', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('L5 Swagger')
->assertSee('new_path')
->assertStatus(200);
}
/** @test */
public function canGenerateApiJsonFileWithChangedBaseServer()
{
if (! $this->isOpenApi()) {
$this->markTestSkipped('only for openApi 3.0');
}
$this->setAnnotationsPath();
$cfg = config('l5-swagger');
$cfg['paths']['base'] = 'https://test-server.url';
$cfg['swagger_version'] = '3.0';
config(['l5-swagger' => $cfg]);
tap(new Generator)->generateDocs();
$this->assertTrue(file_exists($this->jsonDocsFile()));
$this->get(route('l5-swagger.docs'))
->assertSee('https://test-server.url')
->assertDontSee('basePath')
->assertStatus(200);
$this->get(route('l5-swagger.docs', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('https://test-server.url')
->assertDontSee('basePath')
->assertStatus(200);
}
/** @test */
public function canSetProxy()
{
$this->setAnnotationsPath();
$cfg = config('l5-swagger');
$cfg['proxy'] = '*';
config(['l5-swagger' => $cfg]);
$this->get(route('l5-swagger.api'))
->assertStatus(200);
$this->assertTrue(file_exists($this->jsonDocsFile()));
$this->assertTrue(file_exists($this->yamlDocsFile()));
}
/** @test */
public function canSetValidatorUrl()
{
$this->setAnnotationsPath();
$cfg = config('l5-swagger');
$cfg['validator_url'] = 'http://validator-url.dev';
config(['l5-swagger' => $cfg]);
$this->get(route('l5-swagger.api'))
->assertSee('validator-url.dev')
->assertStatus(200);
$this->get(route('l5-swagger.api', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('validator-url.dev')
->assertStatus(200);
$this->assertTrue(file_exists($this->jsonDocsFile()));
$this->assertTrue(file_exists($this->yamlDocsFile()));
}
}