Skip to content

Commit

Permalink
feat: remove app, implement local driver test cases;
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTray committed Dec 14, 2022
1 parent 844631a commit 8d9b839
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 39 deletions.
27 changes: 0 additions & 27 deletions bootstrap/app.php

This file was deleted.

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
4 changes: 1 addition & 3 deletions src/AutoDocServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
50 changes: 50 additions & 0 deletions tests/LocalDriverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace RonasIT\Support\Tests;

use RonasIT\Support\AutoDoc\Drivers\LocalDriver;

class LocalDriverTest extends TestCase
{
protected $tmpData;
protected $localDriverClass;
protected $productionFilePath;

public function setUp(): void
{
parent::setUp();

$this->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);
}
}
32 changes: 23 additions & 9 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}
138 changes: 138 additions & 0 deletions tests/fixtures/LocalDriverTest/tmp_data.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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": "[email protected]",
"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": "[email protected]",
"password": "123"
}
}
},
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
"title": "Photoclaim API",
"termsOfService": "",
"contact": {
"email": "[email protected]"
}
}
}
1 change: 1 addition & 0 deletions tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
Original file line number Diff line number Diff line change
@@ -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":"[email protected]","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":"[email protected]","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":"[email protected]","password":"123"}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Photoclaim API","termsOfService":"","contact":{"email":"[email protected]"}}}
2 changes: 2 additions & 0 deletions tests/storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 8d9b839

Please sign in to comment.