Conditions | 1 |
Paths | 1 |
Total Lines | 21 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
21 | public function testCreateUserGetsHandled() |
||
22 | { |
||
23 | $handler = new CreateUserHandler($this->userRepository); |
||
24 | |||
25 | $user = new CreateUser('sumo', 'randomPassword', 'sumocoders'); |
||
26 | |||
27 | $handler->handle($user); |
||
28 | |||
29 | $this->assertEquals( |
||
30 | 'sumo', |
||
31 | $this->userRepository->findByUsername('sumo')->getUsername() |
||
32 | ); |
||
33 | $this->assertEquals( |
||
34 | 'sumocoders', |
||
35 | $this->userRepository->findByUsername('sumo')->getDisplayName() |
||
|
|||
36 | ); |
||
37 | $this->assertEquals( |
||
38 | 'randomPassword', |
||
39 | $this->userRepository->findByUsername('sumo')->getPassword() |
||
40 | ); |
||
41 | } |
||
42 | } |
||
43 |
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: