Skip to content

Commit

Permalink
Merge pull request #32 from KentarouTakeda/add-support-for-laravel-11
Browse files Browse the repository at this point in the history
Add support for laravel 11
  • Loading branch information
KentarouTakeda authored Feb 5, 2024
2 parents e522617 + a2f7ace commit 6c80b31
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/package-installation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ jobs:
laravel:
- "^9.0"
- "^10.0"
# TODO This tag will be revised after official release
- "^11.x-dev"
include:
- option: --ignore-platform-req=php
php: "8.4"
exclude:
- php: "8.1"
laravel: "^11.x-dev"

name: PHP:${{ matrix.php }} / Laravel:${{ matrix.laravel }}

Expand Down
23 changes: 20 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
laravel:
- "^9.0"
- "^10.0"
- "^11.0"
stability:
- lowest
- stable
Expand All @@ -31,6 +32,13 @@ jobs:
stability: stable
- option: --ignore-platform-req=php
php: "8.4"
- unstable: 1
laravel: "^11.0"
exclude:
- laravel: "^11.0"
php: "8.1"
- laravel: "^11.0"
stability: lowest

name: PHP:${{ matrix.php }} / Laravel:${{ matrix.laravel }} / ${{ matrix.stability }}

Expand All @@ -46,9 +54,18 @@ jobs:
coverage: none

- name: Install Composer dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update --ansi
composer update --prefer-${{ matrix.stability }} ${{ matrix.option }} --no-interaction --no-progress --ansi
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update --ansi

- name: Set minimum stability
if: ${{ matrix.unstable }}
run: composer config minimum-stability dev --ansi

- name: Uninstall the package that is not compatible with Laravel 11
if: ${{ matrix.unstable }}
run: composer remove --dev vyuldashev/laravel-openapi --no-interaction --no-update

- name: Install Composer dependencies
run: composer update --prefer-${{ matrix.stability }} ${{ matrix.option }} --no-interaction --no-progress --ansi

- name: Run Code Format Check
if: ${{ matrix.current }}
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"license": "MIT",
"type": "library",
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"KentarouTakeda\\Laravel\\OpenApiValidator\\": "src/"
}
Expand Down Expand Up @@ -79,5 +82,6 @@
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi"
}
},
"prefer-stable": true
}
4 changes: 3 additions & 1 deletion src/SchemaRepository/L5SwaggerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use KentarouTakeda\Laravel\OpenApiValidator\ResolverInterface;
use L5Swagger\GeneratorFactory;

use function KentarouTakeda\Laravel\OpenApiValidator\isl5SwaggerInstalled;

class L5SwaggerResolver implements ResolverInterface
{
private readonly GeneratorFactory $generatorFactory;
Expand All @@ -18,7 +20,7 @@ public function __construct(
private readonly Repository $repository,
private readonly Filesystem $filesystem,
) {
if (!class_exists(GeneratorFactory::class)) {
if (!isl5SwaggerInstalled()) {
throw new LackOfDependenciesException('L5Swagger is not installed.', class: GeneratorFactory::class);
}

Expand Down
4 changes: 3 additions & 1 deletion src/SchemaRepository/LaravelOpenApiResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
use KentarouTakeda\Laravel\OpenApiValidator\ResolverInterface;
use Vyuldashev\LaravelOpenApi\Generator;

use function KentarouTakeda\Laravel\OpenApiValidator\isLaravelOpenAPIInstalled;

class LaravelOpenApiResolver implements ResolverInterface
{
private readonly Generator $generator;

public function __construct(
) {
if (!class_exists(Generator::class)) {
if (!isLaravelOpenAPIInstalled()) {
throw new LackOfDependenciesException('Laravel OpenAPI is not installed.', class: Generator::class);
}

Expand Down
3 changes: 1 addition & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace KentarouTakeda\Laravel\OpenApiValidator;

use Composer\InstalledVersions;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use KentarouTakeda\Laravel\OpenApiValidator\Config\Config;
Expand Down Expand Up @@ -44,7 +43,7 @@ public function boot(
]);
}

if (InstalledVersions::isInstalled('swagger-api/swagger-ui') && $config->getIsSwaggerUiEnabled()) {
if (isSwaggerUIInstalled() && $config->getIsSwaggerUiEnabled()) {
$this->loadRoutesFrom(__DIR__.'/../routes/swagger-ui.php');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'openapi-validator');
}
Expand Down
22 changes: 22 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace KentarouTakeda\Laravel\OpenApiValidator;

use Composer\InstalledVersions;

function isSwaggerUIInstalled(): bool
{
return InstalledVersions::isInstalled('swagger-api/swagger-ui');
}

function isLaravelOpenAPIInstalled(): bool
{
return InstalledVersions::isInstalled('vyuldashev/laravel-openapi');
}

function isl5SwaggerInstalled(): bool
{
return InstalledVersions::isInstalled('darkaonline/l5-swagger');
}
16 changes: 16 additions & 0 deletions tests/Feature/Http/Controllers/DocumentControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Config\Repository;
use KentarouTakeda\Laravel\OpenApiValidator\Tests\Feature\TestCase;

use function KentarouTakeda\Laravel\OpenApiValidator\isLaravelOpenAPIInstalled;
use function KentarouTakeda\Laravel\OpenApiValidator\isSwaggerUIInstalled;

class DocumentControllerTest extends TestCase
{
protected function defineEnvironment($app)
Expand All @@ -16,6 +19,15 @@ protected function defineEnvironment($app)
));
}

public static function setUpBeforeClass(): void
{
if (!isSwaggerUIInstalled()) {
self::markTestSkipped('Swagger UI is not installed.');
}

parent::setUpBeforeClass();
}

/**
* @test
*/
Expand All @@ -30,6 +42,10 @@ public function indexShouldRedirectToDefaultProvider(): void
*/
public function viewShouldReturnDocument(): void
{
if (!isLaravelOpenAPIInstalled()) {
$this->markTestSkipped('Laravel OpenAPI is not installed.');
}

$this->get(route('openapi-validator.document.laravel-openapi'))
->assertOk()
->assertViewIs('openapi-validator::documents')
Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/SchemaRepository/L5SwaggerResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
use OpenApi\Attributes\Response;
use OpenApi\Attributes\Schema;

use function KentarouTakeda\Laravel\OpenApiValidator\isl5SwaggerInstalled;

class L5SwaggerResolverTest extends TestCase
{
use TestWithTemporaryFilesTrait;

private L5SwaggerResolver $l5SwaggerResolver;

public static function setUpBeforeClass(): void
{
if (!isl5SwaggerInstalled()) {
self::markTestSkipped('L5Swagger is not installed.');
}

parent::setUpBeforeClass();
}

public function setUp(): void
{
parent::setUp();
Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/SchemaRepository/LaravelOpenApiResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
use Vyuldashev\LaravelOpenApi\Attributes\Operation;
use Vyuldashev\LaravelOpenApi\Attributes\PathItem;

use function KentarouTakeda\Laravel\OpenApiValidator\isLaravelOpenAPIInstalled;

class LaravelOpenApiResolverTest extends TestCase
{
private LaravelOpenApiResolver $laravelOpenApiResolver;

public static function setUpBeforeClass(): void
{
if (!isLaravelOpenAPIInstalled()) {
self::markTestSkipped('Laravel OpenAPI is not installed.');
}

parent::setUpBeforeClass();
}

public function setUp(): void
{
parent::setUp();
Expand Down
17 changes: 14 additions & 3 deletions tests/Feature/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@
use Orchestra\Testbench\TestCase as BaseTestCase;
use Vyuldashev\LaravelOpenApi\OpenApiServiceProvider;

use function KentarouTakeda\Laravel\OpenApiValidator\isl5SwaggerInstalled;
use function KentarouTakeda\Laravel\OpenApiValidator\isLaravelOpenAPIInstalled;

class TestCase extends BaseTestCase
{
protected function getPackageProviders($app)
{
return [
L5SwaggerServiceProvider::class,
OpenApiServiceProvider::class,
$providers = [
ServiceProvider::class,
];

if (isl5SwaggerInstalled()) {
$providers[] = L5SwaggerServiceProvider::class;
}

if (isLaravelOpenAPIInstalled()) {
$providers[] = OpenApiServiceProvider::class;
}

return $providers;
}
}

0 comments on commit 6c80b31

Please # to comment.