Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to devizzent/cebe-php-openapi. #28

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phploc" version="^4.0" installed="4.0.1" location="./tools/phploc" copy="true"/>
<phar name="composer" version="^2.0.3" installed="2.4.2" location="./tools/composer" copy="true"/>
<phar name="composer" version="^2.0.3" installed="2.7.7" location="./tools/composer" copy="true"/>
</phive>
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
],
"require": {
"php": "^8.1.0",
"league/openapi-psr7-validator": "^0.17|^0.18",
"cebe/php-openapi": "^1.7",
"league/openapi-psr7-validator": "0.*",
"devizzent/cebe-php-openapi": "^1.0",
"psr/http-message": "^1.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testItCanBeBuilt(): void
{
$exception = new InvalidOpenApiDefinitionException(new Exception());

static::assertInstanceOf(InvalidArgumentException::class, $exception);
static::assertStringContainsString('The given OpenApi definition can\'t be loaded', $exception->getMessage());
self::assertInstanceOf(InvalidArgumentException::class, $exception);
self::assertStringContainsString('The given OpenApi definition can\'t be loaded', $exception->getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testItDoesntMapUnknownException(): void
)
);

static::assertNull(
self::assertNull(
(new ValidationExceptionMapper())->map($exceptionChain)
);
}
Expand All @@ -53,9 +53,9 @@ public function testItMapsSchemaMismatchException(): void

$mapped = (new ValidationExceptionMapper())->map($exceptionChain);

static::assertInstanceOf(DataSchemaException::class, $mapped);
static::assertSame('a.b', $mapped->path);
static::assertSame($error, $mapped->getPrevious());
self::assertInstanceOf(DataSchemaException::class, $mapped);
self::assertSame('a.b', $mapped->path);
self::assertSame($error, $mapped->getPrevious());
}

public function testItMapsInvalidSchema(): void
Expand All @@ -72,8 +72,8 @@ public function testItMapsInvalidSchema(): void

$mapped = (new ValidationExceptionMapper())->map($exceptionChain);

static::assertInstanceOf(ApiSchemaException::class, $mapped);
static::assertSame($error, $mapped->getPrevious());
self::assertInstanceOf(ApiSchemaException::class, $mapped);
self::assertSame($error, $mapped->getPrevious());
}

public function testItMapsValidationFailed(): void
Expand All @@ -90,7 +90,7 @@ public function testItMapsValidationFailed(): void

$mapped = (new ValidationExceptionMapper())->map($exceptionChain);

static::assertInstanceOf(GenericException::class, $mapped);
self::assertInstanceOf(GenericException::class, $mapped);
}

public function testItMapsInvalidQueryArgs(): void
Expand All @@ -113,7 +113,7 @@ public function testItMapsInvalidQueryArgs(): void

$mapped = (new ValidationExceptionMapper())->map($exceptionChain);

static::assertInstanceOf(GenericException::class, $mapped);
static::assertSame($invalidQueryArgsError, $mapped->getPrevious());
self::assertInstanceOf(GenericException::class, $mapped);
self::assertSame($invalidQueryArgsError, $mapped->getPrevious());
}
}
24 changes: 12 additions & 12 deletions tests/unit/Bridge/LeagueOpenAPIValidation/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ public function testItCanBuildValidators(): void
{
$leagueBuilder = $this->createMock(ValidatorBuilder::class);
$leagueBuilder
->expects(static::once())
->expects(self::once())
->method('getRequestValidator')
->willReturn($this->createMock(PSR7RequestValidator::class));
$leagueBuilder
->expects(static::once())
->expects(self::once())
->method('getResponseValidator')
->willReturn($this->createMock(PSR7ResponseValidator::class));

$factory = new Factory($leagueBuilder);

static::assertInstanceOf(RequestValidator::class, $factory->getRequestValidator());
static::assertInstanceOf(ResponseValidator::class, $factory->getResponseValidator());
self::assertInstanceOf(RequestValidator::class, $factory->getRequestValidator());
self::assertInstanceOf(ResponseValidator::class, $factory->getResponseValidator());
}

public function testItCaptureErrorsDuringRequestValidatorCreation(): void
Expand All @@ -41,7 +41,7 @@ public function testItCaptureErrorsDuringRequestValidatorCreation(): void

$leagueBuilder = $this->createMock(ValidatorBuilder::class);
$leagueBuilder
->expects(static::once())
->expects(self::once())
->method('getRequestValidator')
->willThrowException(new Exception('Anything happened there…'));

Expand All @@ -54,7 +54,7 @@ public function testItCaptureErrorsDuringResponseValidatorCreation(): void

$leagueBuilder = $this->createMock(ValidatorBuilder::class);
$leagueBuilder
->expects(static::once())
->expects(self::once())
->method('getResponseValidator')
->willThrowException(new Exception('Anything happened there…'));

Expand All @@ -71,14 +71,14 @@ public function testItCanBeBuiltFromYamlFile(): void
YAML);

if ($writeSuccess === false) {
static::markTestSkipped('Temp file wasn\'t written.');
self::markTestSkipped('Temp file wasn\'t written.');
return;
}

$factory = Factory::fromYamlFile($file);

static::assertInstanceOf(RequestValidator::class, $factory->getRequestValidator());
static::assertInstanceOf(ResponseValidator::class, $factory->getResponseValidator());
self::assertInstanceOf(RequestValidator::class, $factory->getRequestValidator());
self::assertInstanceOf(ResponseValidator::class, $factory->getResponseValidator());
}

public function testItCanBeBuiltFromJsonFile(): void
Expand All @@ -94,14 +94,14 @@ public function testItCanBeBuiltFromJsonFile(): void
JSON);

if ($writeSuccess === false) {
static::markTestSkipped('Temp file wasn\'t written.');
self::markTestSkipped('Temp file wasn\'t written.');
return;
}

$factory = Factory::fromJsonFile($file);

static::assertInstanceOf(RequestValidator::class, $factory->getRequestValidator());
static::assertInstanceOf(ResponseValidator::class, $factory->getResponseValidator());
self::assertInstanceOf(RequestValidator::class, $factory->getRequestValidator());
self::assertInstanceOf(ResponseValidator::class, $factory->getResponseValidator());
}

public function testItCantBeBuiltFromInexistantJsonFile(): void
Expand Down
142 changes: 71 additions & 71 deletions tests/unit/Bridge/LeagueOpenAPIValidation/RequestValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,77 +30,77 @@ public function testItCanBeBuilt(): void
new ValidationExceptionMapper()
);

static::assertInstanceOf(RequestValidatorInterface::class, $validator);
self::assertInstanceOf(RequestValidatorInterface::class, $validator);
}

public function testItCanValidateRequest(): void
{
$requestValidator = $this->createMock(PSR7RequestValidator::class);
$request = $this->createMock(RequestInterface::class);

$requestValidator
->expects(static::once())
->method('validate')
->with($request);

(new RequestValidator(
$requestValidator,
new ValidationExceptionMapper()
))->validate($request);
}

public function testItCallsExceptionMapperOnThrowable(): void
{
$this->expectException(ApiSchemaException::class);

$requestValidator = $this->createMock(PSR7RequestValidator::class);
$validationMapper = $this->createMock(ValidationExceptionMapper::class);
$request = $this->createMock(RequestInterface::class);

$error = new Exception('Error');

$requestValidator
->expects(static::once())
->method('validate')
->with($request)
->willThrowException($error);

$validationMapper
->expects(static::once())
->method('map')
->with($error)
->willReturn(new ApiSchemaException($error));

(new RequestValidator($requestValidator, $validationMapper))->validate($request);
}

/**
* @dataProvider giveExceptions
*/
public function testItCanCatchExceptions(Throwable $error, string $exception): void
{
$this->expectException($exception);

$requestValidator = $this->createMock(PSR7RequestValidator::class);
$request = $this->createMock(RequestInterface::class);

$requestValidator
->expects(static::once())
->method('validate')
->with($request)
->willThrowException($error);

(new RequestValidator(
$requestValidator,
new ValidationExceptionMapper()
))->validate($request);
}

public function giveExceptions(): \Generator
{
yield [new NoOperation('Message'), OperationNotFoundException::class];
yield [new NoPath('Message'), OperationNotFoundException::class];
yield [new MultipleOperationsMismatchForRequest('Message'), OperationNotFoundException::class];
yield [new RuntimeException('Message'), RuntimeException::class];
}
public function testItCanValidateRequest(): void
{
$requestValidator = $this->createMock(PSR7RequestValidator::class);
$request = $this->createMock(RequestInterface::class);

$requestValidator
->expects(self::once())
->method('validate')
->with($request);

(new RequestValidator(
$requestValidator,
new ValidationExceptionMapper()
))->validate($request);
}

public function testItCallsExceptionMapperOnThrowable(): void
{
$this->expectException(ApiSchemaException::class);

$requestValidator = $this->createMock(PSR7RequestValidator::class);
$validationMapper = $this->createMock(ValidationExceptionMapper::class);
$request = $this->createMock(RequestInterface::class);

$error = new Exception('Error');

$requestValidator
->expects(self::once())
->method('validate')
->with($request)
->willThrowException($error);

$validationMapper
->expects(self::once())
->method('map')
->with($error)
->willReturn(new ApiSchemaException($error));

(new RequestValidator($requestValidator, $validationMapper))->validate($request);
}

/**
* @dataProvider provideItCanCatchExceptionsCases
*/
public function testItCanCatchExceptions(Throwable $error, string $exception): void
{
$this->expectException($exception);

$requestValidator = $this->createMock(PSR7RequestValidator::class);
$request = $this->createMock(RequestInterface::class);

$requestValidator
->expects(self::once())
->method('validate')
->with($request)
->willThrowException($error);

(new RequestValidator(
$requestValidator,
new ValidationExceptionMapper()
))->validate($request);
}

public static function provideItCanCatchExceptionsCases(): iterable
{
yield [new NoOperation('Message'), OperationNotFoundException::class];
yield [new NoPath('Message'), OperationNotFoundException::class];
yield [new MultipleOperationsMismatchForRequest('Message'), OperationNotFoundException::class];
yield [new RuntimeException('Message'), RuntimeException::class];
}
}
Loading
Loading