From 09e73d69d7ff63022027370b6b5c95848d4b7623 Mon Sep 17 00:00:00 2001 From: tyamahori Date: Thu, 27 Oct 2022 13:30:33 +0900 Subject: [PATCH] :green_heart: fix ${var} string --- .github/workflows/ci.yml | 7 +++++-- src/ValidatesOpenApiSpec.php | 6 +++--- tests/ValidatesReponsesTest.php | 2 +- tests/ValidatesRequestsTest.php | 2 +- tests/ValidatorBuildAndSetupTest.php | 22 ++++++++++++++++++---- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16160bc..65f59da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.4, 8.0, 8.1] + php: [7.4, 8.0, 8.1, 8.2] laravel: [6.*, 7.*, 8.*, 9.*] include: - laravel: 9.* @@ -27,7 +27,10 @@ jobs: laravel: 7.* - php: 8.1 laravel: 6.* - + - php: 8.2 + laravel: 7.* + - php: 8.2 + laravel: 6.* name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/src/ValidatesOpenApiSpec.php b/src/ValidatesOpenApiSpec.php index 3d70072..3d35b77 100644 --- a/src/ValidatesOpenApiSpec.php +++ b/src/ValidatesOpenApiSpec.php @@ -45,7 +45,7 @@ public function getOpenApiValidatorBuilder(): ValidatorBuilder } elseif ($specType === 'yaml') { $this->openApiValidatorBuilder = (new ValidatorBuilder())->fromYaml($this->getOpenApiSpec()); } else { - throw new UnknownParserForFileTypeException("Unknown parser for file type ${specType}"); + throw new UnknownParserForFileTypeException("Unknown parser for file type {$specType}"); } } @@ -153,7 +153,7 @@ protected function getResponseCodesToSkipRegex(): string $codes = $this->responseCodesToSkip ?? ['5\d\d']; return '/' . implode('|', array_map(function ($code) { - return "(${code})"; + return "({$code})"; }, $codes)) . '/'; } @@ -213,7 +213,7 @@ protected function getSpecFileType(): string $type = strtolower(Str::afterLast($this->getOpenApiSpecPath(), '.')); if (! $type || ! in_array($type, ['json', 'yaml'])) { - throw new UnknownSpecFileTypeException("Expected json or yaml type OpenAPI spec, got ${type}"); + throw new UnknownSpecFileTypeException("Expected json or yaml type OpenAPI spec, got {$type}"); } return $type; diff --git a/tests/ValidatesReponsesTest.php b/tests/ValidatesReponsesTest.php index caa7404..d70c6c8 100644 --- a/tests/ValidatesReponsesTest.php +++ b/tests/ValidatesReponsesTest.php @@ -39,7 +39,7 @@ public function testValidatesResponses(OperationAddress $address, array $respons if (is_null($expectedException)) { $this->fail('Validation failed with unexpected exception ' . get_class($exception) . PHP_EOL . $exception->getMessage()); } - $this->assertInstanceOf($expectedException, $exception, "Expected an exception of class [${expectedException}] to be thrown, got " . get_class($exception)); + $this->assertInstanceOf($expectedException, $exception, "Expected an exception of class [{$expectedException}] to be thrown, got " . get_class($exception)); $this->assertFalse($expectSuccess); // End the test here diff --git a/tests/ValidatesRequestsTest.php b/tests/ValidatesRequestsTest.php index d03bea4..403a3a6 100644 --- a/tests/ValidatesRequestsTest.php +++ b/tests/ValidatesRequestsTest.php @@ -40,7 +40,7 @@ public function testValidatesRequests(array $requestData, bool $expectSuccess, ? if (is_null($expectedException)) { $this->fail('Validation failed with unexpected exception ' . get_class($exception) . PHP_EOL . $exception->getMessage()); } - $this->assertInstanceOf($expectedException, $exception, "Expected an exception of class [${expectedException}] to be thrown, got " . get_class($exception)); + $this->assertInstanceOf($expectedException, $exception, "Expected an exception of class [{$expectedException}] to be thrown, got " . get_class($exception)); $this->assertFalse($expectSuccess); // End the test here diff --git a/tests/ValidatorBuildAndSetupTest.php b/tests/ValidatorBuildAndSetupTest.php index 0e3c30e..bcbab62 100644 --- a/tests/ValidatorBuildAndSetupTest.php +++ b/tests/ValidatorBuildAndSetupTest.php @@ -24,7 +24,7 @@ class ValidatorBuildAndSetupTest extends TestCase */ public function testGetsOpenApiValidatorBuilder(string $extension) { - $this->app['config']->set('openapi_validator.spec_path', __DIR__."/fixtures/OpenAPI.${extension}"); + $this->app['config']->set('openapi_validator.spec_path', __DIR__."/fixtures/OpenAPI.{$extension}"); $builder = $this->getOpenApiValidatorBuilder(); $this->assertInstanceOf(ValidatorBuilder::class, $builder); @@ -40,15 +40,29 @@ public function provideSpecFormats() /** * @test + * @dataProvider provideSpecUnknownFormats */ - public function testThrowsExceptionForUnknownFormat() + public function testThrowsExceptionForUnknownFormat(string $extension) { - $this->app['config']->set('openapi_validator.spec_path', __DIR__.'/fixtures/OpenAPI.banana'); + $this->app['config']->set('openapi_validator.spec_path', __DIR__ . "/fixtures/OpenAPI.{$extension}"); $this->expectException(UnknownSpecFileTypeException::class); + $this->expectErrorMessage("Expected json or yaml type OpenAPI spec, got {$extension}"); $this->getSpecFileType(); } + /** + * @return array + */ + public function provideSpecUnknownFormats(): array + { + return [ + ['banana'], + ['jsonn'], + ['yamll'], + ]; + } + /** * @test */ @@ -105,7 +119,7 @@ public function testSkipsResponseCodes($responseCode, $codesToSkip, bool $expect public function provideResponseCodes() { for ($i = 0; $i <= 8; $i++) { - yield "Skips 50${i} by default" => [500 + $i, [], true]; + yield "Skips 50{$i} by default" => [500 + $i, [], true]; } yield 'Skips other 500s by default (1)' => [