Skip to content

Commit ff5b0dc

Browse files
committed
Fix issue if user ID is a Ulid
Remove dep Change ID dep
1 parent a3ebcd8 commit ff5b0dc

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Changelog
22
=========
3+
## 2.5.1
4+
* Bugfix: Prevent error in `EntityUserProvider::refreshUser` when `$userId` is a `Ulid`
5+
36
## 2.5.0 (2026-02-19)
47
* Added: PHP 8.5 test coverage,
58
* Added: Support for Symfony 8.0,

src/Security/Core/User/EntityUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function refreshUser(UserInterface $user): UserInterface
9494
$username = $user->getUserIdentifier();
9595

9696
if (null === $user = $this->findUser([$identifier => $userId])) {
97-
throw $this->createUserNotFoundException($username, \sprintf('User with ID "%d" could not be reloaded.', $userId));
97+
throw $this->createUserNotFoundException($username, \sprintf('User with ID "%s" could not be reloaded.', $userId));
9898
}
9999

100100
return $user;

tests/Fixtures/StringIDUser.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the HWIOAuthBundle package.
5+
*
6+
* (c) Hardware Info <opensource@hardware.info>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace HWI\Bundle\OAuthBundle\Tests\Fixtures;
13+
14+
use Deprecated;
15+
use Symfony\Component\Security\Core\User\UserInterface;
16+
17+
final class StringIDUser implements UserInterface
18+
{
19+
public function getId(): string
20+
{
21+
return '6f5f78b2-005d-4eea-96c4-79044aaebb34';
22+
}
23+
24+
public function getRoles(): array
25+
{
26+
return [];
27+
}
28+
29+
public function getUserIdentifier(): string
30+
{
31+
return 'abc';
32+
}
33+
34+
#[Deprecated]
35+
public function eraseCredentials(): void
36+
{
37+
}
38+
}

tests/Security/Core/User/EntityUserProviderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* This file is part of the HWIOAuthBundle package.
57
*
@@ -15,9 +17,11 @@
1517
use Doctrine\Persistence\ManagerRegistry;
1618
use Doctrine\Persistence\ObjectManager;
1719
use Doctrine\Persistence\ObjectRepository;
20+
use ErrorException;
1821
use HWI\Bundle\OAuthBundle\OAuth\ResourceOwnerInterface;
1922
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
2023
use HWI\Bundle\OAuthBundle\Security\Core\User\EntityUserProvider;
24+
use HWI\Bundle\OAuthBundle\Tests\Fixtures\StringIDUser;
2125
use HWI\Bundle\OAuthBundle\Tests\Fixtures\User;
2226
use PHPUnit\Framework\Attributes\Group;
2327
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
@@ -184,4 +188,33 @@ private function assertUserNotFoundException(): void
184188
{
185189
$this->expectException(UserNotFoundException::class);
186190
}
191+
192+
public function testRefreshUserWorksWithUlid(): void
193+
{
194+
// Simulate `framework.php_errors.throw: true`
195+
set_error_handler(static function (
196+
int $severity,
197+
string $message,
198+
string $file,
199+
int $line
200+
): never {
201+
throw new ErrorException($message, 0, $severity, $file, $line);
202+
});
203+
204+
try {
205+
$this->assertUserNotFoundException();
206+
$this->expectExceptionMessage('User with ID "6f5f78b2-005d-4eea-96c4-79044aaebb34" could not be reloaded.');
207+
208+
$provider = new EntityUserProvider(
209+
$this->createManagerRegistryMock(),
210+
StringIDUser::class,
211+
[]
212+
);
213+
214+
$provider->refreshUser(new StringIDUser());
215+
} finally {
216+
restore_error_handler();
217+
}
218+
}
219+
187220
}

0 commit comments

Comments
 (0)