1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkMultiUserBundle\Tests\Command; |
4
|
|
|
|
5
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Command\UpdateUser; |
6
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Command\UpdateUserHandler; |
7
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\InMemoryUserRepository; |
8
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\UserRepository; |
9
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection; |
10
|
|
|
|
11
|
|
|
class UpdateUserHandlerTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var UserRepository |
15
|
|
|
*/ |
16
|
|
|
private $userRepository; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var UserRepositoryCollection |
20
|
|
|
*/ |
21
|
|
|
private $userRepositoryCollection; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->userRepository = new InMemoryUserRepository(); |
26
|
|
|
$this->userRepositoryCollection = new UserRepositoryCollection([$this->userRepository]); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Test if UpdateUserHandler gets handled. |
31
|
|
|
*/ |
32
|
|
|
public function testUpdateUserGetsHandled() |
33
|
|
|
{ |
34
|
|
|
$handler = new UpdateUserHandler($this->userRepositoryCollection); |
35
|
|
|
|
36
|
|
|
$updatingUser = $this->userRepository->findByUsername('wouter'); |
37
|
|
|
|
38
|
|
|
$command = new UpdateUser($updatingUser, 'wouter', 'randomPassword', 'sumocoders'); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$handler->handle($command); |
41
|
|
|
|
42
|
|
|
$this->assertEquals( |
43
|
|
|
'wouter', |
44
|
|
|
$this->userRepository->findByUsername('wouter')->getUsername() |
45
|
|
|
); |
46
|
|
|
$this->assertEquals( |
47
|
|
|
'sumocoders', |
48
|
|
|
$this->userRepository->findByUsername('wouter')->getDisplayName() |
49
|
|
|
); |
50
|
|
|
$this->assertEquals( |
51
|
|
|
'randomPassword', |
52
|
|
|
$this->userRepository->findByUsername('wouter')->getPassword() |
53
|
|
|
); |
54
|
|
|
$this->assertNotEquals( |
55
|
|
|
$updatingUser->getDisplayName(), |
56
|
|
|
$this->userRepository->findByUsername('wouter')->getDisplayName() |
57
|
|
|
); |
58
|
|
|
$this->assertNotEquals( |
59
|
|
|
$updatingUser->getPassword(), |
60
|
|
|
$this->userRepository->findByUsername('wouter')->getPassword() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: