-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve logged in shop user provider
- Loading branch information
1 parent
65d9b44
commit 97507e6
Showing
17 changed files
with
119 additions
and
91 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\ShopApiPlugin\Provider; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Model\ShopUserInterface; | ||
use Sylius\Component\User\Model\UserInterface; | ||
use Sylius\ShopApiPlugin\Provider\LoggedInShopUserProviderInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Core\Exception\TokenNotFoundException; | ||
|
||
final class LoggedInShopUserProviderSpec extends ObjectBehavior | ||
{ | ||
function let(TokenStorageInterface $tokenStorage): void | ||
{ | ||
$this->beConstructedWith($tokenStorage); | ||
} | ||
|
||
function it_is_reviewer_subject_provider(): void | ||
{ | ||
$this->shouldImplement(LoggedInShopUserProviderInterface::class); | ||
} | ||
|
||
function it_throws_an_error_if_there_is_no_shop_user_logged_in( | ||
TokenStorageInterface $tokenStorage, | ||
TokenInterface $token, | ||
UserInterface $anotherUser | ||
): void { | ||
$tokenStorage->getToken()->willReturn(null, $token); | ||
$token->getUser()->willReturn(null, $anotherUser); | ||
|
||
$this->shouldThrow(TokenNotFoundException::class)->during('provide'); | ||
$this->shouldThrow(TokenNotFoundException::class)->during('provide'); | ||
$this->shouldThrow(TokenNotFoundException::class)->during('provide'); | ||
} | ||
|
||
function it_returns_the_logged_in_user_if_there_is_one( | ||
TokenStorageInterface $tokenStorage, | ||
TokenInterface $token, | ||
ShopUserInterface $shopUser | ||
): void { | ||
$token->getUser()->willReturn($shopUser); | ||
$tokenStorage->getToken()->willReturn($token); | ||
|
||
$this->provide()->shouldReturn($shopUser); | ||
} | ||
|
||
function it_checks_if_shop_user_is_logged_in( | ||
TokenStorageInterface $tokenStorage, | ||
TokenInterface $token, | ||
ShopUserInterface $shopUser, | ||
UserInterface $anotherUser | ||
): void { | ||
$tokenStorage->getToken()->willReturn(null, $token); | ||
$token->getUser()->willReturn(null, $anotherUser, $shopUser); | ||
|
||
$this->check()->shouldReturn(false); | ||
$this->check()->shouldReturn(false); | ||
$this->check()->shouldReturn(false); | ||
$this->check()->shouldReturn(true); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
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
Oops, something went wrong.