Skip to content

Commit

Permalink
chore: Use self:: instead of static:: inside tests.
Browse files Browse the repository at this point in the history
This was a change from php-cs-fixer.
  • Loading branch information
shulard committed Jun 12, 2024
1 parent c667c29 commit f1efe0f
Show file tree
Hide file tree
Showing 26 changed files with 251 additions and 251 deletions.
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

0 comments on commit f1efe0f

Please sign in to comment.