Skip to content

Commit 407b9fc

Browse files
committed
Fix tests
1 parent 269f1e2 commit 407b9fc

19 files changed

+105
-61
lines changed

.github/workflows/unit-tests.yml

+9-17
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,17 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
#Stable supported versions
18-
php: ['8.1', '8.2']
19-
symfony: ['5.4.*', '6.2.*']
20-
composer-flags: ['--prefer-stable']
21-
can-fail: [false]
22-
exclude:
23-
- php: '8.1'
24-
symfony: '6.2.*'
2517
include:
26-
# Lowest supported versions
27-
- php: '8.1'
28-
symfony: '5.4.*'
29-
composer-flags: '--prefer-stable --prefer-lowest'
18+
# Lowest Deps
19+
- php: 8.1
20+
symfony: 5.4.*
21+
composer-flags: '--prefer-stable'
22+
can-fail: false
23+
# Stable deps
24+
- php: 8.2
25+
symfony: 6.3.*
26+
composer-flags: '--prefer-stable'
3027
can-fail: false
31-
# Development versions
32-
- php: '8.3'
33-
symfony: '6.3.x-dev'
34-
composer-flags: ''
35-
can-fail: true
3628

3729
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
3830

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For implementation into Symfony projects, please see [bundle documentation](basi
1212

1313
## Requirements
1414

15-
* [PHP 7.2](http://php.net/releases/7_2_0.php) or greater
15+
* [PHP 8.1](http://php.net/releases/8_1_0.php) or greater
1616
* [Symfony 5.4](https://symfony.com/roadmap/5.4) or greater
1717

1818
## Installation

psalm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<psalm
33
errorLevel="1"
44
strictBinaryOperands="true"
5-
phpVersion="7.2"
5+
phpVersion="8.1"
66
allowStringToStandInForClass="true"
77
rememberPropertyAssignmentsAfterCall="false"
88
checkForThrowsInGlobalScope="true"

src/Command/CreateClientCommand.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
88
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
9+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
910
use League\Bundle\OAuth2ServerBundle\ValueObject\Grant;
1011
use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri;
1112
use League\Bundle\OAuth2ServerBundle\ValueObject\Scope;
@@ -117,20 +118,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117118
return 0;
118119
}
119120

120-
private function buildClientFromInput(InputInterface $input): AbstractClient
121+
private function buildClientFromInput(InputInterface $input): ClientInterface
121122
{
122123
$name = $input->getArgument('name');
123-
124-
/** @var string $identifier */
125-
$identifier = $input->getArgument('identifier') ?? hash('md5', random_bytes(16));
126-
124+
$identifier = (string) $input->getArgument('identifier') ?: hash('md5', random_bytes(16));
127125
$isPublic = $input->getOption('public');
128126

129127
if ($isPublic && null !== $input->getArgument('secret')) {
130128
throw new \InvalidArgumentException('The client cannot have a secret and be public.');
131129
}
132130

133-
/** @var string $secret */
134131
$secret = $isPublic ? null : $input->getArgument('secret') ?? hash('sha512', random_bytes(32));
135132

136133
/** @var AbstractClient $client */

src/Converter/UserConverter.php

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class UserConverter implements UserConverterInterface
1212
{
1313
/**
1414
* @psalm-suppress DeprecatedMethod
15+
* @psalm-suppress UndefinedInterfaceMethod
1516
*/
1617
public function toLeague(?UserInterface $user): UserEntityInterface
1718
{

src/DBAL/Type/ImplodedArray.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class ImplodedArray extends TextType
2020
/**
2121
* @psalm-suppress MixedArgumentTypeCoercion
2222
*/
23-
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
23+
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
2424
{
2525
if (!\is_array($value)) {
2626
throw new \LogicException('This type can only be used in combination with arrays.');
@@ -41,7 +41,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
4141
/**
4242
* @psalm-return list<T>
4343
*/
44-
public function convertToPHPValue($value, AbstractPlatform $platform): array
44+
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): array
4545
{
4646
if (null === $value) {
4747
return [];

src/Entity/Scope.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class Scope implements ScopeEntityInterface
1212
use EntityTrait;
1313

1414
#[\ReturnTypeWillChange]
15-
public function jsonSerialize()
15+
public function jsonSerialize(): mixed
1616
{
1717
return $this->getIdentifier();
1818
}

src/Event/AuthorizationRequestResolveEvent.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Event;
66

7-
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
7+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
88
use League\Bundle\OAuth2ServerBundle\ValueObject\Scope;
99
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
1010
use Symfony\Component\HttpFoundation\Response;
@@ -27,7 +27,7 @@ final class AuthorizationRequestResolveEvent extends Event
2727
private $scopes;
2828

2929
/**
30-
* @var AbstractClient
30+
* @var ClientInterface
3131
*/
3232
private $client;
3333

@@ -49,7 +49,7 @@ final class AuthorizationRequestResolveEvent extends Event
4949
/**
5050
* @param Scope[] $scopes
5151
*/
52-
public function __construct(AuthorizationRequest $authorizationRequest, array $scopes, AbstractClient $client)
52+
public function __construct(AuthorizationRequest $authorizationRequest, array $scopes, ClientInterface $client)
5353
{
5454
$this->authorizationRequest = $authorizationRequest;
5555
$this->scopes = $scopes;
@@ -94,7 +94,7 @@ public function getGrantTypeId(): string
9494
/**
9595
* @psalm-mutation-free
9696
*/
97-
public function getClient(): AbstractClient
97+
public function getClient(): ClientInterface
9898
{
9999
return $this->client;
100100
}

src/LeagueOAuth2ServerBundle.php

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public function getContainerExtension(): ExtensionInterface
3333
return new LeagueOAuth2ServerExtension();
3434
}
3535

36+
/**
37+
* @psalm-suppress UndefinedMethod
38+
*/
3639
private function configureSecurityExtension(ContainerBuilder $container): void
3740
{
3841
/** @var SecurityExtension $extension */
@@ -61,6 +64,7 @@ private function configureDoctrineExtension(ContainerBuilder $container): void
6164
'league.oauth2_server.persistence.doctrine.enabled'
6265
)
6366
);
67+
6468
$container->addCompilerPass(new EncryptionKeyPass());
6569
}
6670
}

src/Manager/Null/AccessTokenManager.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
88
use League\Bundle\OAuth2ServerBundle\Model\AccessToken;
9+
use League\Bundle\OAuth2ServerBundle\Model\AccessTokenInterface;
910

1011
final class AccessTokenManager implements AccessTokenManagerInterface
1112
{
@@ -14,7 +15,7 @@ public function find(string $identifier): ?AccessToken
1415
return null;
1516
}
1617

17-
public function save(AccessToken $accessToken): void
18+
public function save(AccessTokenInterface $accessToken): void
1819
{
1920
}
2021

src/Model/AbstractClient.php

-5
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ public function setRedirectUris(RedirectUri ...$redirectUris): ClientInterface
114114
return $this;
115115
}
116116

117-
/**
118-
* @return list<Grant>
119-
*
120-
* @psalm-mutation-free
121-
*/
122117
public function getGrants(): array
123118
{
124119
return $this->grants;

src/Model/ClientInterface.php

+18
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,38 @@
88
use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri;
99
use League\Bundle\OAuth2ServerBundle\ValueObject\Scope;
1010

11+
/**
12+
* @method string getName()
13+
*/
1114
interface ClientInterface
1215
{
1316
public function getIdentifier(): string;
1417

1518
public function getSecret(): ?string;
1619

20+
/**
21+
* @return list<RedirectUri>
22+
*
23+
* @psalm-mutation-free
24+
*/
1725
public function getRedirectUris(): array;
1826

1927
public function setRedirectUris(RedirectUri ...$redirectUris): self;
2028

29+
/**
30+
* @return list<Grant>
31+
*
32+
* @psalm-mutation-free
33+
*/
2134
public function getGrants(): array;
2235

2336
public function setGrants(Grant ...$grants): self;
2437

38+
/**
39+
* @return list<Scope>
40+
*
41+
* @psalm-mutation-free
42+
*/
2543
public function getScopes(): array;
2644

2745
public function setScopes(Scope ...$scopes): self;

src/Repository/ClientRepository.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use League\Bundle\OAuth2ServerBundle\Entity\Client as ClientEntity;
88
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
9-
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
9+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
1010
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
1111

1212
final class ClientRepository implements ClientRepositoryInterface
@@ -55,7 +55,7 @@ public function validateClient($clientIdentifier, $clientSecret, $grantType): bo
5555
return false;
5656
}
5757

58-
private function buildClientEntity(AbstractClient $client): ClientEntity
58+
private function buildClientEntity(ClientInterface $client): ClientEntity
5959
{
6060
$clientEntity = new ClientEntity();
6161
$clientEntity->setName($client->getName());
@@ -67,7 +67,7 @@ private function buildClientEntity(AbstractClient $client): ClientEntity
6767
return $clientEntity;
6868
}
6969

70-
private function isGrantSupported(AbstractClient $client, ?string $grant): bool
70+
private function isGrantSupported(ClientInterface $client, ?string $grant): bool
7171
{
7272
if (null === $grant) {
7373
return true;

src/Security/Authenticator/OAuth2Authenticator.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ public function doAuthenticate(Request $request) /* : Passport */
101101
/** @var string $oauthClientId */
102102
$oauthClientId = $psr7Request->getAttribute('oauth_client_id', '');
103103

104+
/** @psalm-suppress MixedInferredReturnType */
104105
$userLoader = function (string $userIdentifier): UserInterface {
105106
if ('' === $userIdentifier) {
106107
return new NullUser();
107108
}
108109
if (!method_exists($this->userProvider, 'loadUserByIdentifier')) {
109-
/** @psalm-suppress DeprecatedMethod */
110+
/**
111+
* @psalm-suppress DeprecatedMethod
112+
* @psalm-suppress MixedReturnStatement
113+
*/
110114
return $this->userProvider->loadUserByUsername($userIdentifier);
111115
}
112116

@@ -127,6 +131,9 @@ public function doAuthenticate(Request $request) /* : Passport */
127131
* @return OAuth2Token
128132
*
129133
* @psalm-suppress DeprecatedInterface
134+
* @psalm-suppress UndefinedClass
135+
* @psalm-suppress MixedInferredReturnType
136+
* @psalm-suppress RedundantCondition
130137
*/
131138
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
132139
{
@@ -135,6 +142,10 @@ public function createAuthenticatedToken(PassportInterface $passport, string $fi
135142
}
136143

137144
$token = $this->createToken($passport, $firewallName);
145+
/**
146+
* @psalm-suppress TooManyArguments
147+
* @psalm-suppress UndefinedMethod
148+
*/
138149
$token->setAuthenticated(true);
139150

140151
return $token;
@@ -157,7 +168,10 @@ public function createToken(Passport $passport, string $firewallName): TokenInte
157168
$token = new OAuth2Token($passport->getUser(), $accessTokenId, $oauthClientId, $scopeBadge->getScopes(), $this->rolePrefix);
158169
if (method_exists(AuthenticatorInterface::class, 'createAuthenticatedToken') && !method_exists(AuthenticatorInterface::class, 'createToken')) {
159170
// symfony 5.4 only
160-
/** @psalm-suppress TooManyArguments */
171+
/**
172+
* @psalm-suppress TooManyArguments
173+
* @psalm-suppress UndefinedMethod
174+
*/
161175
$token->setAuthenticated(true, false);
162176
}
163177

src/Security/EventListener/CheckScopeListener.php

-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1010
use Symfony\Component\HttpFoundation\Request;
1111
use Symfony\Component\HttpFoundation\RequestStack;
12-
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
1312
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
1413

1514
/**
@@ -29,8 +28,6 @@ public function __construct(RequestStack $requestStack)
2928
public function checkPassport(CheckPassportEvent $event): void
3029
{
3130
/**
32-
* @var Passport $passport
33-
*
3431
* @psalm-suppress DeprecatedInterface
3532
*/
3633
$passport = $event->getPassport();

src/Service/CredentialsRevoker/DoctrineCredentialsRevoker.php

+4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ public function __construct(EntityManagerInterface $entityManager, ClientManager
3333

3434
/**
3535
* @psalm-suppress DeprecatedMethod
36+
* @psalm-suppress UndefinedInterfaceMethod
3637
*/
3738
public function revokeCredentialsForUser(UserInterface $user): void
3839
{
40+
/**
41+
* @psalm-suppress MixedAssignment
42+
*/
3943
$userIdentifier = method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername();
4044

4145
$this->entityManager->createQueryBuilder()

tests/Acceptance/AbstractAcceptanceTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Tests\Acceptance;
66

7+
use Doctrine\DBAL\Platforms\SqlitePlatform;
78
use League\Bundle\OAuth2ServerBundle\Tests\TestHelper;
89
use Symfony\Bundle\FrameworkBundle\Console\Application;
910
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
@@ -30,7 +31,7 @@ protected function setUp(): void
3031
TestHelper::initializeDoctrineSchema($this->application);
3132

3233
$connection = $this->client->getContainer()->get('database_connection');
33-
if ('sqlite' === $connection->getDatabasePlatform()->getName()) {
34+
if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {
3435
// https://www.sqlite.org/foreignkeys.html
3536
$connection->executeQuery('PRAGMA foreign_keys = ON');
3637
}

tests/Fixtures/User.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getUserIdentifier(): string
3333
return FixtureFactory::FIXTURE_USER;
3434
}
3535

36-
public function eraseCredentials()
36+
public function eraseCredentials(): void
3737
{
3838
}
3939
}

0 commit comments

Comments
 (0)