Skip to content

Commit

Permalink
Merge pull request #75 from RonasIT/67_increase_covering_by_unit_tests
Browse files Browse the repository at this point in the history
#67: Increase coverage by unit tests
  • Loading branch information
DenTray committed Mar 1, 2023
2 parents 9e6e00f + dc6c1d5 commit 7187aa0
Show file tree
Hide file tree
Showing 29 changed files with 1,559 additions and 168 deletions.
4 changes: 3 additions & 1 deletion src/Services/SwaggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ protected function generateEmptyData(): array
$data['securityDefinitions'] = $securityDefinitions;
}

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

return $data;
}
Expand Down
24 changes: 22 additions & 2 deletions tests/AutoDocControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public function testGetJSONDocumentation()
$response->assertJson($this->documentation);
}

public function testGetJSONDocumentationWithAdditionalPaths()
{
config([
'auto-doc.additional_paths' => ['tests/fixtures/AutoDocControllerTest/tmp_data_with_additional_paths.json']
]);

$response = $this->json('get', '/auto-doc/documentation');

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

$this->assertEqualsJsonFixture('tmp_data_with_additional_paths', $response->json());
}

public function testGetJSONDocumentationWithGlobalPrefix()
{
$this->addGlobalPrefix();
Expand All @@ -56,7 +69,7 @@ public function testGetViewDocumentation()

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

$this->assertEquals($response->getContent(), $this->getFixture('rendered_documentation.html'));
$this->assertEqualsFixture('rendered_documentation.html', $response->getContent());
}

public function testGetViewDocumentationEnvironmentDisable()
Expand All @@ -78,7 +91,7 @@ public function testGetViewDocumentationWithGlobalPrefix()

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

$this->assertEquals($response->getContent(), $this->getFixture('rendered_documentation_with_global_path.html'));
$this->assertEqualsFixture('rendered_documentation_with_global_path.html', $response->getContent());
}

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

public function testGetFileNotExists()
{
$response = $this->get('/auto-doc/non-existent-file.js');

$response->assertStatus(Response::HTTP_NOT_FOUND);
}

public function testGetSwaggerAssetFileWithGlobalPrefix()
{
$this->addGlobalPrefix();
Expand Down
26 changes: 26 additions & 0 deletions tests/AutoDocMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace RonasIT\Support\Tests;

use RonasIT\Support\AutoDoc\Http\Middleware\AutoDocMiddleware;
use RonasIT\Support\Tests\Support\Traits\SwaggerServiceMockTrait;

class AutoDocMiddlewareTest extends TestCase
{
use SwaggerServiceMockTrait;

public function testHandle()
{
config(['auto-doc.security' => 'laravel']);

$this->mockDriverGetEmptyAndSaveTpmData($this->getJsonFixture('tmp_data_search_roles_request'));

$request = $this->generateGetRolesRequest();

$middleware = new AutoDocMiddleware();

$middleware->handle($request, function () {
return $this->generateResponse('example_success_search_roles_response.json');
});
}
}
2 changes: 1 addition & 1 deletion tests/LocalDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testGetDocumentation()

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

$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
$this->assertEqualsJsonFixture('tmp_data', $documentation);
}

public function testGetDocumentationFileNotExists()
Expand Down
17 changes: 17 additions & 0 deletions tests/PushDocumentationCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace RonasIT\Support\Tests;

class PushDocumentationCommandTest extends TestCase
{
public function testHandle()
{
$this->artisan('swagger:push-documentation')->assertExitCode(0);

$this->assertFileExists(storage_path('documentation.json'));

$docContent = file_get_contents(storage_path('documentation.json'));

$this->assertEqualsJsonFixture('documentation', json_decode($docContent, true));
}
}
4 changes: 2 additions & 2 deletions tests/StorageDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testSaveData()
$this->storageDriverClass->saveData();

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

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

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

$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
$this->assertEqualsJsonFixture('tmp_data', $documentation);
}

public function testGetDocumentationFileNotExists()
Expand Down
Loading

0 comments on commit 7187aa0

Please sign in to comment.