forked from RonasIT/laravel-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: format yml files, move views to the resources folder, move stor…
…age to base path, implement swagger service tests;
- Loading branch information
Showing
29 changed files
with
543 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
name: Laravel | ||
name: run-tests-with-coverage | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
branches: ["master"] | ||
pull_request: | ||
branches: [ "master" ] | ||
branches: ["master"] | ||
|
||
jobs: | ||
laravel-tests: | ||
|
||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e | ||
with: | ||
php-version: '7.3' | ||
- uses: actions/checkout@v3 | ||
- name: Copy .env | ||
run: php -r "file_exists('.env') || copy('.env.example', '.env');" | ||
- name: Install Dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | ||
- name: Execute tests (Unit and Feature tests) via PHPUnit | ||
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
- name: Upload coverage results to Coveralls | ||
env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
composer global require php-coveralls/php-coveralls | ||
php-coveralls --coverage_clover=build/logs/clover.xml -v | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '7.1' | ||
- uses: actions/checkout@v3 | ||
- name: Copy .env | ||
run: php -r "file_exists('.env') || copy('.env.example', '.env');" | ||
- name: Install Dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | ||
- name: Execute tests (Unit and Feature tests) via PHPUnit | ||
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
- name: Upload coverage results to Coveralls | ||
env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
composer global require php-coveralls/php-coveralls | ||
php-coveralls --coverage_clover=build/logs/clover.xml -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
version: '3' | ||
|
||
services: | ||
|
||
apache: | ||
image: ronasit/php-nginx-dev:7.3 | ||
working_dir: /app | ||
ports: | ||
- 80:80 | ||
- 443:443 | ||
volumes: | ||
- ./:/app | ||
nginx: | ||
image: ronasit/php-nginx-dev:7.3 | ||
working_dir: /app | ||
ports: | ||
- 80:80 | ||
- 443:443 | ||
volumes: | ||
- ./:/app |
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
namespace RonasIT\Support\Tests; | ||
|
||
use Symfony\Component\HttpFoundation\Response; | ||
use RonasIT\Support\AutoDoc\Services\SwaggerService; | ||
use RonasIT\Support\AutoDoc\Exceptions\LegacyConfigException; | ||
use RonasIT\Support\Tests\Support\Traits\SwaggerServiceMockTrait; | ||
use RonasIT\Support\AutoDoc\Exceptions\InvalidDriverClassException; | ||
use RonasIT\Support\AutoDoc\Exceptions\SwaggerDriverClassNotFoundException; | ||
|
||
class SwaggerServiceTest extends TestCase | ||
{ | ||
use SwaggerServiceMockTrait; | ||
|
||
public function testConstructorInvalidConfigVersion() | ||
{ | ||
config(['auto-doc.config_version' => '1.0']); | ||
|
||
$this->expectException(LegacyConfigException::class); | ||
|
||
app(SwaggerService::class); | ||
} | ||
|
||
public function testConstructorEmptyConfigVersion() | ||
{ | ||
config(['auto-doc.config_version' => null]); | ||
|
||
$this->expectException(LegacyConfigException::class); | ||
|
||
app(SwaggerService::class); | ||
} | ||
|
||
public function testConstructorDriverClassNotExists() | ||
{ | ||
config(['auto-doc.drivers.local.class' => 'NotExistsClass']); | ||
|
||
$this->expectException(SwaggerDriverClassNotFoundException::class); | ||
|
||
app(SwaggerService::class); | ||
} | ||
|
||
public function testConstructorDriverClassNotImplementsInterface() | ||
{ | ||
config(['auto-doc.drivers.local.class' => TestCase::class]); | ||
|
||
$this->expectException(InvalidDriverClassException::class); | ||
|
||
app(SwaggerService::class); | ||
} | ||
|
||
public function testAddData() | ||
{ | ||
$this->mockDriverSaveTmpData($this->getJsonFixture('tmp_data_search_roles_request')); | ||
|
||
$service = app(SwaggerService::class); | ||
|
||
$request = $this->generateRequest('get', 'users/roles', [ | ||
'with' => ['users'] | ||
], [], [ | ||
'Content-type' => 'application/json' | ||
]); | ||
|
||
$response = new Response($this->getFixture('example_success_roles_response.json'), 200, [ | ||
'Content-type' => 'application/json', | ||
'authorization' => 'Bearer some_token' | ||
]); | ||
|
||
$service->addData($request, $response); | ||
} | ||
|
||
public function testAddDataWithJWTSecurity() | ||
{ | ||
config(['auto-doc.security' => 'jwt']); | ||
|
||
$this->mockDriverSaveTmpData($this->getJsonFixture('tmp_data_search_roles_request_jwt_security')); | ||
|
||
$service = app(SwaggerService::class); | ||
|
||
$request = $this->generateRequest('get', 'users/roles', [ | ||
'with' => ['users'] | ||
]); | ||
|
||
$response = new Response($this->getFixture('example_success_roles_response.json'), 200, [ | ||
'Content-type' => 'application/json', | ||
'authorization' => 'Bearer some_token' | ||
]); | ||
|
||
$service->addData($request, $response); | ||
} | ||
|
||
public function testAddDataWithLaravelSecurity() | ||
{ | ||
config(['auto-doc.security' => 'laravel']); | ||
|
||
$this->mockDriverSaveTmpData($this->getJsonFixture('tmp_data_search_roles_request_laravel_security')); | ||
|
||
$service = app(SwaggerService::class); | ||
|
||
$request = $this->generateRequest('get', 'users/roles', [ | ||
'with' => ['users'] | ||
]); | ||
|
||
$response = new Response($this->getFixture('example_success_roles_response.json'), 200, [ | ||
'Content-type' => 'application/json', | ||
'authorization' => 'Bearer some_token' | ||
]); | ||
|
||
$service->addData($request, $response); | ||
} | ||
|
||
public function testAddDataWithPathParameters() | ||
{ | ||
$this->mockDriverSaveTmpData($this->getJsonFixture('tmp_data_get_user_request')); | ||
|
||
$service = app(SwaggerService::class); | ||
|
||
$request = $this->generateRequest('get', 'users/{id}/assign-role/{role-id}', [ | ||
'with' => ['role'], | ||
'with_likes_count' => true | ||
], [ | ||
'id' => 1, | ||
'role-id' => 5 | ||
]); | ||
|
||
$response = new Response($this->getFixture('example_success_user_response.json'), 200, [ | ||
'Content-type' => 'application/json' | ||
]); | ||
|
||
$service->addData($request, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/fixtures/SwaggerServiceTest/example_success_roles_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "admin", | ||
"users": [ | ||
{ | ||
"id": 1, | ||
"name": "admin" | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "client", | ||
"users": [ | ||
{ | ||
"id": 2, | ||
"name": "first_client" | ||
}, | ||
{ | ||
"id": 3, | ||
"name": "second_client" | ||
} | ||
] | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
tests/fixtures/SwaggerServiceTest/example_success_user_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": 2, | ||
"name": "first_client", | ||
"likes_count": 23, | ||
"role": { | ||
"id": 2, | ||
"name": "client" | ||
} | ||
} |
Oops, something went wrong.