Skip to content

Commit 7187aa0

Browse files
authored
Merge pull request #75 from RonasIT/67_increase_covering_by_unit_tests
#67: Increase coverage by unit tests
2 parents 9e6e00f + dc6c1d5 commit 7187aa0

29 files changed

+1559
-168
lines changed

src/Services/SwaggerService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ protected function generateEmptyData(): array
125125
$data['securityDefinitions'] = $securityDefinitions;
126126
}
127127

128-
$data['info']['description'] = view($data['info']['description'])->render();
128+
if (!empty($data['info']['description'])) {
129+
$data['info']['description'] = view($data['info']['description'])->render();
130+
}
129131

130132
return $data;
131133
}

tests/AutoDocControllerTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ public function testGetJSONDocumentation()
3737
$response->assertJson($this->documentation);
3838
}
3939

40+
public function testGetJSONDocumentationWithAdditionalPaths()
41+
{
42+
config([
43+
'auto-doc.additional_paths' => ['tests/fixtures/AutoDocControllerTest/tmp_data_with_additional_paths.json']
44+
]);
45+
46+
$response = $this->json('get', '/auto-doc/documentation');
47+
48+
$response->assertStatus(Response::HTTP_OK);
49+
50+
$this->assertEqualsJsonFixture('tmp_data_with_additional_paths', $response->json());
51+
}
52+
4053
public function testGetJSONDocumentationWithGlobalPrefix()
4154
{
4255
$this->addGlobalPrefix();
@@ -56,7 +69,7 @@ public function testGetViewDocumentation()
5669

5770
$response->assertStatus(Response::HTTP_OK);
5871

59-
$this->assertEquals($response->getContent(), $this->getFixture('rendered_documentation.html'));
72+
$this->assertEqualsFixture('rendered_documentation.html', $response->getContent());
6073
}
6174

6275
public function testGetViewDocumentationEnvironmentDisable()
@@ -78,7 +91,7 @@ public function testGetViewDocumentationWithGlobalPrefix()
7891

7992
$response->assertStatus(Response::HTTP_OK);
8093

81-
$this->assertEquals($response->getContent(), $this->getFixture('rendered_documentation_with_global_path.html'));
94+
$this->assertEqualsFixture('rendered_documentation_with_global_path.html', $response->getContent());
8295
}
8396

8497
public function testGetSwaggerAssetFile()
@@ -92,6 +105,13 @@ public function testGetSwaggerAssetFile()
92105
$response->assertHeader('Content-Type', 'text/html; charset=UTF-8');
93106
}
94107

108+
public function testGetFileNotExists()
109+
{
110+
$response = $this->get('/auto-doc/non-existent-file.js');
111+
112+
$response->assertStatus(Response::HTTP_NOT_FOUND);
113+
}
114+
95115
public function testGetSwaggerAssetFileWithGlobalPrefix()
96116
{
97117
$this->addGlobalPrefix();

tests/AutoDocMiddlewareTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace RonasIT\Support\Tests;
4+
5+
use RonasIT\Support\AutoDoc\Http\Middleware\AutoDocMiddleware;
6+
use RonasIT\Support\Tests\Support\Traits\SwaggerServiceMockTrait;
7+
8+
class AutoDocMiddlewareTest extends TestCase
9+
{
10+
use SwaggerServiceMockTrait;
11+
12+
public function testHandle()
13+
{
14+
config(['auto-doc.security' => 'laravel']);
15+
16+
$this->mockDriverGetEmptyAndSaveTpmData($this->getJsonFixture('tmp_data_search_roles_request'));
17+
18+
$request = $this->generateGetRolesRequest();
19+
20+
$middleware = new AutoDocMiddleware();
21+
22+
$middleware->handle($request, function () {
23+
return $this->generateResponse('example_success_search_roles_response.json');
24+
});
25+
}
26+
}

tests/LocalDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testGetDocumentation()
5858

5959
$documentation = $this->localDriverClass->getDocumentation();
6060

61-
$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
61+
$this->assertEqualsJsonFixture('tmp_data', $documentation);
6262
}
6363

6464
public function testGetDocumentationFileNotExists()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace RonasIT\Support\Tests;
4+
5+
class PushDocumentationCommandTest extends TestCase
6+
{
7+
public function testHandle()
8+
{
9+
$this->artisan('swagger:push-documentation')->assertExitCode(0);
10+
11+
$this->assertFileExists(storage_path('documentation.json'));
12+
13+
$docContent = file_get_contents(storage_path('documentation.json'));
14+
15+
$this->assertEqualsJsonFixture('documentation', json_decode($docContent, true));
16+
}
17+
}

tests/StorageDriverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testSaveData()
4242
$this->storageDriverClass->saveData();
4343

4444
$this->disk->assertExists($this->filePath);
45-
$this->assertEquals($this->getFixture('tmp_data_non_formatted.json'), $this->disk->get($this->filePath));
45+
$this->assertEqualsFixture('tmp_data_non_formatted.json', $this->disk->get($this->filePath));
4646

4747
$this->assertEquals([], $this->storageDriverClass->getTmpData());
4848
}
@@ -53,7 +53,7 @@ public function testGetDocumentation()
5353

5454
$documentation = $this->storageDriverClass->getDocumentation();
5555

56-
$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
56+
$this->assertEqualsJsonFixture('tmp_data', $documentation);
5757
}
5858

5959
public function testGetDocumentationFileNotExists()

0 commit comments

Comments
 (0)