Skip to content

Commit b00e0ac

Browse files
committed
tests: storage driver class test cases;
1 parent f9c29cc commit b00e0ac

File tree

4 files changed

+204
-1
lines changed

4 files changed

+204
-1
lines changed

src/Drivers/StorageDriver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace RonasIT\Support\AutoDoc\Drivers;
44

5-
use stdClass;
65
use Illuminate\Support\Facades\Storage;
76
use Illuminate\Contracts\Filesystem\FileNotFoundException;
87
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface;

tests/StorageDriverTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace RonasIT\Support\Tests;
4+
5+
use Illuminate\Contracts\Filesystem\FileNotFoundException;
6+
use Illuminate\Support\Facades\Storage;
7+
use RonasIT\Support\AutoDoc\Drivers\StorageDriver;
8+
9+
class StorageDriverTest extends TestCase
10+
{
11+
protected $disk;
12+
protected $tmpData;
13+
protected $filePath;
14+
protected $storageDriverClass;
15+
16+
public function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
$this->tmpData = $this->getJsonFixture('tmp_data');
21+
$this->filePath = __DIR__ . '/storage/documentation.json';
22+
23+
config(['auto-doc.drivers.storage.disk' => 'testing']);
24+
config(['auto-doc.drivers.storage.production_path' => $this->filePath]);
25+
26+
$this->disk = Storage::fake('testing');
27+
28+
$this->storageDriverClass = new StorageDriver();
29+
}
30+
31+
public function testGetAndSaveTmpData()
32+
{
33+
$this->storageDriverClass->saveTmpData($this->tmpData);
34+
35+
$this->assertEquals($this->tmpData, $this->storageDriverClass->getTmpData());
36+
}
37+
38+
public function testSaveData()
39+
{
40+
$this->storageDriverClass->saveTmpData($this->tmpData);
41+
42+
$this->storageDriverClass->saveData();
43+
44+
$this->disk->assertExists($this->filePath);
45+
$this->assertEquals($this->getFixture('tmp_data_non_formatted.json'), $this->disk->get($this->filePath));
46+
47+
$this->assertEquals([], $this->storageDriverClass->getTmpData());
48+
}
49+
50+
public function testGetDocumentation()
51+
{
52+
$this->disk->put($this->filePath, $this->getFixture('tmp_data_non_formatted.json'));
53+
54+
$documentation = $this->storageDriverClass->getDocumentation();
55+
56+
$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
57+
}
58+
59+
public function testGetDocumentationFileNotExists()
60+
{
61+
$this->expectException(FileNotFoundException::class);
62+
63+
$this->storageDriverClass->getDocumentation();
64+
}
65+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"swagger": "2.0",
3+
"host": "localhost",
4+
"basePath": "\/",
5+
"schemes": [],
6+
"paths": {
7+
"\/auth\/login": {
8+
"post": {
9+
"tags": [
10+
"auth"
11+
],
12+
"consumes": [
13+
"application\/json"
14+
],
15+
"produces": [
16+
"application\/json"
17+
],
18+
"parameters": [
19+
{
20+
"in": "body",
21+
"name": "body",
22+
"description": "",
23+
"required": true,
24+
"schema": {
25+
"$ref": "#\/definitions\/authloginObject"
26+
}
27+
}
28+
],
29+
"responses": {
30+
"200": {
31+
"description": "Operation successfully done",
32+
"schema": {
33+
"example": {
34+
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTE0NzY0ODAwLCJleHAiOjE1MTQ3Njg0MDAsIm5iZiI6MTUxNDc2NDgwMCwianRpIjoiM2tYM2tXQ3Z0UWdOSjBBOSIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.Trk1hpjhczDmu60vgKs1aYPl7wxWNJfNCYcW5mC0LQ8",
35+
"user": {
36+
"id": 2,
37+
"email": "[email protected]",
38+
"deleted_at": null,
39+
"created_at": "2017-11-16 06:08:34",
40+
"updated_at": "2018-01-01 00:00:00",
41+
"role_id": 2,
42+
"clio_user_id": null,
43+
"images_limit": 500,
44+
"state": "confirmed",
45+
"reset_password_hash": null,
46+
"failed_auth_attempts": 0,
47+
"last_auth_attempt": "2018-01-01 00:00:00",
48+
"first_name": "user",
49+
"last_name": null,
50+
"set_password_hash_created_at": null,
51+
"full_name": "user",
52+
"settings": null,
53+
"new_email": "[email protected]",
54+
"is_email_verified": true,
55+
"role": {
56+
"id": 2,
57+
"name": "client",
58+
"created_at": null,
59+
"updated_at": null,
60+
"settable": true
61+
},
62+
"services": [
63+
{
64+
"id": 1,
65+
"name": "500px",
66+
"created_at": "2017-11-16 06:08:34",
67+
"updated_at": "2017-11-16 06:08:34",
68+
"is_photo_service": true,
69+
"allow_not_unique_accounts": false,
70+
"pivot": {
71+
"user_id": 2,
72+
"service_id": 1,
73+
"is_token_expired": 0
74+
}
75+
}
76+
]
77+
},
78+
"ttl": 60,
79+
"refresh_ttl": 20160
80+
}
81+
}
82+
},
83+
"401": {
84+
"description": "Unauthorized",
85+
"schema": {
86+
"example": {
87+
"error": "You have entered an incorrect credentials."
88+
}
89+
}
90+
},
91+
"400": {
92+
"description": "Bad Request",
93+
"schema": {
94+
"example": {
95+
"error": "The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."
96+
}
97+
}
98+
}
99+
},
100+
"security": [],
101+
"description": "",
102+
"summary": "login"
103+
}
104+
}
105+
},
106+
"definitions": {
107+
"authloginObject": {
108+
"type": "object",
109+
"properties": {
110+
"email": {
111+
"type": "string",
112+
"description": "2"
113+
},
114+
"password": {
115+
"type": "string",
116+
"description": ""
117+
}
118+
},
119+
"required": [
120+
"email",
121+
"password"
122+
],
123+
"example": {
124+
"email": "[email protected]",
125+
"password": "123"
126+
}
127+
}
128+
},
129+
"info": {
130+
"description": "This is automatically collected documentation",
131+
"version": "0.0.0",
132+
"title": "Photoclaim API",
133+
"termsOfService": "",
134+
"contact": {
135+
"email": "[email protected]"
136+
}
137+
}
138+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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":"[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]"}}}

0 commit comments

Comments
 (0)