Skip to content

Commit

Permalink
Merge pull request #68 from RonasIT/dpankratov/actions-configure
Browse files Browse the repository at this point in the history
Create laravel.yml
  • Loading branch information
astorozhevsky committed Jan 13, 2023
2 parents d9ff2e2 + 94d4de8 commit 9281ec1
Show file tree
Hide file tree
Showing 45 changed files with 1,341 additions and 24 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/run-tests-with-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run tests with coverage

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
tests-with-coverage:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
- uses: actions/checkout@v3
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- 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:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/logs/clover.xml -v
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ bootstrap/cache/

# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
.rocketeer/
composer.lock
composer.lock

.phpunit.result.cache
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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
34 changes: 34 additions & 0 deletions bootstrap/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/

$compiledPath = __DIR__.'/cache/compiled.php';

if (file_exists($compiledPath)) {
require $compiledPath;
}
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
}
],
"require": {
"php": ">=7.1.0",
"php": ">=7.3.0",
"laravel/framework": ">=5.3.0",
"phpunit/phpunit": ">=7.0|<=10.0"
},
"require-dev": {
"orchestra/testbench": "^6.25",
"php-coveralls/php-coveralls": "^2.5"
},
"autoload": {
"psr-4": {
"RonasIT\\Support\\AutoDoc\\": "src/"
"RonasIT\\Support\\AutoDoc\\": "src/",
"RonasIT\\Support\\Tests\\": "tests/",
"RonasIT\\Support\\Tests\\Support\\Traits\\": "tests/support/Traits"
},
"exclude-from-classmap": [
"src/Tests/"
Expand Down
2 changes: 1 addition & 1 deletion config/auto-doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'

services:
nginx:
build: .
working_dir: /app
ports:
- 80:80
- 443:443
volumes:
- ./:/app
22 changes: 22 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="bootstrap/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./app/Http/routes.php</file>
</exclude>
</coverage>
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<a href="https://packagist.org/packages/ronasit/laravel-swagger"><img src="https://img.shields.io/packagist/l/ronasit/laravel-swagger" alt="License"></a>
</p>

[![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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions src/AutoDocServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ 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'),
__DIR__ . '/../resources/views/swagger-description.blade.php' => resource_path('views/swagger-description.blade.php'),
], 'view');

if (!$this->app->routesAreCached()) {
Expand All @@ -25,7 +23,7 @@ public function boot()
PushDocumentationCommand::class
]);

$this->loadViewsFrom(__DIR__ . '/Views', 'auto-doc');
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'auto-doc');
}

public function register()
Expand Down
1 change: 0 additions & 1 deletion src/Drivers/LocalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 31 additions & 13 deletions src/Drivers/RemoteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

Expand All @@ -67,4 +60,29 @@ protected function getUrl(): string
{
return "{$this->remoteUrl}/documentations/{$this->key}";
}

/**
* @codeCoverageIgnore
*/
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];
}
}
1 change: 0 additions & 1 deletion src/Drivers/StorageDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
72 changes: 72 additions & 0 deletions tests/LocalDriverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

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
{
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 testCreateClassConfigEmpty()
{
$this->expectException(MissedProductionFilePathException::class);

config(['auto-doc.drivers.local.production_path' => null]);

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()
{
file_put_contents($this->productionFilePath, json_encode($this->tmpData));

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

$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();
}
}
Loading

0 comments on commit 9281ec1

Please sign in to comment.