Conditions | 1 |
Paths | 1 |
Total Lines | 24 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
21 | public function testCreateUserGetsHandled() |
||
22 | { |
||
23 | $handler = new CreateUserHandler($this->userRepository); |
||
24 | |||
25 | $user = new CreateUser(); |
||
26 | $user->username = 'sumo'; |
||
27 | $user->displayName = 'sumocoders'; |
||
28 | $user->password = 'randomPassword'; |
||
29 | |||
30 | $handler->handle($user); |
||
31 | |||
32 | $this->assertEquals( |
||
33 | 'sumo', |
||
34 | $this->userRepository->findByUsername('sumo')->getUsername() |
||
35 | ); |
||
36 | $this->assertEquals( |
||
37 | 'sumocoders', |
||
38 | $this->userRepository->findByUsername('sumo')->getDisplayName() |
||
|
|||
39 | ); |
||
40 | $this->assertEquals( |
||
41 | 'randomPassword', |
||
42 | $this->userRepository->findByUsername('sumo')->getPassword() |
||
43 | ); |
||
44 | } |
||
45 | } |
||
46 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: