From 6cc7056b9b434d520f510a8d96ffc642bab72c22 Mon Sep 17 00:00:00 2001
From: DenTray
Date: Tue, 13 Dec 2022 18:14:51 +0600
Subject: [PATCH 01/20] Create laravel.yml
---
.github/workflows/laravel.yml | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
create mode 100644 .github/workflows/laravel.yml
diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml
new file mode 100644
index 0000000..4fe9fee
--- /dev/null
+++ b/.github/workflows/laravel.yml
@@ -0,0 +1,26 @@
+name: Laravel
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+jobs:
+ laravel-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: Directory Permissions
+ run: chmod -R 777 storage bootstrap/cache
+ - name: Execute tests (Unit and Feature tests) via PHPUnit
+ run: vendor/bin/phpunit
From 0da103976d506943921345c889879e736f315fd5 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Tue, 13 Dec 2022 18:44:33 +0600
Subject: [PATCH 02/20] feat: add application, configure phpunit;
---
bootstrap/app.php | 27 +++++++++++++++++++++++++++
bootstrap/autoload.php | 34 ++++++++++++++++++++++++++++++++++
composer.json | 3 ++-
docker-compose.yml | 12 ++++++++++++
phpunit.xml | 22 ++++++++++++++++++++++
src/Drivers/LocalDriver.php | 1 -
tests/TestCase.php | 19 +++++++++++++++++++
7 files changed, 116 insertions(+), 2 deletions(-)
create mode 100755 bootstrap/app.php
create mode 100755 bootstrap/autoload.php
create mode 100644 docker-compose.yml
create mode 100755 phpunit.xml
create mode 100755 tests/TestCase.php
diff --git a/bootstrap/app.php b/bootstrap/app.php
new file mode 100755
index 0000000..bc7cf56
--- /dev/null
+++ b/bootstrap/app.php
@@ -0,0 +1,27 @@
+detectEnvironment(function()
+{
+ return getenv('APP_ENV') ?: 'local';
+});
+$fn = ".env.{$env}";
+
+$app->loadEnvironmentFrom(file_exists(base_path($fn)) ? $fn : '.env');
+
+
+return $app;
diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php
new file mode 100755
index 0000000..3830137
--- /dev/null
+++ b/bootstrap/autoload.php
@@ -0,0 +1,34 @@
+
+
+
+
+ ./app
+
+
+ ./app/Http/routes.php
+
+
+
+
+ ./tests
+
+
+
+
+
+
+
+
+
diff --git a/src/Drivers/LocalDriver.php b/src/Drivers/LocalDriver.php
index 06b65e3..6b56c00 100755
--- a/src/Drivers/LocalDriver.php
+++ b/src/Drivers/LocalDriver.php
@@ -2,7 +2,6 @@
namespace RonasIT\Support\AutoDoc\Drivers;
-use stdClass;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface;
use RonasIT\Support\AutoDoc\Exceptions\MissedProductionFilePathException;
diff --git a/tests/TestCase.php b/tests/TestCase.php
new file mode 100755
index 0000000..173442f
--- /dev/null
+++ b/tests/TestCase.php
@@ -0,0 +1,19 @@
+
Date: Tue, 13 Dec 2022 18:46:58 +0600
Subject: [PATCH 03/20] fix: fix composer autoload block;
---
composer.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index 64ab969..4a9fd2a 100644
--- a/composer.json
+++ b/composer.json
@@ -23,7 +23,7 @@
"autoload": {
"psr-4": {
"RonasIT\\Support\\AutoDoc\\": "src/",
- "RonasIT\\Support\\Tests": "tests/"
+ "RonasIT\\Support\\Tests\\": "tests/"
},
"exclude-from-classmap": [
"src/Tests/"
From 8e4bdea903bbd80bd897efc156e6b9fc6cf66265 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Tue, 13 Dec 2022 18:51:46 +0600
Subject: [PATCH 04/20] fix: remove permissions stage;
---
.github/workflows/laravel.yml | 2 --
1 file changed, 2 deletions(-)
diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml
index 4fe9fee..072652d 100644
--- a/.github/workflows/laravel.yml
+++ b/.github/workflows/laravel.yml
@@ -20,7 +20,5 @@ jobs:
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: Directory Permissions
- run: chmod -R 777 storage bootstrap/cache
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
From 844631a7254338e8cd738ac1aa607f26a3579e5b Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Tue, 13 Dec 2022 19:00:37 +0600
Subject: [PATCH 05/20] fix: add coverage status/ci status badges;
---
readme.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/readme.md b/readme.md
index 10fe8df..6c75826 100644
--- a/readme.md
+++ b/readme.md
@@ -8,6 +8,9 @@
+[![Laravel Swagger](https://github.com/RonasIT/laravel-swagger/actions/workflows/laravel.yml/badge.svg?branch=master)](https://github.com/RonasIT/laravel-swagger/actions/workflows/laravel.yml)
+[![Coverage Status](https://coveralls.io/repos/github/RonasIT/laravel-swagger/badge.svg?branch=master)](https://coveralls.io/github/RonasIT/laravel-swagger?branch=master)
+
## Introduction
This plugin is designed to generate documentation for your REST API during the
From 8d9b8393c3785c3a52f22754349d8716589dedac Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Wed, 14 Dec 2022 18:24:21 +0600
Subject: [PATCH 06/20] feat: remove app, implement local driver test cases;
---
bootstrap/app.php | 27 ----
composer.json | 3 +
src/AutoDocServiceProvider.php | 4 +-
tests/LocalDriverTest.php | 50 +++++++
tests/TestCase.php | 32 ++--
tests/fixtures/LocalDriverTest/tmp_data.json | 138 ++++++++++++++++++
.../tmp_data_non_formatted.json | 1 +
tests/storage/.gitignore | 2 +
8 files changed, 218 insertions(+), 39 deletions(-)
delete mode 100755 bootstrap/app.php
create mode 100755 tests/LocalDriverTest.php
create mode 100644 tests/fixtures/LocalDriverTest/tmp_data.json
create mode 100644 tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
create mode 100755 tests/storage/.gitignore
diff --git a/bootstrap/app.php b/bootstrap/app.php
deleted file mode 100755
index bc7cf56..0000000
--- a/bootstrap/app.php
+++ /dev/null
@@ -1,27 +0,0 @@
-detectEnvironment(function()
-{
- return getenv('APP_ENV') ?: 'local';
-});
-$fn = ".env.{$env}";
-
-$app->loadEnvironmentFrom(file_exists(base_path($fn)) ? $fn : '.env');
-
-
-return $app;
diff --git a/composer.json b/composer.json
index 4a9fd2a..429b923 100644
--- a/composer.json
+++ b/composer.json
@@ -20,6 +20,9 @@
"laravel/framework": ">=5.3.0",
"phpunit/phpunit": ">=7.0|<=10.0"
},
+ "require-dev": {
+ "orchestra/testbench": "^6.25"
+ },
"autoload": {
"psr-4": {
"RonasIT\\Support\\AutoDoc\\": "src/",
diff --git a/src/AutoDocServiceProvider.php b/src/AutoDocServiceProvider.php
index 4652cd2..be0dd69 100644
--- a/src/AutoDocServiceProvider.php
+++ b/src/AutoDocServiceProvider.php
@@ -9,9 +9,7 @@ class AutoDocServiceProvider extends ServiceProvider
{
public function boot()
{
- $this->publishes([
- __DIR__ . '/../config/auto-doc.php' => config_path('auto-doc.php'),
- ], 'config');
+ $this->mergeConfigFrom(__DIR__ . '/../config/auto-doc.php', 'auto-doc');
$this->publishes([
__DIR__ . '/Views/swagger-description.blade.php' => resource_path('views/swagger-description.blade.php'),
diff --git a/tests/LocalDriverTest.php b/tests/LocalDriverTest.php
new file mode 100755
index 0000000..943b261
--- /dev/null
+++ b/tests/LocalDriverTest.php
@@ -0,0 +1,50 @@
+tmpData = $this->getJsonFixture('tmp_data');
+ $this->productionFilePath = __DIR__ . '/storage/documentation.json';
+
+ config(['auto-doc.drivers.local.production_path' => $this->productionFilePath]);
+
+ $this->localDriverClass = new LocalDriver();
+ }
+
+ public function testGetAndSaveTmpData()
+ {
+ $this->localDriverClass->saveTmpData($this->tmpData);
+
+ $this->assertEquals($this->tmpData, $this->localDriverClass->getTmpData());
+ }
+
+ public function testSaveData()
+ {
+ $this->localDriverClass->saveTmpData($this->tmpData);
+
+ $this->localDriverClass->saveData();
+
+ $this->assertFileExists($this->productionFilePath);
+ $this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), $this->productionFilePath);
+
+ $this->assertEquals([], $this->localDriverClass->getTmpData());
+ }
+
+ public function testGetDocumentation()
+ {
+ $documentation = $this->localDriverClass->getDocumentation();
+
+ $this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
+ }
+}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 173442f..a93a8b3 100755
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,18 +2,32 @@
namespace RonasIT\Support\Tests;
-use Illuminate\Foundation\Application;
-use Illuminate\Foundation\Testing\TestCase as BaseTest;
+use Orchestra\Testbench\TestCase as BaseTest;
+use RonasIT\Support\AutoDoc\AutoDocServiceProvider;
class TestCase extends BaseTest
{
- /**
- * Creates the application.
- *
- * @return Application
- */
- public function createApplication(): Application
+ protected function getPackageProviders($app): array
{
- return require __DIR__ . '/../bootstrap/app.php';
+ return [
+ AutoDocServiceProvider::class
+ ];
+ }
+
+ protected function getJsonFixture($name)
+ {
+ return json_decode($this->getFixture("{$name}.json"), true);
+ }
+
+ protected function getFixture($name)
+ {
+ return file_get_contents($this->generateFixturePath($name));
+ }
+
+ protected function generateFixturePath($name): string
+ {
+ $testClass = last(explode('\\', get_class($this)));
+
+ return __DIR__ . "/fixtures/{$testClass}/{$name}";
}
}
diff --git a/tests/fixtures/LocalDriverTest/tmp_data.json b/tests/fixtures/LocalDriverTest/tmp_data.json
new file mode 100644
index 0000000..d1e7d58
--- /dev/null
+++ b/tests/fixtures/LocalDriverTest/tmp_data.json
@@ -0,0 +1,138 @@
+{
+ "swagger": "2.0",
+ "host": "localhost",
+ "basePath": "\/",
+ "schemes": [],
+ "paths": {
+ "\/auth\/login": {
+ "post": {
+ "tags": [
+ "auth"
+ ],
+ "consumes": [
+ "application\/json"
+ ],
+ "produces": [
+ "application\/json"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "",
+ "required": true,
+ "schema": {
+ "$ref": "#\/definitions\/authloginObject"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Operation successfully done",
+ "schema": {
+ "example": {
+ "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8",
+ "user": {
+ "id": 2,
+ "email": "user@test.com",
+ "deleted_at": null,
+ "created_at": "2017-11-16 06:08:34",
+ "updated_at": "2018-01-01 00:00:00",
+ "role_id": 2,
+ "clio_user_id": null,
+ "images_limit": 500,
+ "state": "confirmed",
+ "reset_password_hash": null,
+ "failed_auth_attempts": 0,
+ "last_auth_attempt": "2018-01-01 00:00:00",
+ "first_name": "user",
+ "last_name": null,
+ "set_password_hash_created_at": null,
+ "full_name": "user",
+ "settings": null,
+ "new_email": "new_email_test2@test.com",
+ "is_email_verified": true,
+ "role": {
+ "id": 2,
+ "name": "client",
+ "created_at": null,
+ "updated_at": null,
+ "settable": true
+ },
+ "services": [
+ {
+ "id": 1,
+ "name": "500px",
+ "created_at": "2017-11-16 06:08:34",
+ "updated_at": "2017-11-16 06:08:34",
+ "is_photo_service": true,
+ "allow_not_unique_accounts": false,
+ "pivot": {
+ "user_id": 2,
+ "service_id": 1,
+ "is_token_expired": 0
+ }
+ }
+ ]
+ },
+ "ttl": 60,
+ "refresh_ttl": 20160
+ }
+ }
+ },
+ "401": {
+ "description": "Unauthorized",
+ "schema": {
+ "example": {
+ "error": "You have entered an incorrect credentials."
+ }
+ }
+ },
+ "400": {
+ "description": "Bad Request",
+ "schema": {
+ "example": {
+ "error": "The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."
+ }
+ }
+ }
+ },
+ "security": [],
+ "description": "",
+ "summary": "login"
+ }
+ }
+ },
+ "definitions": {
+ "authloginObject": {
+ "type": "object",
+ "properties": {
+ "email": {
+ "type": "string",
+ "description": "2"
+ },
+ "password": {
+ "type": "string",
+ "description": ""
+ }
+ },
+ "required": [
+ "email",
+ "password"
+ ],
+ "example": {
+ "email": "admin@test.com",
+ "password": "123"
+ }
+ }
+ },
+ "info": {
+ "description": "This is automatically collected documentation",
+ "version": "0.0.0",
+ "title": "Photoclaim API",
+ "termsOfService": "",
+ "contact": {
+ "email": "your@email.com"
+ }
+ }
+}
diff --git a/tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json b/tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
new file mode 100644
index 0000000..9dd48d8
--- /dev/null
+++ b/tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
@@ -0,0 +1 @@
+{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"clio_user_id":null,"images_limit":500,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","settings":null,"new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true},"services":[{"id":1,"name":"500px","created_at":"2017-11-16 06:08:34","updated_at":"2017-11-16 06:08:34","is_photo_service":true,"allow_not_unique_accounts":false,"pivot":{"user_id":2,"service_id":1,"is_token_expired":0}}]},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Photoclaim API","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
diff --git a/tests/storage/.gitignore b/tests/storage/.gitignore
new file mode 100755
index 0000000..d6b7ef3
--- /dev/null
+++ b/tests/storage/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
From d064cc37cff8016895fbdf93f0f7a036c4128d2f Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Wed, 14 Dec 2022 18:31:00 +0600
Subject: [PATCH 07/20] feat: configure coverall library;
---
.github/workflows/laravel.yml | 8 +++++++-
composer.json | 3 ++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml
index 072652d..69d7860 100644
--- a/.github/workflows/laravel.yml
+++ b/.github/workflows/laravel.yml
@@ -21,4 +21,10 @@ jobs:
- 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
+ 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
diff --git a/composer.json b/composer.json
index 429b923..56a922b 100644
--- a/composer.json
+++ b/composer.json
@@ -21,7 +21,8 @@
"phpunit/phpunit": ">=7.0|<=10.0"
},
"require-dev": {
- "orchestra/testbench": "^6.25"
+ "orchestra/testbench": "^6.25",
+ "php-coveralls/php-coveralls": "^2.5"
},
"autoload": {
"psr-4": {
From 889b3998c380d8844d27248e544cde6d5935c393 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Wed, 14 Dec 2022 18:57:08 +0600
Subject: [PATCH 08/20] fix: path to src in phpunit.xml;
---
phpunit.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/phpunit.xml b/phpunit.xml
index 2238caf..288f36d 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -2,7 +2,7 @@
- ./app
+ ./src
./app/Http/routes.php
From 61aabf71f86358dac0505758bd2d3a7cd65d6a62 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Wed, 14 Dec 2022 19:18:37 +0600
Subject: [PATCH 09/20] tests: exceptions tests for LocalDriver class;
---
tests/LocalDriverTest.php | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tests/LocalDriverTest.php b/tests/LocalDriverTest.php
index 943b261..0439739 100755
--- a/tests/LocalDriverTest.php
+++ b/tests/LocalDriverTest.php
@@ -3,6 +3,8 @@
namespace RonasIT\Support\Tests;
use RonasIT\Support\AutoDoc\Drivers\LocalDriver;
+use Illuminate\Contracts\Filesystem\FileNotFoundException;
+use RonasIT\Support\AutoDoc\Exceptions\MissedProductionFilePathException;
class LocalDriverTest extends TestCase
{
@@ -22,6 +24,15 @@ public function setUp(): void
$this->localDriverClass = new LocalDriver();
}
+ public function testCreateClassConfigEmpty()
+ {
+ $this->expectException(MissedProductionFilePathException::class);
+
+ config(['auto-doc.drivers.local.production_path' => null]);
+
+ new LocalDriver();
+ }
+
public function testGetAndSaveTmpData()
{
$this->localDriverClass->saveTmpData($this->tmpData);
@@ -47,4 +58,13 @@ public function testGetDocumentation()
$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
}
+
+ public function testGetDocumentationFileNotExists()
+ {
+ $this->expectException(FileNotFoundException::class);
+
+ config(['auto-doc.drivers.local.production_path' => 'not_exists_file']);
+
+ (new LocalDriver())->getDocumentation();
+ }
}
From a038bb40fb21b795113a0cf213cca68783ed0605 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Wed, 14 Dec 2022 21:00:35 +0600
Subject: [PATCH 10/20] tests: save tmp data tests for RemoteDriver;
---
.gitignore | 6 +-
tests/RemoteDriverTest.php | 46 ++++++
tests/TestCase.php | 13 ++
tests/fixtures/RemoteDriverTest/tmp_data.json | 138 ++++++++++++++++++
.../tmp_data_non_formatted.json | 1 +
tests/storage/.gitignore | 2 -
6 files changed, 203 insertions(+), 3 deletions(-)
create mode 100755 tests/RemoteDriverTest.php
create mode 100644 tests/fixtures/RemoteDriverTest/tmp_data.json
create mode 100644 tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json
delete mode 100755 tests/storage/.gitignore
diff --git a/.gitignore b/.gitignore
index 3c39fef..15f46e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,8 @@ bootstrap/cache/
# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
.rocketeer/
-composer.lock
\ No newline at end of file
+composer.lock
+
+.phpunit.result.cache
+
+tests/storage
diff --git a/tests/RemoteDriverTest.php b/tests/RemoteDriverTest.php
new file mode 100755
index 0000000..5b131df
--- /dev/null
+++ b/tests/RemoteDriverTest.php
@@ -0,0 +1,46 @@
+tmpData = $this->getJsonFixture('tmp_data');
+ $this->tmpDocumentationFilePath = __DIR__ . '/storage/temp_documentation.json';
+
+ $this->removeDriverClass = new RemoteDriver();
+ }
+
+ public function testSaveTmpData()
+ {
+ $this->removeDriverClass->saveTmpData($this->tmpData);
+
+ $this->assertFileExists($this->tmpDocumentationFilePath);
+ $this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), $this->tmpDocumentationFilePath);
+ }
+
+ public function testGetTmpData()
+ {
+ file_put_contents($this->tmpDocumentationFilePath, json_encode($this->tmpData));
+
+ $result = $this->removeDriverClass->getTmpData();
+
+ $this->assertEquals($this->tmpData, $result);
+ }
+
+ public function testGetTmpDataNoFile()
+ {
+ $result = $this->removeDriverClass->getTmpData();
+
+ $this->assertNull($result);
+ }
+}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index a93a8b3..1f24981 100755
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,11 +2,19 @@
namespace RonasIT\Support\Tests;
+use Illuminate\Filesystem\Filesystem;
use Orchestra\Testbench\TestCase as BaseTest;
use RonasIT\Support\AutoDoc\AutoDocServiceProvider;
class TestCase extends BaseTest
{
+ public function tearDown(): void
+ {
+ parent::tearDown();
+
+ (new Filesystem)->cleanDirectory(__DIR__ . '/storage');
+ }
+
protected function getPackageProviders($app): array
{
return [
@@ -14,6 +22,11 @@ protected function getPackageProviders($app): array
];
}
+ protected function defineEnvironment($app)
+ {
+ $app->useStoragePath(__DIR__ . '/storage');
+ }
+
protected function getJsonFixture($name)
{
return json_decode($this->getFixture("{$name}.json"), true);
diff --git a/tests/fixtures/RemoteDriverTest/tmp_data.json b/tests/fixtures/RemoteDriverTest/tmp_data.json
new file mode 100644
index 0000000..d1e7d58
--- /dev/null
+++ b/tests/fixtures/RemoteDriverTest/tmp_data.json
@@ -0,0 +1,138 @@
+{
+ "swagger": "2.0",
+ "host": "localhost",
+ "basePath": "\/",
+ "schemes": [],
+ "paths": {
+ "\/auth\/login": {
+ "post": {
+ "tags": [
+ "auth"
+ ],
+ "consumes": [
+ "application\/json"
+ ],
+ "produces": [
+ "application\/json"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "",
+ "required": true,
+ "schema": {
+ "$ref": "#\/definitions\/authloginObject"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Operation successfully done",
+ "schema": {
+ "example": {
+ "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8",
+ "user": {
+ "id": 2,
+ "email": "user@test.com",
+ "deleted_at": null,
+ "created_at": "2017-11-16 06:08:34",
+ "updated_at": "2018-01-01 00:00:00",
+ "role_id": 2,
+ "clio_user_id": null,
+ "images_limit": 500,
+ "state": "confirmed",
+ "reset_password_hash": null,
+ "failed_auth_attempts": 0,
+ "last_auth_attempt": "2018-01-01 00:00:00",
+ "first_name": "user",
+ "last_name": null,
+ "set_password_hash_created_at": null,
+ "full_name": "user",
+ "settings": null,
+ "new_email": "new_email_test2@test.com",
+ "is_email_verified": true,
+ "role": {
+ "id": 2,
+ "name": "client",
+ "created_at": null,
+ "updated_at": null,
+ "settable": true
+ },
+ "services": [
+ {
+ "id": 1,
+ "name": "500px",
+ "created_at": "2017-11-16 06:08:34",
+ "updated_at": "2017-11-16 06:08:34",
+ "is_photo_service": true,
+ "allow_not_unique_accounts": false,
+ "pivot": {
+ "user_id": 2,
+ "service_id": 1,
+ "is_token_expired": 0
+ }
+ }
+ ]
+ },
+ "ttl": 60,
+ "refresh_ttl": 20160
+ }
+ }
+ },
+ "401": {
+ "description": "Unauthorized",
+ "schema": {
+ "example": {
+ "error": "You have entered an incorrect credentials."
+ }
+ }
+ },
+ "400": {
+ "description": "Bad Request",
+ "schema": {
+ "example": {
+ "error": "The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."
+ }
+ }
+ }
+ },
+ "security": [],
+ "description": "",
+ "summary": "login"
+ }
+ }
+ },
+ "definitions": {
+ "authloginObject": {
+ "type": "object",
+ "properties": {
+ "email": {
+ "type": "string",
+ "description": "2"
+ },
+ "password": {
+ "type": "string",
+ "description": ""
+ }
+ },
+ "required": [
+ "email",
+ "password"
+ ],
+ "example": {
+ "email": "admin@test.com",
+ "password": "123"
+ }
+ }
+ },
+ "info": {
+ "description": "This is automatically collected documentation",
+ "version": "0.0.0",
+ "title": "Photoclaim API",
+ "termsOfService": "",
+ "contact": {
+ "email": "your@email.com"
+ }
+ }
+}
diff --git a/tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json b/tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json
new file mode 100644
index 0000000..9dd48d8
--- /dev/null
+++ b/tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json
@@ -0,0 +1 @@
+{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"clio_user_id":null,"images_limit":500,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","settings":null,"new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true},"services":[{"id":1,"name":"500px","created_at":"2017-11-16 06:08:34","updated_at":"2017-11-16 06:08:34","is_photo_service":true,"allow_not_unique_accounts":false,"pivot":{"user_id":2,"service_id":1,"is_token_expired":0}}]},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Photoclaim API","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
diff --git a/tests/storage/.gitignore b/tests/storage/.gitignore
deleted file mode 100755
index d6b7ef3..0000000
--- a/tests/storage/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*
-!.gitignore
From 39ec6f3fd5b5af0b80ffcb29ce40f92b888a1a5e Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Wed, 14 Dec 2022 21:03:31 +0600
Subject: [PATCH 11/20] fix: revert gitignore for tests/storage dir;
---
.gitignore | 2 --
tests/storage/.gitignore | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
create mode 100755 tests/storage/.gitignore
diff --git a/.gitignore b/.gitignore
index 15f46e9..b6d6068 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,5 +17,3 @@ bootstrap/cache/
composer.lock
.phpunit.result.cache
-
-tests/storage
diff --git a/tests/storage/.gitignore b/tests/storage/.gitignore
new file mode 100755
index 0000000..d6b7ef3
--- /dev/null
+++ b/tests/storage/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
From ec3450ce7e684c72f2a243debb4bb2bce24f3742 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Wed, 14 Dec 2022 21:06:30 +0600
Subject: [PATCH 12/20] fix: get documentation local driver test;
---
tests/LocalDriverTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/LocalDriverTest.php b/tests/LocalDriverTest.php
index 0439739..769cb28 100755
--- a/tests/LocalDriverTest.php
+++ b/tests/LocalDriverTest.php
@@ -54,6 +54,8 @@ public function testSaveData()
public function testGetDocumentation()
{
+ file_put_contents($this->productionFilePath, json_encode($this->tmpData));
+
$documentation = $this->localDriverClass->getDocumentation();
$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
From e0019370d2ca899c7c7583c133b81844fdcce6af Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Thu, 15 Dec 2022 13:53:27 +0600
Subject: [PATCH 13/20] fix: get documentation remote driver test;
---
src/Drivers/RemoteDriver.php | 41 +++++++++++++------
tests/RemoteDriverTest.php | 79 ++++++++++++++++++++++++++++++++++++
tests/TestCase.php | 23 ++++++++++-
3 files changed, 129 insertions(+), 14 deletions(-)
diff --git a/src/Drivers/RemoteDriver.php b/src/Drivers/RemoteDriver.php
index 836799f..750e17b 100755
--- a/src/Drivers/RemoteDriver.php
+++ b/src/Drivers/RemoteDriver.php
@@ -2,7 +2,7 @@
namespace RonasIT\Support\AutoDoc\Drivers;
-use stdClass;
+use Illuminate\Contracts\Filesystem\FileNotFoundException;
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface;
class RemoteDriver implements SwaggerDriverInterface
@@ -36,16 +36,9 @@ public function getTmpData()
public function saveData()
{
- $curl = curl_init();
-
- curl_setopt($curl, CURLOPT_URL, $this->getUrl());
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($this->getTmpData()));
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
-
- curl_exec($curl);
- curl_close($curl);
+ $this->makeHttpRequest('post', $this->getUrl(), $this->getTmpData(), [
+ 'Content-Type: application/json'
+ ]);
if (file_exists($this->tempFileName)) {
unlink($this->tempFileName);
@@ -54,9 +47,9 @@ public function saveData()
public function getDocumentation(): array
{
- $content = file_get_contents($this->getUrl());
+ list($content, $statusCode) = $this->makeHttpRequest('get', $this->getUrl());
- if (empty($content)) {
+ if (empty($content) || $statusCode !== 200) {
throw new FileNotFoundException();
}
@@ -67,4 +60,26 @@ protected function getUrl(): string
{
return "{$this->remoteUrl}/documentations/{$this->key}";
}
+
+ protected function makeHttpRequest($type, $url, $data = [], $headers = [])
+ {
+ $curl = curl_init();
+
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+
+ if ($type === 'post') {
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
+ }
+
+ $result = curl_exec($curl);
+
+ $statusCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
+
+ curl_close($curl);
+
+ return [$result, $statusCode];
+ }
}
diff --git a/tests/RemoteDriverTest.php b/tests/RemoteDriverTest.php
index 5b131df..fbea2f7 100755
--- a/tests/RemoteDriverTest.php
+++ b/tests/RemoteDriverTest.php
@@ -3,6 +3,7 @@
namespace RonasIT\Support\Tests;
use RonasIT\Support\AutoDoc\Drivers\RemoteDriver;
+use Illuminate\Contracts\Filesystem\FileNotFoundException;
class RemoteDriverTest extends TestCase
{
@@ -43,4 +44,82 @@ public function testGetTmpDataNoFile()
$this->assertNull($result);
}
+
+ public function testSaveData()
+ {
+ config(['auto-doc.drivers.remote.key' => 'mocked_key']);
+ config(['auto-doc.drivers.remote.url' => 'mocked_url']);
+
+ $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+
+ $mock
+ ->expects($this->once())
+ ->method('makeHttpRequest')
+ ->with('post', 'mocked_url/documentations/mocked_key', $this->tmpData, [
+ 'Content-Type: application/json'
+ ])
+ ->willReturn(true);
+
+ file_put_contents($this->tmpDocumentationFilePath, json_encode($this->tmpData));
+
+ $mock->saveData();
+
+ $this->assertFileDoesNotExist($this->tmpDocumentationFilePath);
+ }
+
+ public function testSaveDataWithoutTmpFile()
+ {
+ config(['auto-doc.drivers.remote.key' => 'mocked_key']);
+ config(['auto-doc.drivers.remote.url' => 'mocked_url']);
+
+ $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+
+ $mock
+ ->expects($this->once())
+ ->method('makeHttpRequest')
+ ->with('post', 'mocked_url/documentations/mocked_key', null, [
+ 'Content-Type: application/json'
+ ])
+ ->willReturn(true);
+
+ $mock->saveData();
+ }
+
+ public function testGetDocumentation()
+ {
+ config(['auto-doc.drivers.remote.key' => 'mocked_key']);
+ config(['auto-doc.drivers.remote.url' => 'mocked_url']);
+
+ $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+
+ $mock
+ ->expects($this->once())
+ ->method('makeHttpRequest')
+ ->with('get', 'mocked_url/documentations/mocked_key')
+ ->willReturn([$this->getFixture('tmp_data_non_formatted.json'), 200]);
+
+ $documentation = $mock->getDocumentation();
+
+ $this->assertEquals($this->tmpData, $documentation);
+ }
+
+ public function testGetDocumentationNoFile()
+ {
+ $this->expectException(FileNotFoundException::class);
+
+ config(['auto-doc.drivers.remote.key' => 'mocked_key']);
+ config(['auto-doc.drivers.remote.url' => 'mocked_url']);
+
+ $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+
+ $mock
+ ->expects($this->once())
+ ->method('makeHttpRequest')
+ ->with('get', 'mocked_url/documentations/mocked_key')
+ ->willReturn(json_encode([['error' => 'Not found.'], 404]));
+
+ $documentation = $mock->getDocumentation();
+
+ $this->assertEquals($this->tmpData, $documentation);
+ }
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 1f24981..0ad15b1 100755
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -12,7 +12,7 @@ public function tearDown(): void
{
parent::tearDown();
- (new Filesystem)->cleanDirectory(__DIR__ . '/storage');
+ $this->clearDirectory(__DIR__ . '/storage', ['.gitignore']);
}
protected function getPackageProviders($app): array
@@ -27,6 +27,14 @@ protected function defineEnvironment($app)
$app->useStoragePath(__DIR__ . '/storage');
}
+ protected function mockCLass($className, $methods = [])
+ {
+ return $this
+ ->getMockBuilder($className)
+ ->onlyMethods($methods)
+ ->getMock();
+ }
+
protected function getJsonFixture($name)
{
return json_decode($this->getFixture("{$name}.json"), true);
@@ -43,4 +51,17 @@ protected function generateFixturePath($name): string
return __DIR__ . "/fixtures/{$testClass}/{$name}";
}
+
+ protected function clearDirectory($dirPath, $exceptPaths = [])
+ {
+ $fileSystem = new Filesystem();
+
+ $files = $fileSystem->allFiles($dirPath);
+
+ foreach ($files as $file) {
+ if (!in_array($file->getFilename(), $exceptPaths)) {
+ $fileSystem->delete($file->getRealPath());
+ }
+ }
+ }
}
From f9c29cca3ba55bfa8497be33dc30cb5fca0ccc9e Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Thu, 15 Dec 2022 14:03:47 +0600
Subject: [PATCH 14/20] tests: ignore remote driver curl logic from the
coverage;
---
src/Drivers/RemoteDriver.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/Drivers/RemoteDriver.php b/src/Drivers/RemoteDriver.php
index 750e17b..abac160 100755
--- a/src/Drivers/RemoteDriver.php
+++ b/src/Drivers/RemoteDriver.php
@@ -61,6 +61,9 @@ protected function getUrl(): string
return "{$this->remoteUrl}/documentations/{$this->key}";
}
+ /**
+ * @codeCoverageIgnore
+ */
protected function makeHttpRequest($type, $url, $data = [], $headers = [])
{
$curl = curl_init();
From b00e0acd4fc15a0e5a995aea046d6157e0bc5918 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Thu, 15 Dec 2022 14:59:30 +0600
Subject: [PATCH 15/20] tests: storage driver class test cases;
---
src/Drivers/StorageDriver.php | 1 -
tests/StorageDriverTest.php | 65 +++++++++
.../fixtures/StorageDriverTest/tmp_data.json | 138 ++++++++++++++++++
.../tmp_data_non_formatted.json | 1 +
4 files changed, 204 insertions(+), 1 deletion(-)
create mode 100755 tests/StorageDriverTest.php
create mode 100644 tests/fixtures/StorageDriverTest/tmp_data.json
create mode 100644 tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json
diff --git a/src/Drivers/StorageDriver.php b/src/Drivers/StorageDriver.php
index 015e5d8..015631d 100755
--- a/src/Drivers/StorageDriver.php
+++ b/src/Drivers/StorageDriver.php
@@ -2,7 +2,6 @@
namespace RonasIT\Support\AutoDoc\Drivers;
-use stdClass;
use Illuminate\Support\Facades\Storage;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface;
diff --git a/tests/StorageDriverTest.php b/tests/StorageDriverTest.php
new file mode 100755
index 0000000..898ffd0
--- /dev/null
+++ b/tests/StorageDriverTest.php
@@ -0,0 +1,65 @@
+tmpData = $this->getJsonFixture('tmp_data');
+ $this->filePath = __DIR__ . '/storage/documentation.json';
+
+ config(['auto-doc.drivers.storage.disk' => 'testing']);
+ config(['auto-doc.drivers.storage.production_path' => $this->filePath]);
+
+ $this->disk = Storage::fake('testing');
+
+ $this->storageDriverClass = new StorageDriver();
+ }
+
+ public function testGetAndSaveTmpData()
+ {
+ $this->storageDriverClass->saveTmpData($this->tmpData);
+
+ $this->assertEquals($this->tmpData, $this->storageDriverClass->getTmpData());
+ }
+
+ public function testSaveData()
+ {
+ $this->storageDriverClass->saveTmpData($this->tmpData);
+
+ $this->storageDriverClass->saveData();
+
+ $this->disk->assertExists($this->filePath);
+ $this->assertEquals($this->getFixture('tmp_data_non_formatted.json'), $this->disk->get($this->filePath));
+
+ $this->assertEquals([], $this->storageDriverClass->getTmpData());
+ }
+
+ public function testGetDocumentation()
+ {
+ $this->disk->put($this->filePath, $this->getFixture('tmp_data_non_formatted.json'));
+
+ $documentation = $this->storageDriverClass->getDocumentation();
+
+ $this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
+ }
+
+ public function testGetDocumentationFileNotExists()
+ {
+ $this->expectException(FileNotFoundException::class);
+
+ $this->storageDriverClass->getDocumentation();
+ }
+}
diff --git a/tests/fixtures/StorageDriverTest/tmp_data.json b/tests/fixtures/StorageDriverTest/tmp_data.json
new file mode 100644
index 0000000..d1e7d58
--- /dev/null
+++ b/tests/fixtures/StorageDriverTest/tmp_data.json
@@ -0,0 +1,138 @@
+{
+ "swagger": "2.0",
+ "host": "localhost",
+ "basePath": "\/",
+ "schemes": [],
+ "paths": {
+ "\/auth\/login": {
+ "post": {
+ "tags": [
+ "auth"
+ ],
+ "consumes": [
+ "application\/json"
+ ],
+ "produces": [
+ "application\/json"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "",
+ "required": true,
+ "schema": {
+ "$ref": "#\/definitions\/authloginObject"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Operation successfully done",
+ "schema": {
+ "example": {
+ "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8",
+ "user": {
+ "id": 2,
+ "email": "user@test.com",
+ "deleted_at": null,
+ "created_at": "2017-11-16 06:08:34",
+ "updated_at": "2018-01-01 00:00:00",
+ "role_id": 2,
+ "clio_user_id": null,
+ "images_limit": 500,
+ "state": "confirmed",
+ "reset_password_hash": null,
+ "failed_auth_attempts": 0,
+ "last_auth_attempt": "2018-01-01 00:00:00",
+ "first_name": "user",
+ "last_name": null,
+ "set_password_hash_created_at": null,
+ "full_name": "user",
+ "settings": null,
+ "new_email": "new_email_test2@test.com",
+ "is_email_verified": true,
+ "role": {
+ "id": 2,
+ "name": "client",
+ "created_at": null,
+ "updated_at": null,
+ "settable": true
+ },
+ "services": [
+ {
+ "id": 1,
+ "name": "500px",
+ "created_at": "2017-11-16 06:08:34",
+ "updated_at": "2017-11-16 06:08:34",
+ "is_photo_service": true,
+ "allow_not_unique_accounts": false,
+ "pivot": {
+ "user_id": 2,
+ "service_id": 1,
+ "is_token_expired": 0
+ }
+ }
+ ]
+ },
+ "ttl": 60,
+ "refresh_ttl": 20160
+ }
+ }
+ },
+ "401": {
+ "description": "Unauthorized",
+ "schema": {
+ "example": {
+ "error": "You have entered an incorrect credentials."
+ }
+ }
+ },
+ "400": {
+ "description": "Bad Request",
+ "schema": {
+ "example": {
+ "error": "The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."
+ }
+ }
+ }
+ },
+ "security": [],
+ "description": "",
+ "summary": "login"
+ }
+ }
+ },
+ "definitions": {
+ "authloginObject": {
+ "type": "object",
+ "properties": {
+ "email": {
+ "type": "string",
+ "description": "2"
+ },
+ "password": {
+ "type": "string",
+ "description": ""
+ }
+ },
+ "required": [
+ "email",
+ "password"
+ ],
+ "example": {
+ "email": "admin@test.com",
+ "password": "123"
+ }
+ }
+ },
+ "info": {
+ "description": "This is automatically collected documentation",
+ "version": "0.0.0",
+ "title": "Photoclaim API",
+ "termsOfService": "",
+ "contact": {
+ "email": "your@email.com"
+ }
+ }
+}
diff --git a/tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json b/tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json
new file mode 100644
index 0000000..9dd48d8
--- /dev/null
+++ b/tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json
@@ -0,0 +1 @@
+{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"clio_user_id":null,"images_limit":500,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","settings":null,"new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true},"services":[{"id":1,"name":"500px","created_at":"2017-11-16 06:08:34","updated_at":"2017-11-16 06:08:34","is_photo_service":true,"allow_not_unique_accounts":false,"pivot":{"user_id":2,"service_id":1,"is_token_expired":0}}]},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Photoclaim API","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
From 2d360db6ea1caf2473de7f3c8ab1e2b82ffea69d Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Mon, 19 Dec 2022 21:17:31 +0600
Subject: [PATCH 16/20] feat: format yml files, move views to the resources
folder, move storage to base path, implement swagger service tests;
---
.github/workflows/laravel.yml | 42 +++---
config/auto-doc.php | 2 +-
docker-compose.yml | 17 ++-
.../views}/documentation.blade.php | 0
.../views}/swagger-description.blade.php | 0
.../views}/swagger/favicon-16x16.png | Bin
.../views}/swagger/favicon-32x32.png | Bin
.../views}/swagger/swagger-ui-bundle.js | 0
.../views}/swagger/swagger-ui-bundle.js.map | 0
.../swagger/swagger-ui-standalone-preset.js | 0
.../swagger-ui-standalone-preset.js.map | 0
.../views}/swagger/swagger-ui.css | 0
.../views}/swagger/swagger-ui.css.map | 0
.../views}/swagger/swagger-ui.js | 0
.../views}/swagger/swagger-ui.js.map | 0
src/AutoDocServiceProvider.php | 4 +-
{tests/storage => storage}/.gitignore | 0
tests/LocalDriverTest.php | 2 +-
tests/RemoteDriverTest.php | 5 +-
tests/SwaggerServiceTest.php | 132 ++++++++++++++++++
tests/TestCase.php | 41 ++++--
.../example_success_roles_response.json | 26 ++++
.../example_success_user_response.json | 9 ++
.../tmp_data_get_user_request.json | 63 +++++++++
.../tmp_data_search_roles_request.json | 67 +++++++++
...ata_search_roles_request_jwt_security.json | 72 ++++++++++
...search_roles_request_laravel_security.json | 72 ++++++++++
tests/support/Traits/MockTrait.php | 14 ++
.../Traits/SwaggerServiceMockTrait.php | 21 +++
29 files changed, 543 insertions(+), 46 deletions(-)
rename {src/Views => resources/views}/documentation.blade.php (100%)
rename {src/Views => resources/views}/swagger-description.blade.php (100%)
rename {src/Views => resources/views}/swagger/favicon-16x16.png (100%)
rename {src/Views => resources/views}/swagger/favicon-32x32.png (100%)
rename {src/Views => resources/views}/swagger/swagger-ui-bundle.js (100%)
rename {src/Views => resources/views}/swagger/swagger-ui-bundle.js.map (100%)
rename {src/Views => resources/views}/swagger/swagger-ui-standalone-preset.js (100%)
rename {src/Views => resources/views}/swagger/swagger-ui-standalone-preset.js.map (100%)
rename {src/Views => resources/views}/swagger/swagger-ui.css (100%)
rename {src/Views => resources/views}/swagger/swagger-ui.css.map (100%)
rename {src/Views => resources/views}/swagger/swagger-ui.js (100%)
rename {src/Views => resources/views}/swagger/swagger-ui.js.map (100%)
rename {tests/storage => storage}/.gitignore (100%)
create mode 100755 tests/SwaggerServiceTest.php
create mode 100644 tests/fixtures/SwaggerServiceTest/example_success_roles_response.json
create mode 100644 tests/fixtures/SwaggerServiceTest/example_success_user_response.json
create mode 100644 tests/fixtures/SwaggerServiceTest/tmp_data_get_user_request.json
create mode 100644 tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request.json
create mode 100644 tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_jwt_security.json
create mode 100644 tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_laravel_security.json
create mode 100644 tests/support/Traits/MockTrait.php
create mode 100644 tests/support/Traits/SwaggerServiceMockTrait.php
diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml
index 69d7860..bf6572d 100644
--- a/.github/workflows/laravel.yml
+++ b/.github/workflows/laravel.yml
@@ -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
diff --git a/config/auto-doc.php b/config/auto-doc.php
index 1c38045..e4b9b7d 100644
--- a/config/auto-doc.php
+++ b/config/auto-doc.php
@@ -31,7 +31,7 @@
|
| You can use your custom documentation view
*/
- 'description' => 'swagger-description',
+ 'description' => 'auto-doc::swagger-description',
'version' => '0.0.0',
'title' => 'Name of Your Application',
'termsOfService' => '',
diff --git a/docker-compose.yml b/docker-compose.yml
index 3f2b91e..95e7cfc 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -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
diff --git a/src/Views/documentation.blade.php b/resources/views/documentation.blade.php
similarity index 100%
rename from src/Views/documentation.blade.php
rename to resources/views/documentation.blade.php
diff --git a/src/Views/swagger-description.blade.php b/resources/views/swagger-description.blade.php
similarity index 100%
rename from src/Views/swagger-description.blade.php
rename to resources/views/swagger-description.blade.php
diff --git a/src/Views/swagger/favicon-16x16.png b/resources/views/swagger/favicon-16x16.png
similarity index 100%
rename from src/Views/swagger/favicon-16x16.png
rename to resources/views/swagger/favicon-16x16.png
diff --git a/src/Views/swagger/favicon-32x32.png b/resources/views/swagger/favicon-32x32.png
similarity index 100%
rename from src/Views/swagger/favicon-32x32.png
rename to resources/views/swagger/favicon-32x32.png
diff --git a/src/Views/swagger/swagger-ui-bundle.js b/resources/views/swagger/swagger-ui-bundle.js
similarity index 100%
rename from src/Views/swagger/swagger-ui-bundle.js
rename to resources/views/swagger/swagger-ui-bundle.js
diff --git a/src/Views/swagger/swagger-ui-bundle.js.map b/resources/views/swagger/swagger-ui-bundle.js.map
similarity index 100%
rename from src/Views/swagger/swagger-ui-bundle.js.map
rename to resources/views/swagger/swagger-ui-bundle.js.map
diff --git a/src/Views/swagger/swagger-ui-standalone-preset.js b/resources/views/swagger/swagger-ui-standalone-preset.js
similarity index 100%
rename from src/Views/swagger/swagger-ui-standalone-preset.js
rename to resources/views/swagger/swagger-ui-standalone-preset.js
diff --git a/src/Views/swagger/swagger-ui-standalone-preset.js.map b/resources/views/swagger/swagger-ui-standalone-preset.js.map
similarity index 100%
rename from src/Views/swagger/swagger-ui-standalone-preset.js.map
rename to resources/views/swagger/swagger-ui-standalone-preset.js.map
diff --git a/src/Views/swagger/swagger-ui.css b/resources/views/swagger/swagger-ui.css
similarity index 100%
rename from src/Views/swagger/swagger-ui.css
rename to resources/views/swagger/swagger-ui.css
diff --git a/src/Views/swagger/swagger-ui.css.map b/resources/views/swagger/swagger-ui.css.map
similarity index 100%
rename from src/Views/swagger/swagger-ui.css.map
rename to resources/views/swagger/swagger-ui.css.map
diff --git a/src/Views/swagger/swagger-ui.js b/resources/views/swagger/swagger-ui.js
similarity index 100%
rename from src/Views/swagger/swagger-ui.js
rename to resources/views/swagger/swagger-ui.js
diff --git a/src/Views/swagger/swagger-ui.js.map b/resources/views/swagger/swagger-ui.js.map
similarity index 100%
rename from src/Views/swagger/swagger-ui.js.map
rename to resources/views/swagger/swagger-ui.js.map
diff --git a/src/AutoDocServiceProvider.php b/src/AutoDocServiceProvider.php
index be0dd69..bfc4622 100644
--- a/src/AutoDocServiceProvider.php
+++ b/src/AutoDocServiceProvider.php
@@ -12,7 +12,7 @@ public function boot()
$this->mergeConfigFrom(__DIR__ . '/../config/auto-doc.php', 'auto-doc');
$this->publishes([
- __DIR__ . '/Views/swagger-description.blade.php' => resource_path('views/swagger-description.blade.php'),
+ __DIR__ . '/../resources/views/swagger-description.blade.php' => resource_path('views/swagger-description.blade.php'),
], 'view');
if (!$this->app->routesAreCached()) {
@@ -23,7 +23,7 @@ public function boot()
PushDocumentationCommand::class
]);
- $this->loadViewsFrom(__DIR__ . '/Views', 'auto-doc');
+ $this->loadViewsFrom(__DIR__ . '/../resources/views', 'auto-doc');
}
public function register()
diff --git a/tests/storage/.gitignore b/storage/.gitignore
similarity index 100%
rename from tests/storage/.gitignore
rename to storage/.gitignore
diff --git a/tests/LocalDriverTest.php b/tests/LocalDriverTest.php
index 769cb28..939d5df 100755
--- a/tests/LocalDriverTest.php
+++ b/tests/LocalDriverTest.php
@@ -17,7 +17,7 @@ public function setUp(): void
parent::setUp();
$this->tmpData = $this->getJsonFixture('tmp_data');
- $this->productionFilePath = __DIR__ . '/storage/documentation.json';
+ $this->productionFilePath = __DIR__ . '/../storage/documentation.json';
config(['auto-doc.drivers.local.production_path' => $this->productionFilePath]);
diff --git a/tests/RemoteDriverTest.php b/tests/RemoteDriverTest.php
index fbea2f7..57b22b0 100755
--- a/tests/RemoteDriverTest.php
+++ b/tests/RemoteDriverTest.php
@@ -3,10 +3,13 @@
namespace RonasIT\Support\Tests;
use RonasIT\Support\AutoDoc\Drivers\RemoteDriver;
+use RonasIT\Support\Tests\Support\Traits\MockTrait;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
class RemoteDriverTest extends TestCase
{
+ use MockTrait;
+
protected $tmpData;
protected $removeDriverClass;
protected $tmpDocumentationFilePath;
@@ -16,7 +19,7 @@ public function setUp(): void
parent::setUp();
$this->tmpData = $this->getJsonFixture('tmp_data');
- $this->tmpDocumentationFilePath = __DIR__ . '/storage/temp_documentation.json';
+ $this->tmpDocumentationFilePath = __DIR__ . '/../storage/temp_documentation.json';
$this->removeDriverClass = new RemoteDriver();
}
diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php
new file mode 100755
index 0000000..4b6a1d7
--- /dev/null
+++ b/tests/SwaggerServiceTest.php
@@ -0,0 +1,132 @@
+ '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);
+ }
+}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 0ad15b1..f78406e 100755
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,9 +2,12 @@
namespace RonasIT\Support\Tests;
+use Illuminate\Http\Request;
use Illuminate\Filesystem\Filesystem;
+use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase as BaseTest;
use RonasIT\Support\AutoDoc\AutoDocServiceProvider;
+use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class TestCase extends BaseTest
{
@@ -12,7 +15,7 @@ public function tearDown(): void
{
parent::tearDown();
- $this->clearDirectory(__DIR__ . '/storage', ['.gitignore']);
+ $this->clearDirectory(__DIR__ . '/../storage', ['.gitignore']);
}
protected function getPackageProviders($app): array
@@ -24,15 +27,7 @@ protected function getPackageProviders($app): array
protected function defineEnvironment($app)
{
- $app->useStoragePath(__DIR__ . '/storage');
- }
-
- protected function mockCLass($className, $methods = [])
- {
- return $this
- ->getMockBuilder($className)
- ->onlyMethods($methods)
- ->getMock();
+ $app->setBasePath(__DIR__ . '/..');
}
protected function getJsonFixture($name)
@@ -64,4 +59,30 @@ protected function clearDirectory($dirPath, $exceptPaths = [])
}
}
}
+
+ protected function generateRequest($type, $uri, $data = [], $pathParams = [], $headers = []): Request
+ {
+ $realUri = $uri;
+
+ foreach ($pathParams as $pathParam => $value) {
+ $realUri = str_replace($pathParam, $value, $uri);
+ }
+
+ $symfonyRequest = SymfonyRequest::create(
+ $this->prepareUrlForRequest($realUri),
+ strtoupper($type),
+ $data,
+ [],
+ [],
+ $this->transformHeadersToServerVars($headers)
+ );
+
+ $request = Request::createFromBase($symfonyRequest);
+
+ $request->setRouteResolver(function () use ($uri) {
+ return Route::get($uri);
+ });
+
+ return $request;
+ }
}
diff --git a/tests/fixtures/SwaggerServiceTest/example_success_roles_response.json b/tests/fixtures/SwaggerServiceTest/example_success_roles_response.json
new file mode 100644
index 0000000..e0e3a59
--- /dev/null
+++ b/tests/fixtures/SwaggerServiceTest/example_success_roles_response.json
@@ -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"
+ }
+ ]
+ }
+]
diff --git a/tests/fixtures/SwaggerServiceTest/example_success_user_response.json b/tests/fixtures/SwaggerServiceTest/example_success_user_response.json
new file mode 100644
index 0000000..0a100bb
--- /dev/null
+++ b/tests/fixtures/SwaggerServiceTest/example_success_user_response.json
@@ -0,0 +1,9 @@
+{
+ "id": 2,
+ "name": "first_client",
+ "likes_count": 23,
+ "role": {
+ "id": 2,
+ "name": "client"
+ }
+}
diff --git a/tests/fixtures/SwaggerServiceTest/tmp_data_get_user_request.json b/tests/fixtures/SwaggerServiceTest/tmp_data_get_user_request.json
new file mode 100644
index 0000000..f7726e1
--- /dev/null
+++ b/tests/fixtures/SwaggerServiceTest/tmp_data_get_user_request.json
@@ -0,0 +1,63 @@
+{
+ "swagger": "2.0",
+ "host": "localhost",
+ "basePath": "/",
+ "schemes": [],
+ "paths": {
+ "/users/{id}/assign-role/{role-id}": {
+ "get": {
+ "tags": [
+ "users"
+ ],
+ "consumes": [],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "id",
+ "description": "",
+ "required": true,
+ "type": "string"
+ },
+ {
+ "in": "path",
+ "name": "role-id",
+ "description": "",
+ "required": true,
+ "type": "string"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "example": {
+ "id": 2,
+ "name": "first_client",
+ "likes_count": 23,
+ "role": {
+ "id": 2,
+ "name": "client"
+ }
+ }
+ }
+ }
+ },
+ "security": [],
+ "description": ""
+ }
+ }
+ },
+ "definitions": {},
+ "info": {
+ "description": "This is automatically collected documentation",
+ "version": "0.0.0",
+ "title": "Name of Your Application",
+ "termsOfService": "",
+ "contact": {
+ "email": "your@email.com"
+ }
+ }
+}
diff --git a/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request.json b/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request.json
new file mode 100644
index 0000000..c8b44d8
--- /dev/null
+++ b/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request.json
@@ -0,0 +1,67 @@
+{
+ "swagger": "2.0",
+ "host": "localhost",
+ "basePath": "/",
+ "schemes": [],
+ "paths": {
+ "/users/roles": {
+ "get": {
+ "tags": [
+ "users"
+ ],
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "example": [
+ {
+ "id": 1,
+ "name": "admin",
+ "users": [
+ {
+ "id": 1,
+ "name": "admin"
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "client",
+ "users": [
+ {
+ "id": 2,
+ "name": "first_client"
+ },
+ {
+ "id": 3,
+ "name": "second_client"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ },
+ "security": [],
+ "description": ""
+ }
+ }
+ },
+ "definitions": {},
+ "info": {
+ "description": "This is automatically collected documentation",
+ "version": "0.0.0",
+ "title": "Name of Your Application",
+ "termsOfService": "",
+ "contact": {
+ "email": "your@email.com"
+ }
+ }
+}
diff --git a/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_jwt_security.json b/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_jwt_security.json
new file mode 100644
index 0000000..29ca2f1
--- /dev/null
+++ b/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_jwt_security.json
@@ -0,0 +1,72 @@
+{
+ "swagger": "2.0",
+ "host": "localhost",
+ "basePath": "/",
+ "schemes": [],
+ "paths": {
+ "/users/roles": {
+ "get": {
+ "tags": [
+ "users"
+ ],
+ "consumes": [],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "example": [
+ {
+ "id": 1,
+ "name": "admin",
+ "users": [
+ {
+ "id": 1,
+ "name": "admin"
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "client",
+ "users": [
+ {
+ "id": 2,
+ "name": "first_client"
+ },
+ {
+ "id": 3,
+ "name": "second_client"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ },
+ "security": [],
+ "description": ""
+ }
+ }
+ },
+ "definitions": {},
+ "info": {
+ "description": "This is automatically collected documentation",
+ "version": "0.0.0",
+ "title": "Name of Your Application",
+ "termsOfService": "",
+ "contact": {
+ "email": "your@email.com"
+ }
+ },
+ "securityDefinitions": {
+ "jwt": {
+ "type": "apiKey",
+ "name": "authorization",
+ "in": "header"
+ }
+ }
+}
diff --git a/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_laravel_security.json b/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_laravel_security.json
new file mode 100644
index 0000000..ac7b70d
--- /dev/null
+++ b/tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_laravel_security.json
@@ -0,0 +1,72 @@
+{
+ "swagger": "2.0",
+ "host": "localhost",
+ "basePath": "/",
+ "schemes": [],
+ "paths": {
+ "/users/roles": {
+ "get": {
+ "tags": [
+ "users"
+ ],
+ "consumes": [],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "example": [
+ {
+ "id": 1,
+ "name": "admin",
+ "users": [
+ {
+ "id": 1,
+ "name": "admin"
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "client",
+ "users": [
+ {
+ "id": 2,
+ "name": "first_client"
+ },
+ {
+ "id": 3,
+ "name": "second_client"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ },
+ "security": [],
+ "description": ""
+ }
+ }
+ },
+ "definitions": {},
+ "info": {
+ "description": "This is automatically collected documentation",
+ "version": "0.0.0",
+ "title": "Name of Your Application",
+ "termsOfService": "",
+ "contact": {
+ "email": "your@email.com"
+ }
+ },
+ "securityDefinitions": {
+ "laravel": {
+ "type": "apiKey",
+ "name": "Cookie",
+ "in": "header"
+ }
+ }
+}
diff --git a/tests/support/Traits/MockTrait.php b/tests/support/Traits/MockTrait.php
new file mode 100644
index 0000000..9d049fa
--- /dev/null
+++ b/tests/support/Traits/MockTrait.php
@@ -0,0 +1,14 @@
+getMockBuilder($className)
+ ->onlyMethods($methods)
+ ->getMock();
+ }
+}
diff --git a/tests/support/Traits/SwaggerServiceMockTrait.php b/tests/support/Traits/SwaggerServiceMockTrait.php
new file mode 100644
index 0000000..7b5ae76
--- /dev/null
+++ b/tests/support/Traits/SwaggerServiceMockTrait.php
@@ -0,0 +1,21 @@
+mockCLass(LocalDriver::class, ['saveTmpData']);
+
+ $firstCall = array_merge($expectedData, ['paths' => []]);
+
+ $driver->expects($this->exactly(2))->method('saveTmpData')->withConsecutive([$firstCall], [$expectedData]);
+
+ $this->app->instance(LocalDriver::class, $driver);
+ }
+}
From 8dc285b40bb0031e904964f5b96806e43f1f6fd3 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Mon, 19 Dec 2022 21:38:12 +0600
Subject: [PATCH 17/20] feat: increase php version requirements up to 7.3;
---
.github/workflows/laravel.yml | 2 +-
composer.json | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml
index bf6572d..43e4c29 100644
--- a/.github/workflows/laravel.yml
+++ b/.github/workflows/laravel.yml
@@ -12,7 +12,7 @@ jobs:
steps:
- uses: shivammathur/setup-php@v2
with:
- php-version: '7.1'
+ php-version: '7.3'
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
diff --git a/composer.json b/composer.json
index 56a922b..c2dcc71 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,7 @@
}
],
"require": {
- "php": ">=7.1.0",
+ "php": ">=7.3.0",
"laravel/framework": ">=5.3.0",
"phpunit/phpunit": ">=7.0|<=10.0"
},
From 8475eb3f6309d4ec774f9724dd818bb0b0783f8c Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Mon, 19 Dec 2022 21:42:04 +0600
Subject: [PATCH 18/20] feat: add traits test dir to classmap;
---
composer.json | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index c2dcc71..5440d7e 100644
--- a/composer.json
+++ b/composer.json
@@ -27,7 +27,8 @@
"autoload": {
"psr-4": {
"RonasIT\\Support\\AutoDoc\\": "src/",
- "RonasIT\\Support\\Tests\\": "tests/"
+ "RonasIT\\Support\\Tests\\": "tests/",
+ "RonasIT\\Support\\Tests\\Support\\Traits\\": "tests/support/Traits"
},
"exclude-from-classmap": [
"src/Tests/"
From 832c89a3fee5a98ae93e719599ebfb69e6db330f Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Thu, 22 Dec 2022 17:55:44 +0600
Subject: [PATCH 19/20] feat: use webdevops docker image;
---
.github/workflows/laravel.yml | 6 ++----
Dockerfile | 4 ++++
docker-compose.yml | 4 +++-
3 files changed, 9 insertions(+), 5 deletions(-)
create mode 100644 Dockerfile
diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml
index 43e4c29..3b175d4 100644
--- a/.github/workflows/laravel.yml
+++ b/.github/workflows/laravel.yml
@@ -7,18 +7,16 @@ on:
branches: ["master"]
jobs:
- tests:
+ tests-with-coverage:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
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
+ - name: Execute unit tests via PHPUnit with coverage
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- name: Upload coverage results to Coveralls
env:
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..0e5ff36
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,4 @@
+FROM webdevops/php-nginx:7.3
+RUN wget -O "/usr/local/bin/go-replace" "https://github.com/webdevops/goreplace/releases/download/1.1.2/gr-arm64-linux" \
+ && chmod +x "/usr/local/bin/go-replace" \
+ && "/usr/local/bin/go-replace" --version
diff --git a/docker-compose.yml b/docker-compose.yml
index 95e7cfc..74f4c52 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,7 +2,9 @@ version: '3'
services:
nginx:
- image: ronasit/php-nginx-dev:7.3
+ build:
+ context: ./
+ dockerfile: "Dockerfile"
working_dir: /app
ports:
- 80:80
From 94d4de8e786e510ce5ca4d573a07a238d8a25028 Mon Sep 17 00:00:00 2001
From: dpankratov
Date: Fri, 13 Jan 2023 12:37:02 +0600
Subject: [PATCH 20/20] feat: rename workflow file, depersonalize fixtures,
fixed typos;
---
...aravel.yml => run-tests-with-coverage.yml} | 2 +-
Dockerfile | 3 ++-
docker-compose.yml | 4 +---
tests/RemoteDriverTest.php | 18 +++++++-------
tests/fixtures/LocalDriverTest/tmp_data.json | 24 +++----------------
.../tmp_data_non_formatted.json | 2 +-
tests/fixtures/RemoteDriverTest/tmp_data.json | 24 +++----------------
.../tmp_data_non_formatted.json | 2 +-
.../fixtures/StorageDriverTest/tmp_data.json | 24 +++----------------
.../tmp_data_non_formatted.json | 2 +-
tests/support/Traits/MockTrait.php | 2 +-
.../Traits/SwaggerServiceMockTrait.php | 6 ++---
12 files changed, 29 insertions(+), 84 deletions(-)
rename .github/workflows/{laravel.yml => run-tests-with-coverage.yml} (96%)
diff --git a/.github/workflows/laravel.yml b/.github/workflows/run-tests-with-coverage.yml
similarity index 96%
rename from .github/workflows/laravel.yml
rename to .github/workflows/run-tests-with-coverage.yml
index 3b175d4..47cc699 100644
--- a/.github/workflows/laravel.yml
+++ b/.github/workflows/run-tests-with-coverage.yml
@@ -1,4 +1,4 @@
-name: run-tests-with-coverage
+name: Run tests with coverage
on:
push:
diff --git a/Dockerfile b/Dockerfile
index 0e5ff36..4be32fe 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,5 @@
-FROM webdevops/php-nginx:7.3
+FROM webdevops/php-nginx-dev:7.3
+
RUN wget -O "/usr/local/bin/go-replace" "https://github.com/webdevops/goreplace/releases/download/1.1.2/gr-arm64-linux" \
&& chmod +x "/usr/local/bin/go-replace" \
&& "/usr/local/bin/go-replace" --version
diff --git a/docker-compose.yml b/docker-compose.yml
index 74f4c52..b33a639 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,9 +2,7 @@ version: '3'
services:
nginx:
- build:
- context: ./
- dockerfile: "Dockerfile"
+ build: .
working_dir: /app
ports:
- 80:80
diff --git a/tests/RemoteDriverTest.php b/tests/RemoteDriverTest.php
index 57b22b0..3d000d6 100755
--- a/tests/RemoteDriverTest.php
+++ b/tests/RemoteDriverTest.php
@@ -11,7 +11,7 @@ class RemoteDriverTest extends TestCase
use MockTrait;
protected $tmpData;
- protected $removeDriverClass;
+ protected $remoteDriverClass;
protected $tmpDocumentationFilePath;
public function setUp(): void
@@ -21,12 +21,12 @@ public function setUp(): void
$this->tmpData = $this->getJsonFixture('tmp_data');
$this->tmpDocumentationFilePath = __DIR__ . '/../storage/temp_documentation.json';
- $this->removeDriverClass = new RemoteDriver();
+ $this->remoteDriverClass = new RemoteDriver();
}
public function testSaveTmpData()
{
- $this->removeDriverClass->saveTmpData($this->tmpData);
+ $this->remoteDriverClass->saveTmpData($this->tmpData);
$this->assertFileExists($this->tmpDocumentationFilePath);
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), $this->tmpDocumentationFilePath);
@@ -36,14 +36,14 @@ public function testGetTmpData()
{
file_put_contents($this->tmpDocumentationFilePath, json_encode($this->tmpData));
- $result = $this->removeDriverClass->getTmpData();
+ $result = $this->remoteDriverClass->getTmpData();
$this->assertEquals($this->tmpData, $result);
}
public function testGetTmpDataNoFile()
{
- $result = $this->removeDriverClass->getTmpData();
+ $result = $this->remoteDriverClass->getTmpData();
$this->assertNull($result);
}
@@ -53,7 +53,7 @@ public function testSaveData()
config(['auto-doc.drivers.remote.key' => 'mocked_key']);
config(['auto-doc.drivers.remote.url' => 'mocked_url']);
- $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+ $mock = $this->mockClass(RemoteDriver::class, ['makeHttpRequest']);
$mock
->expects($this->once())
@@ -75,7 +75,7 @@ public function testSaveDataWithoutTmpFile()
config(['auto-doc.drivers.remote.key' => 'mocked_key']);
config(['auto-doc.drivers.remote.url' => 'mocked_url']);
- $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+ $mock = $this->mockClass(RemoteDriver::class, ['makeHttpRequest']);
$mock
->expects($this->once())
@@ -93,7 +93,7 @@ public function testGetDocumentation()
config(['auto-doc.drivers.remote.key' => 'mocked_key']);
config(['auto-doc.drivers.remote.url' => 'mocked_url']);
- $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+ $mock = $this->mockClass(RemoteDriver::class, ['makeHttpRequest']);
$mock
->expects($this->once())
@@ -113,7 +113,7 @@ public function testGetDocumentationNoFile()
config(['auto-doc.drivers.remote.key' => 'mocked_key']);
config(['auto-doc.drivers.remote.url' => 'mocked_url']);
- $mock = $this->mockCLass(RemoteDriver::class, ['makeHttpRequest']);
+ $mock = $this->mockClass(RemoteDriver::class, ['makeHttpRequest']);
$mock
->expects($this->once())
diff --git a/tests/fixtures/LocalDriverTest/tmp_data.json b/tests/fixtures/LocalDriverTest/tmp_data.json
index d1e7d58..4c350c0 100644
--- a/tests/fixtures/LocalDriverTest/tmp_data.json
+++ b/tests/fixtures/LocalDriverTest/tmp_data.json
@@ -31,7 +31,7 @@
"description": "Operation successfully done",
"schema": {
"example": {
- "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8",
+ "token": "some_token",
"user": {
"id": 2,
"email": "user@test.com",
@@ -39,8 +39,6 @@
"created_at": "2017-11-16 06:08:34",
"updated_at": "2018-01-01 00:00:00",
"role_id": 2,
- "clio_user_id": null,
- "images_limit": 500,
"state": "confirmed",
"reset_password_hash": null,
"failed_auth_attempts": 0,
@@ -49,7 +47,6 @@
"last_name": null,
"set_password_hash_created_at": null,
"full_name": "user",
- "settings": null,
"new_email": "new_email_test2@test.com",
"is_email_verified": true,
"role": {
@@ -58,22 +55,7 @@
"created_at": null,
"updated_at": null,
"settable": true
- },
- "services": [
- {
- "id": 1,
- "name": "500px",
- "created_at": "2017-11-16 06:08:34",
- "updated_at": "2017-11-16 06:08:34",
- "is_photo_service": true,
- "allow_not_unique_accounts": false,
- "pivot": {
- "user_id": 2,
- "service_id": 1,
- "is_token_expired": 0
- }
- }
- ]
+ }
},
"ttl": 60,
"refresh_ttl": 20160
@@ -129,7 +111,7 @@
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
- "title": "Photoclaim API",
+ "title": "Project Title",
"termsOfService": "",
"contact": {
"email": "your@email.com"
diff --git a/tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json b/tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
index 9dd48d8..3ac95f3 100644
--- a/tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
+++ b/tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
@@ -1 +1 @@
-{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"clio_user_id":null,"images_limit":500,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","settings":null,"new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true},"services":[{"id":1,"name":"500px","created_at":"2017-11-16 06:08:34","updated_at":"2017-11-16 06:08:34","is_photo_service":true,"allow_not_unique_accounts":false,"pivot":{"user_id":2,"service_id":1,"is_token_expired":0}}]},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Photoclaim API","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
+{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"some_token","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true}},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Project Title","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
diff --git a/tests/fixtures/RemoteDriverTest/tmp_data.json b/tests/fixtures/RemoteDriverTest/tmp_data.json
index d1e7d58..4c350c0 100644
--- a/tests/fixtures/RemoteDriverTest/tmp_data.json
+++ b/tests/fixtures/RemoteDriverTest/tmp_data.json
@@ -31,7 +31,7 @@
"description": "Operation successfully done",
"schema": {
"example": {
- "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8",
+ "token": "some_token",
"user": {
"id": 2,
"email": "user@test.com",
@@ -39,8 +39,6 @@
"created_at": "2017-11-16 06:08:34",
"updated_at": "2018-01-01 00:00:00",
"role_id": 2,
- "clio_user_id": null,
- "images_limit": 500,
"state": "confirmed",
"reset_password_hash": null,
"failed_auth_attempts": 0,
@@ -49,7 +47,6 @@
"last_name": null,
"set_password_hash_created_at": null,
"full_name": "user",
- "settings": null,
"new_email": "new_email_test2@test.com",
"is_email_verified": true,
"role": {
@@ -58,22 +55,7 @@
"created_at": null,
"updated_at": null,
"settable": true
- },
- "services": [
- {
- "id": 1,
- "name": "500px",
- "created_at": "2017-11-16 06:08:34",
- "updated_at": "2017-11-16 06:08:34",
- "is_photo_service": true,
- "allow_not_unique_accounts": false,
- "pivot": {
- "user_id": 2,
- "service_id": 1,
- "is_token_expired": 0
- }
- }
- ]
+ }
},
"ttl": 60,
"refresh_ttl": 20160
@@ -129,7 +111,7 @@
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
- "title": "Photoclaim API",
+ "title": "Project Title",
"termsOfService": "",
"contact": {
"email": "your@email.com"
diff --git a/tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json b/tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json
index 9dd48d8..3ac95f3 100644
--- a/tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json
+++ b/tests/fixtures/RemoteDriverTest/tmp_data_non_formatted.json
@@ -1 +1 @@
-{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"clio_user_id":null,"images_limit":500,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","settings":null,"new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true},"services":[{"id":1,"name":"500px","created_at":"2017-11-16 06:08:34","updated_at":"2017-11-16 06:08:34","is_photo_service":true,"allow_not_unique_accounts":false,"pivot":{"user_id":2,"service_id":1,"is_token_expired":0}}]},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Photoclaim API","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
+{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"some_token","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true}},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Project Title","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
diff --git a/tests/fixtures/StorageDriverTest/tmp_data.json b/tests/fixtures/StorageDriverTest/tmp_data.json
index d1e7d58..4c350c0 100644
--- a/tests/fixtures/StorageDriverTest/tmp_data.json
+++ b/tests/fixtures/StorageDriverTest/tmp_data.json
@@ -31,7 +31,7 @@
"description": "Operation successfully done",
"schema": {
"example": {
- "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8",
+ "token": "some_token",
"user": {
"id": 2,
"email": "user@test.com",
@@ -39,8 +39,6 @@
"created_at": "2017-11-16 06:08:34",
"updated_at": "2018-01-01 00:00:00",
"role_id": 2,
- "clio_user_id": null,
- "images_limit": 500,
"state": "confirmed",
"reset_password_hash": null,
"failed_auth_attempts": 0,
@@ -49,7 +47,6 @@
"last_name": null,
"set_password_hash_created_at": null,
"full_name": "user",
- "settings": null,
"new_email": "new_email_test2@test.com",
"is_email_verified": true,
"role": {
@@ -58,22 +55,7 @@
"created_at": null,
"updated_at": null,
"settable": true
- },
- "services": [
- {
- "id": 1,
- "name": "500px",
- "created_at": "2017-11-16 06:08:34",
- "updated_at": "2017-11-16 06:08:34",
- "is_photo_service": true,
- "allow_not_unique_accounts": false,
- "pivot": {
- "user_id": 2,
- "service_id": 1,
- "is_token_expired": 0
- }
- }
- ]
+ }
},
"ttl": 60,
"refresh_ttl": 20160
@@ -129,7 +111,7 @@
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
- "title": "Photoclaim API",
+ "title": "Project Title",
"termsOfService": "",
"contact": {
"email": "your@email.com"
diff --git a/tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json b/tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json
index 9dd48d8..3ac95f3 100644
--- a/tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json
+++ b/tests/fixtures/StorageDriverTest/tmp_data_non_formatted.json
@@ -1 +1 @@
-{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"clio_user_id":null,"images_limit":500,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","settings":null,"new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true},"services":[{"id":1,"name":"500px","created_at":"2017-11-16 06:08:34","updated_at":"2017-11-16 06:08:34","is_photo_service":true,"allow_not_unique_accounts":false,"pivot":{"user_id":2,"service_id":1,"is_token_expired":0}}]},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Photoclaim API","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
+{"swagger":"2.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[{"in":"body","name":"body","description":"","required":true,"schema":{"$ref":"#\/definitions\/authloginObject"}}],"responses":{"200":{"description":"Operation successfully done","schema":{"example":{"token":"some_token","user":{"id":2,"email":"user@test.com","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","new_email":"new_email_test2@test.com","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true}},"ttl":60,"refresh_ttl":20160}}},"401":{"description":"Unauthorized","schema":{"example":{"error":"You have entered an incorrect credentials."}}},"400":{"description":"Bad Request","schema":{"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}},"security":[],"description":"","summary":"login"}}},"definitions":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"admin@test.com","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Project Title","termsOfService":"","contact":{"email":"your@email.com"}}}
\ No newline at end of file
diff --git a/tests/support/Traits/MockTrait.php b/tests/support/Traits/MockTrait.php
index 9d049fa..5d06368 100644
--- a/tests/support/Traits/MockTrait.php
+++ b/tests/support/Traits/MockTrait.php
@@ -4,7 +4,7 @@
trait MockTrait
{
- protected function mockCLass($className, $methods = [])
+ protected function mockClass($className, $methods = [])
{
return $this
->getMockBuilder($className)
diff --git a/tests/support/Traits/SwaggerServiceMockTrait.php b/tests/support/Traits/SwaggerServiceMockTrait.php
index 7b5ae76..8ec68bf 100644
--- a/tests/support/Traits/SwaggerServiceMockTrait.php
+++ b/tests/support/Traits/SwaggerServiceMockTrait.php
@@ -8,14 +8,14 @@ trait SwaggerServiceMockTrait
{
use MockTrait;
- protected function mockDriverSaveTmpData($expectedData)
+ protected function mockDriverSaveTmpData($expectedData, $driverClass = LocalDriver::class)
{
- $driver = $this->mockCLass(LocalDriver::class, ['saveTmpData']);
+ $driver = $this->mockClass($driverClass, ['saveTmpData']);
$firstCall = array_merge($expectedData, ['paths' => []]);
$driver->expects($this->exactly(2))->method('saveTmpData')->withConsecutive([$firstCall], [$expectedData]);
- $this->app->instance(LocalDriver::class, $driver);
+ $this->app->instance($driverClass, $driver);
}
}