|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Component\User\Security; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Prophecy\Argument; |
|
18
|
|
|
use Sylius\Component\User\Model\UserInterface; |
|
19
|
|
|
use Sylius\Component\User\Security\PasswordUpdater; |
|
20
|
|
|
use Sylius\Component\User\Security\PasswordUpdaterInterface; |
|
21
|
|
|
use Sylius\Component\User\Security\UserPasswordEncoderInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Łukasz Chruściel <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
final class PasswordUpdaterSpec extends ObjectBehavior |
|
27
|
|
|
{ |
|
28
|
|
|
function let(UserPasswordEncoderInterface $userPasswordEncoder): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->beConstructedWith($userPasswordEncoder); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_implements_password_updater_interface(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->shouldImplement(PasswordUpdaterInterface::class); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_updates_user_profile_with_encoded_password(UserPasswordEncoderInterface $userPasswordEncoder, UserInterface $user): void |
|
39
|
|
|
{ |
|
40
|
|
|
$user->getPlainPassword()->willReturn('topSecretPlainPassword'); |
|
41
|
|
|
|
|
42
|
|
|
$userPasswordEncoder->encode($user)->willReturn('topSecretEncodedPassword'); |
|
43
|
|
|
|
|
44
|
|
|
$user->eraseCredentials()->shouldBeCalled(); |
|
45
|
|
|
$user->setPassword('topSecretEncodedPassword')->shouldBeCalled(); |
|
46
|
|
|
|
|
47
|
|
|
$this->updatePassword($user); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function it_does_nothing_if_plain_password_is_empty(UserPasswordEncoderInterface $userPasswordEncoder, UserInterface $user): void |
|
51
|
|
|
{ |
|
52
|
|
|
$user->getPlainPassword()->willReturn(''); |
|
53
|
|
|
|
|
54
|
|
|
$userPasswordEncoder->encode($user)->willReturn('topSecretEncodedPassword'); |
|
55
|
|
|
|
|
56
|
|
|
$user->setPassword(Argument::any())->shouldNotBeCalled(); |
|
57
|
|
|
$user->eraseCredentials()->shouldNotBeCalled(); |
|
58
|
|
|
|
|
59
|
|
|
$this->updatePassword($user); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|