From 396d9d29a77c99dc388477eaec1c190c6abe404c Mon Sep 17 00:00:00 2001 From: Darius Matulionis Date: Wed, 28 Aug 2024 14:52:39 +0300 Subject: [PATCH] WIP --- phpunit.xml | 2 -- src/helpers.php | 4 ++-- tests/GeneratorTest.php | 4 ++++ tests/HelpersTest.php | 3 +++ tests/RoutesTest.php | 3 +++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index dc9c59c..378379b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,8 +3,6 @@ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" - requireCoverageMetadata="true" - beStrictAboutOutputDuringTests="true" stopOnFailure="false" cacheDirectory=".phpunit.cache" > diff --git a/src/helpers.php b/src/helpers.php index b574f60..424b3d3 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -14,7 +14,7 @@ */ function swagger_ui_dist_path(string $documentation, $asset = null) { - $allowed_files = [ + $allowedFiles = [ 'favicon-16x16.png', 'favicon-32x32.png', 'oauth2-redirect.html', @@ -37,7 +37,7 @@ function swagger_ui_dist_path(string $documentation, $asset = null) return realpath($path); } - if (! in_array($asset, $allowed_files)) { + if (! in_array($asset, $allowedFiles, true)) { throw new L5SwaggerException(sprintf('(%s) - this L5 Swagger asset is not allowed', $asset)); } diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 539b9f0..f67a3d5 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -5,6 +5,8 @@ use Illuminate\Http\Request; use L5Swagger\Exceptions\L5SwaggerException; use L5Swagger\Generator; +use L5Swagger\GeneratorFactory; +use L5Swagger\L5SwaggerServiceProvider; use OpenApi\Analysers\TokenAnalyser; use OpenApi\Processors\CleanUnmerged; use PHPUnit\Framework\Attributes\CoversClass; @@ -16,7 +18,9 @@ * @covers \L5Swagger\Generator */ #[TestDox('Generator')] +#[CoversClass(GeneratorFactory::class)] #[CoversClass(Generator::class)] +#[CoversClass(L5SwaggerServiceProvider::class)] class GeneratorTest extends TestCase { /** diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index 8349cf3..2343d64 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -3,6 +3,7 @@ namespace Tests; use L5Swagger\Exceptions\L5SwaggerException; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\Attributes\TestDox; @@ -10,7 +11,9 @@ * @covers L5SwaggerException */ #[TestDox('Helpers')] +#[CoversClass(L5SwaggerException::class)] #[CoversFunction('l5_swagger_asset')] +#[CoversFunction('swagger_ui_dist_path')] class HelpersTest extends TestCase { public function testAssetFunctionThrowsExceptionIfFileDoesNotExists(): void diff --git a/tests/RoutesTest.php b/tests/RoutesTest.php index fb8db8c..70ce789 100644 --- a/tests/RoutesTest.php +++ b/tests/RoutesTest.php @@ -7,6 +7,7 @@ use L5Swagger\GeneratorFactory; use L5Swagger\Http\Controllers\SwaggerAssetController; use L5Swagger\Http\Controllers\SwaggerController; +use L5Swagger\Http\Middleware\Config; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\MockObject\Exception; @@ -18,6 +19,8 @@ #[TestDox('Routes')] #[CoversClass(SwaggerController::class)] #[CoversClass(SwaggerAssetController::class)] +#[CoversClass(Config::class)] +#[CoversClass(L5SwaggerException::class)] class RoutesTest extends TestCase { public function testUserCantAccessJsonFileIfItIsNotGenerated(): void