1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkMultiUserBundle\Tests\Command; |
4
|
|
|
|
5
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Command\ResetPassword; |
6
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Command\ResetPasswordHandler; |
7
|
|
|
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\Form\ChangePassword; |
8
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidPasswordConfirmationException; |
9
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\InMemoryUserRepository; |
10
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\User; |
11
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection; |
12
|
|
|
|
13
|
|
|
class PasswordResetHandlerTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var UserRepository |
17
|
|
|
*/ |
18
|
|
|
private $userRepository; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var UserRepositoryCollection |
22
|
|
|
*/ |
23
|
|
|
private $userRepositoryCollection; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->userRepository = new InMemoryUserRepository(); |
|
|
|
|
28
|
|
|
$this->userRepositoryCollection = new UserRepositoryCollection([$this->userRepository]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Test if PAsswordResetHandler gets handled. |
33
|
|
|
* |
34
|
|
|
* @throws InvalidPasswordConfirmationException |
35
|
|
|
*/ |
36
|
|
|
public function testPasswordResetGetsHandled() |
37
|
|
|
{ |
38
|
|
|
$handler = new ResetPasswordHandler($this->userRepositoryCollection); |
39
|
|
|
|
40
|
|
|
$user = $this->userRepository->findByUsername('reset'); |
41
|
|
|
|
42
|
|
|
$dataTransferObject = ChangePassword::forUser($user); |
43
|
|
|
$dataTransferObject->newPassword = 'changedPassword'; |
44
|
|
|
|
45
|
|
|
$user = $this->userRepositoryCollection |
46
|
|
|
->findRepositoryByClassName(User::class) |
47
|
|
|
->findByUsername('reset'); |
48
|
|
|
$password = $user->getPassword(); |
49
|
|
|
$token = $user->getPasswordResetToken(); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$handler->handle($dataTransferObject); |
52
|
|
|
|
53
|
|
|
$updatedUser = $this->userRepositoryCollection |
54
|
|
|
->findRepositoryByClassName(User::class) |
55
|
|
|
->findByUsername('reset'); |
56
|
|
|
|
57
|
|
|
$this->assertEquals($user->getUsername(), $updatedUser->getUsername()); |
58
|
|
|
$this->assertNotEquals($password, $updatedUser->getPassword()); |
59
|
|
|
$this->assertNotNull($token); |
60
|
|
|
$this->assertNull($updatedUser->getPasswordResetToken()); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..