Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the implementation of the old UserProviderInterface method #3085

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions src/Security/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
Expand Down Expand Up @@ -48,24 +47,6 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface
return $user;
}

/**
* @param string $username
*/
public function loadUserByUsername($username): SecurityUserInterface
{
$user = $this->findUser($username);

if (!$user) {
if (class_exists(UserNotFoundException::class)) {
throw new UserNotFoundException(sprintf('Username "%s" does not exist.', $username));
}

throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
}

return $user;
}

public function refreshUser(SecurityUserInterface $user): SecurityUserInterface
{
if (!$user instanceof UserInterface) {
Expand All @@ -77,11 +58,7 @@ public function refreshUser(SecurityUserInterface $user): SecurityUserInterface
}

if (null === $reloadedUser = $this->userManager->findUserBy(['id' => $user->getId()])) {
if (class_exists(UserNotFoundException::class)) {
throw new UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId()));
}

throw new UsernameNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId()));
throw new UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId()));
}

return $reloadedUser;
Expand Down
17 changes: 4 additions & 13 deletions tests/Security/EmailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;

class EmailProviderTest extends TestCase
Expand Down Expand Up @@ -45,23 +44,19 @@ public function testLoadUserByUsername()
->with('foobar')
->will($this->returnValue($user));

$this->assertSame($user, $this->userProvider->loadUserByUsername('foobar'));
$this->assertSame($user, $this->userProvider->loadUserByIdentifier('foobar'));
}

public function testLoadUserByInvalidUsername()
{
if (class_exists(UserNotFoundException::class)) {
$this->expectException(UserNotFoundException::class);
} else {
$this->expectException(UsernameNotFoundException::class);
}
$this->expectException(UserNotFoundException::class);

$this->userManager->expects($this->once())
->method('findUserByEmail')
->with('foobar')
->will($this->returnValue(null));

$this->userProvider->loadUserByUsername('foobar');
$this->userProvider->loadUserByIdentifier('foobar');
}

public function testRefreshUserBy()
Expand Down Expand Up @@ -89,11 +84,7 @@ public function testRefreshUserBy()

public function testRefreshDeleted()
{
if (class_exists(UserNotFoundException::class)) {
$this->expectException(UserNotFoundException::class);
} else {
$this->expectException(UsernameNotFoundException::class);
}
$this->expectException(UserNotFoundException::class);

$user = $this->getMockForAbstractClass('FOS\UserBundle\Model\User');
$this->userManager->expects($this->once())
Expand Down
11 changes: 3 additions & 8 deletions tests/Security/EmailUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;

class EmailUserProviderTest extends TestCase
Expand Down Expand Up @@ -45,23 +44,19 @@ public function testLoadUserByUsername()
->with('foobar')
->will($this->returnValue($user));

$this->assertSame($user, $this->userProvider->loadUserByUsername('foobar'));
$this->assertSame($user, $this->userProvider->loadUserByIdentifier('foobar'));
}

public function testLoadUserByInvalidUsername()
{
if (class_exists(UserNotFoundException::class)) {
$this->expectException(UserNotFoundException::class);
} else {
$this->expectException(UsernameNotFoundException::class);
}
$this->expectException(UserNotFoundException::class);

$this->userManager->expects($this->once())
->method('findUserByUsernameOrEmail')
->with('foobar')
->will($this->returnValue(null));

$this->userProvider->loadUserByUsername('foobar');
$this->userProvider->loadUserByIdentifier('foobar');
}

public function testRefreshUserBy()
Expand Down
17 changes: 4 additions & 13 deletions tests/Security/UserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;

class UserProviderTest extends TestCase
Expand Down Expand Up @@ -45,23 +44,19 @@ public function testLoadUserByUsername()
->with('foobar')
->will($this->returnValue($user));

$this->assertSame($user, $this->userProvider->loadUserByUsername('foobar'));
$this->assertSame($user, $this->userProvider->loadUserByIdentifier('foobar'));
}

public function testLoadUserByInvalidUsername()
{
if (class_exists(UserNotFoundException::class)) {
$this->expectException(UserNotFoundException::class);
} else {
$this->expectException(UsernameNotFoundException::class);
}
$this->expectException(UserNotFoundException::class);

$this->userManager->expects($this->once())
->method('findUserByUsername')
->with('foobar')
->will($this->returnValue(null));

$this->userProvider->loadUserByUsername('foobar');
$this->userProvider->loadUserByIdentifier('foobar');
}

public function testRefreshUserBy()
Expand Down Expand Up @@ -89,11 +84,7 @@ public function testRefreshUserBy()

public function testRefreshDeleted()
{
if (class_exists(UserNotFoundException::class)) {
$this->expectException(UserNotFoundException::class);
} else {
$this->expectException(UsernameNotFoundException::class);
}
$this->expectException(UserNotFoundException::class);

$user = $this->getMockForAbstractClass('FOS\UserBundle\Model\User');
$this->userManager->expects($this->once())
Expand Down
Loading