Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3:
  [Yaml] Throw on unquoted exclamation mark
  Use supportsClass where possible
  • Loading branch information
nicolas-grekas committed Jan 21, 2020
2 parents 81d760b + b22f9e7 commit b2c02d5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
61 changes: 58 additions & 3 deletions Tests/User/ChainUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,62 @@ public function testRefreshUser()
$provider1 = $this->getProvider();
$provider1
->expects($this->once())
->method('refreshUser')
->willThrowException(new UnsupportedUserException('unsupported'))
->method('supportsClass')
->willReturn(false)
;

$provider2 = $this->getProvider();
$provider2
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider2
->expects($this->once())
->method('refreshUser')
->willThrowException(new UnsupportedUserException('unsupported'))
;

$provider3 = $this->getProvider();
$provider3
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider3
->expects($this->once())
->method('refreshUser')
->willReturn($account = $this->getAccount())
;

$provider = new ChainUserProvider([$provider1, $provider2]);
$provider = new ChainUserProvider([$provider1, $provider2, $provider3]);
$this->assertSame($account, $provider->refreshUser($this->getAccount()));
}

public function testRefreshUserAgain()
{
$provider1 = $this->getProvider();
$provider1
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider1
->expects($this->once())
->method('refreshUser')
->willThrowException(new UsernameNotFoundException('not found'))
;

$provider2 = $this->getProvider();
$provider2
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider2
->expects($this->once())
->method('refreshUser')
Expand All @@ -109,13 +140,25 @@ public function testRefreshUserThrowsUnsupportedUserException()
{
$this->expectException('Symfony\Component\Security\Core\Exception\UnsupportedUserException');
$provider1 = $this->getProvider();
$provider1
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider1
->expects($this->once())
->method('refreshUser')
->willThrowException(new UnsupportedUserException('unsupported'))
;

$provider2 = $this->getProvider();
$provider2
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider2
->expects($this->once())
->method('refreshUser')
Expand Down Expand Up @@ -173,13 +216,25 @@ public function testSupportsClassWhenNotSupported()
public function testAcceptsTraversable()
{
$provider1 = $this->getProvider();
$provider1
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider1
->expects($this->once())
->method('refreshUser')
->willThrowException(new UnsupportedUserException('unsupported'))
;

$provider2 = $this->getProvider();
$provider2
->expects($this->once())
->method('supportsClass')
->willReturn(true)
;

$provider2
->expects($this->once())
->method('refreshUser')
Expand Down
4 changes: 4 additions & 0 deletions User/ChainUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public function refreshUser(UserInterface $user)

foreach ($this->providers as $provider) {
try {
if (!$provider->supportsClass(\get_class($user))) {
continue;
}

return $provider->refreshUser($user);
} catch (UnsupportedUserException $e) {
// try next one
Expand Down

0 comments on commit b2c02d5

Please sign in to comment.