Skip to content

Commit 13ac1d2

Browse files
Merge branch '4.4' into 5.0
* 4.4: [Yaml] Throw on unquoted exclamation mark Use supportsClass where possible
2 parents 48fe320 + b2c02d5 commit 13ac1d2

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

Tests/User/ChainUserProviderTest.php

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,62 @@ public function testRefreshUser()
7070
$provider1 = $this->getProvider();
7171
$provider1
7272
->expects($this->once())
73-
->method('refreshUser')
74-
->willThrowException(new UnsupportedUserException('unsupported'))
73+
->method('supportsClass')
74+
->willReturn(false)
7575
;
7676

7777
$provider2 = $this->getProvider();
78+
$provider2
79+
->expects($this->once())
80+
->method('supportsClass')
81+
->willReturn(true)
82+
;
83+
7884
$provider2
85+
->expects($this->once())
86+
->method('refreshUser')
87+
->willThrowException(new UnsupportedUserException('unsupported'))
88+
;
89+
90+
$provider3 = $this->getProvider();
91+
$provider3
92+
->expects($this->once())
93+
->method('supportsClass')
94+
->willReturn(true)
95+
;
96+
97+
$provider3
7998
->expects($this->once())
8099
->method('refreshUser')
81100
->willReturn($account = $this->getAccount())
82101
;
83102

84-
$provider = new ChainUserProvider([$provider1, $provider2]);
103+
$provider = new ChainUserProvider([$provider1, $provider2, $provider3]);
85104
$this->assertSame($account, $provider->refreshUser($this->getAccount()));
86105
}
87106

88107
public function testRefreshUserAgain()
89108
{
90109
$provider1 = $this->getProvider();
110+
$provider1
111+
->expects($this->once())
112+
->method('supportsClass')
113+
->willReturn(true)
114+
;
115+
91116
$provider1
92117
->expects($this->once())
93118
->method('refreshUser')
94119
->willThrowException(new UsernameNotFoundException('not found'))
95120
;
96121

97122
$provider2 = $this->getProvider();
123+
$provider2
124+
->expects($this->once())
125+
->method('supportsClass')
126+
->willReturn(true)
127+
;
128+
98129
$provider2
99130
->expects($this->once())
100131
->method('refreshUser')
@@ -109,13 +140,25 @@ public function testRefreshUserThrowsUnsupportedUserException()
109140
{
110141
$this->expectException('Symfony\Component\Security\Core\Exception\UnsupportedUserException');
111142
$provider1 = $this->getProvider();
143+
$provider1
144+
->expects($this->once())
145+
->method('supportsClass')
146+
->willReturn(true)
147+
;
148+
112149
$provider1
113150
->expects($this->once())
114151
->method('refreshUser')
115152
->willThrowException(new UnsupportedUserException('unsupported'))
116153
;
117154

118155
$provider2 = $this->getProvider();
156+
$provider2
157+
->expects($this->once())
158+
->method('supportsClass')
159+
->willReturn(true)
160+
;
161+
119162
$provider2
120163
->expects($this->once())
121164
->method('refreshUser')
@@ -173,13 +216,25 @@ public function testSupportsClassWhenNotSupported()
173216
public function testAcceptsTraversable()
174217
{
175218
$provider1 = $this->getProvider();
219+
$provider1
220+
->expects($this->once())
221+
->method('supportsClass')
222+
->willReturn(true)
223+
;
224+
176225
$provider1
177226
->expects($this->once())
178227
->method('refreshUser')
179228
->willThrowException(new UnsupportedUserException('unsupported'))
180229
;
181230

182231
$provider2 = $this->getProvider();
232+
$provider2
233+
->expects($this->once())
234+
->method('supportsClass')
235+
->willReturn(true)
236+
;
237+
183238
$provider2
184239
->expects($this->once())
185240
->method('refreshUser')

User/ChainUserProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function refreshUser(UserInterface $user)
7373

7474
foreach ($this->providers as $provider) {
7575
try {
76+
if (!$provider->supportsClass(\get_class($user))) {
77+
continue;
78+
}
79+
7680
return $provider->refreshUser($user);
7781
} catch (UnsupportedUserException $e) {
7882
// try next one

0 commit comments

Comments
 (0)