Skip to content

Commit

Permalink
Merge pull request #1475 from hafezdivandari/master-bump-phpunit
Browse files Browse the repository at this point in the history
Bump PHPUnit and PHPStan
  • Loading branch information
Sephster authored Feb 27, 2025
2 parents 0032301 + a669aae commit b8df2b3
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 82 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6.21",
"phpunit/phpunit": "^10.5|^11.5|^12.0",
"laminas/laminas-diactoros": "^3.5",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-phpunit": "^1.3.15",
"phpstan/phpstan": "^1.12|^2.0",
"phpstan/phpstan-phpunit": "^1.3.15|^2.0",
"roave/security-advisories": "dev-master",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-strict-rules": "^1.5.2",
"phpstan/phpstan-deprecation-rules": "^1.1.4|^2.0",
"phpstan/phpstan-strict-rules": "^1.5.2|^2.0",
"slevomat/coding-standard": "^8.14.1",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"squizlabs/php_codesniffer": "^3.8"
Expand Down
15 changes: 8 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
failOnRisky="true"
failOnWarning="true"
stopOnError="true"
stopOnFailure="true"
stopOnIncomplete="false"
stopOnSkipped="false"
bootstrap="tests/Bootstrap.php"
>
<coverage includeUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</coverage>
</source>

<testsuites>
<testsuite name="Tests">
<directory>./tests/</directory>
Expand Down
1 change: 1 addition & 0 deletions src/AuthorizationValidators/BearerTokenValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private function initJwtConfiguration(): void
throw new RuntimeException('Public key is empty');
}

// TODO: next major release: replace deprecated method and remove phpstan ignored error
$this->jwtConfiguration->setValidationConstraints(
new LooseValidAt($clock, $this->jwtValidAtDateLeeway),
new SignedWith(
Expand Down
6 changes: 5 additions & 1 deletion src/Grant/AuthCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ private function validateCodeChallenge(object $authCodePayload, ?string $codeVer
if (isset($this->codeChallengeVerifiers[$authCodePayload->code_challenge_method])) {
$codeChallengeVerifier = $this->codeChallengeVerifiers[$authCodePayload->code_challenge_method];

if (!isset($authCodePayload->code_challenge) || $codeChallengeVerifier->verifyCodeChallenge($codeVerifier, $authCodePayload->code_challenge) === false) {
if (
!property_exists($authCodePayload, 'code_challenge') ||
!isset($authCodePayload->code_challenge) ||
$codeChallengeVerifier->verifyCodeChallenge($codeVerifier, $authCodePayload->code_challenge) === false
) {
throw OAuthServerException::invalidGrant('Failed to verify `code_verifier`.');
}
} else {
Expand Down
13 changes: 0 additions & 13 deletions tests/Bootstrap.php

This file was deleted.

4 changes: 3 additions & 1 deletion tests/Exception/OAuthServerExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ private function issueInvalidClientException(ServerRequestInterface $serverReque
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
$clientRepositoryMock->method('validateClient')->willReturn(false);

$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
$grantMock = $this->getMockBuilder(AbstractGrant::class)
->onlyMethods(['getIdentifier', 'respondToAccessTokenRequest'])
->getMock();
$grantMock->setClientRepository($clientRepositoryMock);

$abstractGrantReflection = new ReflectionClass($grantMock);
Expand Down
135 changes: 84 additions & 51 deletions tests/Grant/AbstractGrantTest.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/Grant/DeviceCodeGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function testRespondToAccessTokenRequest(): void
$deviceCodeEntity->setClient($client);
$deviceCodeEntity->addScope($scope);

$deviceCodeRepositoryMock->method('getDeviceCodeEntityByDeviceCode')
$deviceCodeRepositoryMock->expects(self::atLeast(1))->method('getDeviceCodeEntityByDeviceCode')
->with($deviceCodeEntity->getIdentifier())
->willReturn($deviceCodeEntity);

Expand All @@ -356,7 +356,7 @@ public function testRespondToAccessTokenRequest(): void
$accessTokenEntity->addScope($scope);

$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$accessTokenRepositoryMock->method('getNewToken')
$accessTokenRepositoryMock->expects(self::once())->method('getNewToken')
->with($client, $deviceCodeEntity->getScopes(), $deviceCodeEntity->getUserIdentifier())
->willReturn($accessTokenEntity);
$accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf();
Expand Down
3 changes: 2 additions & 1 deletion tests/Grant/RefreshTokenGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ public function testRespondToRequestFinalizeScopes(): void
$accessToken = new AccessTokenEntity();
$accessToken->setClient($client);
$accessTokenRepositoryMock
->expects(self::once())
->method('getNewToken')
->with($client, $finalizedScopes)
->willReturn($accessToken);
Expand Down Expand Up @@ -674,7 +675,7 @@ public function testRevokedRefreshToken(): void

$refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock();
$refreshTokenRepositoryMock->method('isRefreshTokenRevoked')
->will(self::onConsecutiveCalls(false, true));
->willReturn(false, true);
$refreshTokenRepositoryMock->expects(self::once())->method('revokeRefreshToken')->with(self::equalTo($refreshTokenId));

$oldRefreshToken = json_encode(
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/AbstractGrantExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
{
return TypeCombinator::union(...[
new StringType(),
isset($methodCall->getArgs[2]) ? $scope->getType($methodCall->getArgs[2]->value) : new NullType(),
property_exists($methodCall, 'getArgs') && isset($methodCall->getArgs[2]) ? $scope->getType($methodCall->getArgs[2]->value) : new NullType(),
]);
}
}
2 changes: 2 additions & 0 deletions tests/Stubs/ScopeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

use League\OAuth2\Server\Entities\ScopeEntityInterface;
use League\OAuth2\Server\Entities\Traits\EntityTrait;
use League\OAuth2\Server\Entities\Traits\ScopeTrait;
use ReturnTypeWillChange;

class ScopeEntity implements ScopeEntityInterface
{
use EntityTrait;
use ScopeTrait;

#[ReturnTypeWillChange]
public function jsonSerialize(): string
Expand Down

0 comments on commit b8df2b3

Please sign in to comment.