-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tests] Reduced code duplication in custom providers test cases
- Loading branch information
Showing
3 changed files
with
88 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,8 @@ | |
|
||
namespace Ibexa\Tests\Core\MVC\Symfony\Security\User; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\User\User as APIUser; | ||
use Ibexa\Core\Base\Exceptions\NotFoundException; | ||
use Ibexa\Core\MVC\Symfony\Security\User\BaseProvider; | ||
use Ibexa\Core\MVC\Symfony\Security\User\EmailProvider; | ||
use Ibexa\Core\MVC\Symfony\Security\UserInterface; | ||
use Ibexa\Core\Repository\Values\User\UserReference; | ||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; | ||
use Symfony\Component\Security\Core\Exception\UserNotFoundException; | ||
use Symfony\Component\Security\Core\Exception\UserNotFoundException; | ||
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface; | ||
|
||
/** | ||
* @covers \Ibexa\Core\MVC\Symfony\Security\User\EmailProvider | ||
|
@@ -29,76 +21,13 @@ protected function buildProvider(): BaseProvider | |
return new EmailProvider($this->userService, $this->permissionResolver); | ||
} | ||
|
||
public function testLoadUserByUsernameUserNotFound(): void | ||
protected function getUserIdentifier(): string | ||
{ | ||
$username = '[email protected]'; | ||
$this->userService | ||
->expects(self::once()) | ||
->method('loadUserByEmail') | ||
->with($username) | ||
->willThrowException(new NotFoundException('user', $username)); | ||
|
||
$this->expectException(UserNotFoundException::class); | ||
$this->userProvider->loadUserByIdentifier($username); | ||
} | ||
|
||
public function testLoadUserByUsername(): void | ||
{ | ||
$username = '[email protected]'; | ||
$apiUser = $this->createMock(APIUser::class); | ||
|
||
$this->userService | ||
->expects(self::once()) | ||
->method('loadUserByEmail') | ||
->with($username) | ||
->willReturn($apiUser); | ||
|
||
$user = $this->userProvider->loadUserByIdentifier($username); | ||
self::assertInstanceOf(UserInterface::class, $user); | ||
self::assertSame($apiUser, $user->getAPIUser()); | ||
self::assertSame(['ROLE_USER'], $user->getRoles()); | ||
} | ||
|
||
public function testRefreshUserNotSupported(): void | ||
{ | ||
$user = $this->createMock(SymfonyUserInterface::class); | ||
|
||
$this->expectException(UnsupportedUserException::class); | ||
$this->userProvider->refreshUser($user); | ||
return '[email protected]'; | ||
} | ||
|
||
public function testRefreshUser(): void | ||
protected function getUserServiceMethod(): string | ||
{ | ||
$userId = 123; | ||
$apiUser = $this->buildUserValueObjectStub($userId); | ||
$user = $this->createUserWrapperMockFromAPIUser($apiUser, $userId); | ||
|
||
$this->permissionResolver | ||
->expects(self::once()) | ||
->method('setCurrentUserReference') | ||
->with(new UserReference($apiUser->getUserId())); | ||
|
||
self::assertSame($user, $this->userProvider->refreshUser($user)); | ||
} | ||
|
||
public function testRefreshUserNotFound(): void | ||
{ | ||
$this->expectException(UserNotFoundException::class); | ||
|
||
$userId = 123; | ||
$apiUser = $this->buildUserValueObjectStub($userId); | ||
$user = $this->createMock(UserInterface::class); | ||
$user | ||
->expects(self::once()) | ||
->method('getAPIUser') | ||
->willReturn($apiUser); | ||
|
||
$this->userService | ||
->expects(self::once()) | ||
->method('loadUser') | ||
->with($userId) | ||
->willThrowException(new NotFoundException('user', 'foo')); | ||
|
||
$this->userProvider->refreshUser($user); | ||
return 'loadUserByEmail'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters