Skip to content

Commit 165dbcf

Browse files
committedJun 25, 2024·
Remove the implementation of the old UserProviderInterface method
1 parent dc09a0c commit 165dbcf

File tree

4 files changed

+12
-58
lines changed

4 files changed

+12
-58
lines changed
 

‎src/Security/UserProvider.php

+1-24
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use FOS\UserBundle\Model\UserInterface;
1515
use FOS\UserBundle\Model\UserManagerInterface;
1616
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
17-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1817
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1918
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;
2019
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -48,24 +47,6 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface
4847
return $user;
4948
}
5049

51-
/**
52-
* @param string $username
53-
*/
54-
public function loadUserByUsername($username): SecurityUserInterface
55-
{
56-
$user = $this->findUser($username);
57-
58-
if (!$user) {
59-
if (class_exists(UserNotFoundException::class)) {
60-
throw new UserNotFoundException(sprintf('Username "%s" does not exist.', $username));
61-
}
62-
63-
throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
64-
}
65-
66-
return $user;
67-
}
68-
6950
public function refreshUser(SecurityUserInterface $user): SecurityUserInterface
7051
{
7152
if (!$user instanceof UserInterface) {
@@ -77,11 +58,7 @@ public function refreshUser(SecurityUserInterface $user): SecurityUserInterface
7758
}
7859

7960
if (null === $reloadedUser = $this->userManager->findUserBy(['id' => $user->getId()])) {
80-
if (class_exists(UserNotFoundException::class)) {
81-
throw new UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId()));
82-
}
83-
84-
throw new UsernameNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId()));
61+
throw new UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId()));
8562
}
8663

8764
return $reloadedUser;

‎tests/Security/EmailProviderTest.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
1818
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
19-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
2019
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2120

2221
class EmailProviderTest extends TestCase
@@ -45,23 +44,19 @@ public function testLoadUserByUsername()
4544
->with('foobar')
4645
->will($this->returnValue($user));
4746

48-
$this->assertSame($user, $this->userProvider->loadUserByUsername('foobar'));
47+
$this->assertSame($user, $this->userProvider->loadUserByIdentifier('foobar'));
4948
}
5049

5150
public function testLoadUserByInvalidUsername()
5251
{
53-
if (class_exists(UserNotFoundException::class)) {
54-
$this->expectException(UserNotFoundException::class);
55-
} else {
56-
$this->expectException(UsernameNotFoundException::class);
57-
}
52+
$this->expectException(UserNotFoundException::class);
5853

5954
$this->userManager->expects($this->once())
6055
->method('findUserByEmail')
6156
->with('foobar')
6257
->will($this->returnValue(null));
6358

64-
$this->userProvider->loadUserByUsername('foobar');
59+
$this->userProvider->loadUserByIdentifier('foobar');
6560
}
6661

6762
public function testRefreshUserBy()
@@ -89,11 +84,7 @@ public function testRefreshUserBy()
8984

9085
public function testRefreshDeleted()
9186
{
92-
if (class_exists(UserNotFoundException::class)) {
93-
$this->expectException(UserNotFoundException::class);
94-
} else {
95-
$this->expectException(UsernameNotFoundException::class);
96-
}
87+
$this->expectException(UserNotFoundException::class);
9788

9889
$user = $this->getMockForAbstractClass('FOS\UserBundle\Model\User');
9990
$this->userManager->expects($this->once())

‎tests/Security/EmailUserProviderTest.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
1818
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
19-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
2019
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2120

2221
class EmailUserProviderTest extends TestCase
@@ -45,23 +44,19 @@ public function testLoadUserByUsername()
4544
->with('foobar')
4645
->will($this->returnValue($user));
4746

48-
$this->assertSame($user, $this->userProvider->loadUserByUsername('foobar'));
47+
$this->assertSame($user, $this->userProvider->loadUserByIdentifier('foobar'));
4948
}
5049

5150
public function testLoadUserByInvalidUsername()
5251
{
53-
if (class_exists(UserNotFoundException::class)) {
54-
$this->expectException(UserNotFoundException::class);
55-
} else {
56-
$this->expectException(UsernameNotFoundException::class);
57-
}
52+
$this->expectException(UserNotFoundException::class);
5853

5954
$this->userManager->expects($this->once())
6055
->method('findUserByUsernameOrEmail')
6156
->with('foobar')
6257
->will($this->returnValue(null));
6358

64-
$this->userProvider->loadUserByUsername('foobar');
59+
$this->userProvider->loadUserByIdentifier('foobar');
6560
}
6661

6762
public function testRefreshUserBy()

‎tests/Security/UserProviderTest.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
1818
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
19-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
2019
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2120

2221
class UserProviderTest extends TestCase
@@ -45,23 +44,19 @@ public function testLoadUserByUsername()
4544
->with('foobar')
4645
->will($this->returnValue($user));
4746

48-
$this->assertSame($user, $this->userProvider->loadUserByUsername('foobar'));
47+
$this->assertSame($user, $this->userProvider->loadUserByIdentifier('foobar'));
4948
}
5049

5150
public function testLoadUserByInvalidUsername()
5251
{
53-
if (class_exists(UserNotFoundException::class)) {
54-
$this->expectException(UserNotFoundException::class);
55-
} else {
56-
$this->expectException(UsernameNotFoundException::class);
57-
}
52+
$this->expectException(UserNotFoundException::class);
5853

5954
$this->userManager->expects($this->once())
6055
->method('findUserByUsername')
6156
->with('foobar')
6257
->will($this->returnValue(null));
6358

64-
$this->userProvider->loadUserByUsername('foobar');
59+
$this->userProvider->loadUserByIdentifier('foobar');
6560
}
6661

6762
public function testRefreshUserBy()
@@ -89,11 +84,7 @@ public function testRefreshUserBy()
8984

9085
public function testRefreshDeleted()
9186
{
92-
if (class_exists(UserNotFoundException::class)) {
93-
$this->expectException(UserNotFoundException::class);
94-
} else {
95-
$this->expectException(UsernameNotFoundException::class);
96-
}
87+
$this->expectException(UserNotFoundException::class);
9788

9889
$user = $this->getMockForAbstractClass('FOS\UserBundle\Model\User');
9990
$this->userManager->expects($this->once())

0 commit comments

Comments
 (0)
Please sign in to comment.