Skip to content

Commit

Permalink
Merge pull request #6 from tyamahori/feature/php-8.2
Browse files Browse the repository at this point in the history
fix ${var} string
  • Loading branch information
zerodahero authored Nov 15, 2022
2 parents 83bbb02 + 09e73d6 commit 7fd3d99
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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 }}

Expand Down
6 changes: 3 additions & 3 deletions src/ValidatesOpenApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}

Expand Down Expand Up @@ -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)) . '/';
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ValidatesReponsesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ValidatesRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions tests/ValidatorBuildAndSetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
*/
Expand Down Expand Up @@ -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)' => [
Expand Down

0 comments on commit 7fd3d99

Please sign in to comment.