Skip to content

Commit 559a7a5

Browse files
Merge branch '6.4' into 7.3
* 6.4: [Validator] Update Romanian translations fix tests [String][Inflector] Fix edge cases [Security] Fix attribute-based chained user providers [Intl] Fix Intl::getIcuStubVersion()
2 parents 4465a3b + af1b894 commit 559a7a5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Tests/User/ChainUserProviderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1616
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
17+
use Symfony\Component\Security\Core\User\AttributesBasedUserProviderInterface;
1718
use Symfony\Component\Security\Core\User\ChainUserProvider;
1819
use Symfony\Component\Security\Core\User\InMemoryUser;
1920
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
2021
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
2122
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
2223
use Symfony\Component\Security\Core\User\UserInterface;
24+
use Symfony\Component\Security\Core\User\UserProviderInterface;
2325

2426
class ChainUserProviderTest extends TestCase
2527
{
@@ -45,6 +47,28 @@ public function testLoadUserByIdentifier()
4547
$this->assertSame($account, $provider->loadUserByIdentifier('foo'));
4648
}
4749

50+
public function testLoadUserByIdentifierWithAttributes()
51+
{
52+
$provider1 = $this->createMock(UserProviderInterface::class);
53+
$provider1
54+
->expects($this->once())
55+
->method('loadUserByIdentifier')
56+
->with($this->equalTo('foo'))
57+
->willThrowException(new UserNotFoundException('not found'))
58+
;
59+
60+
$provider2 = $this->createMock(AttributesBasedUserProviderInterface::class);
61+
$provider2
62+
->expects($this->once())
63+
->method('loadUserByIdentifier')
64+
->with($this->equalTo('foo'), $this->equalTo(['attr' => 5]))
65+
->willReturn($account = $this->createMock(UserInterface::class))
66+
;
67+
68+
$provider = new ChainUserProvider([$provider1, $provider2]);
69+
$this->assertSame($account, $provider->loadUserByIdentifier('foo', ['attr' => 5]));
70+
}
71+
4872
public function testLoadUserByIdentifierThrowsUserNotFoundException()
4973
{
5074
$provider1 = $this->createMock(InMemoryUserProvider::class);

User/ChainUserProvider.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,18 @@ public function getProviders(): array
4646
return $this->providers;
4747
}
4848

49-
public function loadUserByIdentifier(string $identifier): UserInterface
49+
/**
50+
* @param array $attributes
51+
*/
52+
public function loadUserByIdentifier(string $identifier/* , array $attributes = [] */): UserInterface
5053
{
54+
$attributes = \func_num_args() > 1 ? func_get_arg(1) : [];
5155
foreach ($this->providers as $provider) {
5256
try {
57+
if ($provider instanceof AttributesBasedUserProviderInterface) {
58+
return $provider->loadUserByIdentifier($identifier, $attributes);
59+
}
60+
5361
return $provider->loadUserByIdentifier($identifier);
5462
} catch (UserNotFoundException) {
5563
// try next one

0 commit comments

Comments
 (0)