-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
408 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Membrane\OpenAPIReader\Tests\ValueObject\Valid\V30; | ||
|
||
use Membrane\OpenAPIReader\Exception\InvalidOpenAPI; | ||
use Membrane\OpenAPIReader\Tests\Fixtures\ProvidesInvalidatedSchemas; | ||
use Membrane\OpenAPIReader\Tests\Fixtures\ProvidesReviewedSchemas; | ||
use Membrane\OpenAPIReader\Tests\Fixtures\ProvidesSimplifiedSchemas; | ||
use Membrane\OpenAPIReader\ValueObject\Partial; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Enum\Type; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Identifier; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\V30\Keywords; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\V30\Schema; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Validated; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Warning; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Warnings; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProviderExternal; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\Attributes\TestDox; | ||
use PHPUnit\Framework\Attributes\UsesClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(Schema::class)] | ||
#[CoversClass(Partial\Schema::class)] // DTO | ||
#[CoversClass(InvalidOpenAPI::class)] | ||
#[UsesClass(Type::class)] | ||
#[UsesClass(Identifier::class)] | ||
#[UsesClass(Validated::class)] | ||
#[UsesClass(Warning::class)] | ||
#[UsesClass(Warnings::class)] | ||
class KeywordsTest extends TestCase | ||
{ | ||
#[Test] | ||
#[TestDox('It reviews schema keywords for recoverable issues')] | ||
#[DataProviderExternal(ProvidesReviewedSchemas::class, 'forV3X')] | ||
public function itReviewsKeywords(Partial\Schema $schema, Warning $warning): void | ||
{ | ||
$identifier = new Identifier('sut'); | ||
$sut = new Keywords($identifier, new Warnings($identifier), $schema); | ||
|
||
self::assertContainsEquals($warning, $sut->getWarnings()->all()); | ||
} | ||
|
||
#[Test] | ||
#[TestDox('It simplifies schema keywords where possible')] | ||
#[DataProviderExternal(ProvidesSimplifiedSchemas::class, 'forV3X')] | ||
#[DataProviderExternal(ProvidesSimplifiedSchemas::class, 'forV30')] | ||
public function itSimplifiesKeywords( | ||
Partial\Schema $schema, | ||
string $propertyName, | ||
mixed $expected, | ||
): void { | ||
$identifier = new Identifier('sut'); | ||
$sut = new Keywords($identifier, new Warnings($identifier), $schema); | ||
|
||
self::assertEquals($expected, $sut->{$propertyName}); | ||
} | ||
|
||
#[Test] | ||
#[TestDox('It invalidates schema keywords for non-recoverable issues')] | ||
#[DataProviderExternal(ProvidesInvalidatedSchemas::class, 'forV3X')] | ||
#[DataProviderExternal(ProvidesInvalidatedSchemas::class, 'forV30')] | ||
public function itInvalidatesKeywords( | ||
InvalidOpenAPI $expected, | ||
Identifier $identifier, | ||
Partial\Schema $schema, | ||
): void { | ||
$warnings = new Warnings($identifier); | ||
|
||
self::expectExceptionObject($expected); | ||
|
||
new Keywords($identifier, $warnings, $schema); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Membrane\OpenAPIReader\Tests\ValueObject\Valid\V31; | ||
|
||
use Membrane\OpenAPIReader\Exception\InvalidOpenAPI; | ||
use Membrane\OpenAPIReader\Tests\Fixtures\ProvidesInvalidatedSchemas; | ||
use Membrane\OpenAPIReader\Tests\Fixtures\ProvidesReviewedSchemas; | ||
use Membrane\OpenAPIReader\Tests\Fixtures\ProvidesSimplifiedSchemas; | ||
use Membrane\OpenAPIReader\ValueObject\Partial; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Enum\Type; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Identifier; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\V31\Keywords; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\V31\Schema; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Validated; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Warning; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Warnings; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProviderExternal; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\Attributes\TestDox; | ||
use PHPUnit\Framework\Attributes\UsesClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(Schema::class)] | ||
#[CoversClass(Partial\Schema::class)] // DTO | ||
#[CoversClass(InvalidOpenAPI::class)] | ||
#[UsesClass(Type::class)] | ||
#[UsesClass(Identifier::class)] | ||
#[UsesClass(Validated::class)] | ||
#[UsesClass(Warning::class)] | ||
#[UsesClass(Warnings::class)] | ||
class KeywordsTest extends TestCase | ||
{ | ||
#[Test] | ||
#[TestDox('It reviews schema keywords for recoverable issues')] | ||
#[DataProviderExternal(ProvidesReviewedSchemas::class, 'forV3X')] | ||
public function itReviewsKeywords(Partial\Schema $schema, Warning $warning): void | ||
{ | ||
$identifier = new Identifier('sut'); | ||
$sut = new Keywords($identifier, new Warnings($identifier), $schema); | ||
|
||
self::assertContainsEquals($warning, $sut->getWarnings()->all()); | ||
} | ||
|
||
#[Test] | ||
#[TestDox('It simplifies schema keywords where possible')] | ||
#[DataProviderExternal(ProvidesSimplifiedSchemas::class, 'forV3X')] | ||
#[DataProviderExternal(ProvidesSimplifiedSchemas::class, 'forV31')] | ||
public function itSimplifiesKeywords( | ||
Partial\Schema $schema, | ||
string $propertyName, | ||
mixed $expected, | ||
): void { | ||
$identifier = new Identifier('sut'); | ||
$sut = new Keywords($identifier, new Warnings($identifier), $schema); | ||
|
||
self::assertEquals($expected, $sut->{$propertyName}); | ||
} | ||
|
||
#[Test] | ||
#[TestDox('It invalidates schema keywords for non-recoverable issues')] | ||
#[DataProviderExternal(ProvidesInvalidatedSchemas::class, 'forV3X')] | ||
#[DataProviderExternal(ProvidesInvalidatedSchemas::class, 'forV31')] | ||
public function itInvalidatesKeywords( | ||
InvalidOpenAPI $expected, | ||
Identifier $identifier, | ||
Partial\Schema $schema, | ||
): void { | ||
$warnings = new Warnings($identifier); | ||
|
||
self::expectExceptionObject($expected); | ||
|
||
new Keywords($identifier, $warnings, $schema); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
|
||
namespace Membrane\OpenAPIReader\Tests\Fixtures; | ||
|
||
use Generator; | ||
use Membrane\OpenAPIReader\Exception\InvalidOpenAPI; | ||
use Membrane\OpenAPIReader\ValueObject\Partial; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Identifier; | ||
use Membrane\OpenAPIReader\ValueObject\Valid\Warning; | ||
use Membrane\OpenAPIReader\ValueObject\Value; | ||
|
||
final class ProvidesInvalidatedSchemas | ||
{ | ||
/** | ||
* @return Generator<array{ | ||
* 0:InvalidOpenAPI, | ||
* 1:Identifier, | ||
* 2:Partial\Schema, | ||
* }> | ||
*/ | ||
public static function forV3X(): Generator | ||
{ | ||
$identifier = new Identifier('sut'); | ||
|
||
yield 'invalid type' => [ | ||
InvalidOpenAPI::invalidType($identifier, 'invalid'), | ||
$identifier, | ||
new Partial\Schema(type: 'invalid'), | ||
]; | ||
|
||
yield 'properties without string keys' => [ | ||
InvalidOpenAPI::mustHaveStringKeys($identifier, 'properties'), | ||
$identifier, | ||
new Partial\Schema(properties: [new Partial\Schema()]), | ||
]; | ||
|
||
yield 'negative maxLength' => [ | ||
InvalidOpenAPI::keywordMustBeNonNegativeInteger($identifier, 'maxLength'), | ||
$identifier, | ||
new Partial\Schema(maxLength: -1), | ||
]; | ||
|
||
yield 'negative maxItems' => [ | ||
InvalidOpenAPI::keywordMustBeNonNegativeInteger($identifier, 'maxItems'), | ||
$identifier, | ||
new Partial\Schema(maxItems: -1), | ||
]; | ||
|
||
yield 'negative maxProperties' => [ | ||
InvalidOpenAPI::keywordMustBeNonNegativeInteger($identifier, 'maxProperties'), | ||
$identifier, | ||
new Partial\Schema(maxProperties: -1), | ||
]; | ||
|
||
yield 'zero multipleOf' => [ | ||
InvalidOpenAPI::keywordCannotBeZero($identifier, 'multipleOf'), | ||
$identifier, | ||
new Partial\Schema(multipleOf: 0), | ||
]; | ||
|
||
yield 'default does not conform to type' => [ | ||
InvalidOpenAPI::defaultMustConformToType($identifier), | ||
$identifier, | ||
new Partial\Schema(type: 'string', default: new Value(1)), | ||
]; | ||
} | ||
|
||
/** | ||
* @return Generator<array{ | ||
* 0:InvalidOpenAPI, | ||
* 1:Identifier, | ||
* 2:Partial\Schema, | ||
* }> | ||
*/ | ||
public static function forV30(): Generator | ||
{ | ||
$identifier = new Identifier('sut'); | ||
|
||
yield 'numeric exclusiveMaximum' => [ | ||
InvalidOpenAPI::numericExclusiveMinMaxIn30($identifier, 'exclusiveMaximum'), | ||
$identifier, | ||
new Partial\Schema(exclusiveMaximum: 5), | ||
]; | ||
|
||
yield 'numeric exclusiveMinimum' => [ | ||
InvalidOpenAPI::numericExclusiveMinMaxIn30($identifier, 'exclusiveMinimum'), | ||
$identifier, | ||
new Partial\Schema(exclusiveMinimum: 5), | ||
]; | ||
} | ||
|
||
/** | ||
* @return Generator<array{ | ||
* 0:InvalidOpenAPI, | ||
* 1:Identifier, | ||
* 2:Partial\Schema, | ||
* }> | ||
*/ | ||
public static function forV31(): Generator | ||
{ | ||
$identifier = new Identifier('sut'); | ||
|
||
yield 'numeric exclusiveMaximum' => [ | ||
InvalidOpenAPI::boolExclusiveMinMaxIn31($identifier, 'exclusiveMaximum'), | ||
$identifier, | ||
new Partial\Schema(exclusiveMaximum: true), | ||
]; | ||
|
||
yield 'numeric exclusiveMinimum' => [ | ||
InvalidOpenAPI::boolExclusiveMinMaxIn31($identifier, 'exclusiveMinimum'), | ||
$identifier, | ||
new Partial\Schema(exclusiveMinimum: true), | ||
]; | ||
} | ||
} |
Oops, something went wrong.