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\Exception\InvalidPasswordConfirmationException; |
8
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\InMemoryUserRepository; |
9
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\User; |
10
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection; |
11
|
|
|
|
12
|
|
|
class PasswordResetHandlerTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var UserRepository |
16
|
|
|
*/ |
17
|
|
|
private $userRepository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var UserRepositoryCollection |
21
|
|
|
*/ |
22
|
|
|
private $userRepositoryCollection; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->userRepository = new InMemoryUserRepository(); |
|
|
|
|
27
|
|
|
$this->userRepositoryCollection = new UserRepositoryCollection([$this->userRepository]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Test if PasswordResetHandler throws error. |
32
|
|
|
* |
33
|
|
|
* @throws InvalidPasswordConfirmationException |
34
|
|
|
*/ |
35
|
|
|
public function testPasswordResetThrowsError() |
36
|
|
|
{ |
37
|
|
|
$handler = new ResetPasswordHandler($this->userRepositoryCollection); |
38
|
|
|
|
39
|
|
|
$user = $this->userRepository->findByUsername('wouter'); |
40
|
|
|
$event = new ResetPassword($user, 'password', 'wrong_confirmation'); |
41
|
|
|
|
42
|
|
|
$this->setExpectedException(InvalidPasswordConfirmationException::class); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$handler->handle($event); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test if PAsswordResetHandler gets handled. |
49
|
|
|
* |
50
|
|
|
* @throws InvalidPasswordConfirmationException |
51
|
|
|
*/ |
52
|
|
|
public function testPasswordResetGetsHandled() |
53
|
|
|
{ |
54
|
|
|
$handler = new ResetPasswordHandler($this->userRepositoryCollection); |
55
|
|
|
|
56
|
|
|
$user = $this->userRepository->findByUsername('reset'); |
57
|
|
|
$event = new ResetPassword($user, 'password', 'password'); |
58
|
|
|
|
59
|
|
|
$user = $this->userRepositoryCollection |
60
|
|
|
->findRepositoryByClassName(User::class) |
61
|
|
|
->findByUsername('reset'); |
62
|
|
|
$password = $user->getPassword(); |
63
|
|
|
$token = $user->getPasswordResetToken(); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$handler->handle($event); |
66
|
|
|
|
67
|
|
|
$updatedUser = $this->userRepositoryCollection |
68
|
|
|
->findRepositoryByClassName(User::class) |
69
|
|
|
->findByUsername('reset'); |
70
|
|
|
|
71
|
|
|
$this->assertEquals($user->getUsername(), $updatedUser->getUsername()); |
72
|
|
|
$this->assertNotEquals($password, $updatedUser->getPassword()); |
73
|
|
|
$this->assertNotNull($token); |
74
|
|
|
$this->assertNull($updatedUser->getPasswordResetToken()); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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..