Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
37 | public function shouldCreateNewUserAndUpdateIt(): void |
||
38 | { |
||
39 | //given: There is a new user to be created |
||
40 | $userName = "[email protected]"; |
||
41 | $password = "itPassword"; |
||
42 | $roles = "ROLE_ADMIN"; |
||
43 | |||
44 | //and: the CLI application is bootable |
||
45 | $application = $this->setupKernel(); |
||
46 | |||
47 | //when: the user is created using CLI Command |
||
48 | $command = $application->find('app:security:create-user'); |
||
49 | $commandTester = new CommandTester($command); |
||
50 | $commandTester->execute(array( |
||
51 | 'command' => $command->getName(), |
||
52 | 'login' => $userName, |
||
53 | 'password' => $password, |
||
54 | 'roles' => $roles, |
||
55 | )); |
||
56 | |||
57 | //then: the user was created successfully |
||
58 | $output = $commandTester->getDisplay(); |
||
59 | $this->assertStringStartsWith("Successfully created user '$userName' with id", $output); |
||
60 | |||
61 | //when: the user is created using CLI Command |
||
62 | $newUserName = "[email protected]"; |
||
63 | $command = $application->find('app:security:rename-user'); |
||
64 | $commandTester = new CommandTester($command); |
||
65 | $commandTester->execute(array( |
||
66 | 'command' => $command->getName(), |
||
67 | 'login' => $userName, |
||
68 | 'newLogin' => $newUserName, |
||
69 | )); |
||
70 | |||
71 | //then: the user was renamed successfully |
||
72 | $output = $commandTester->getDisplay(); |
||
73 | $this->assertStringStartsWith("Successfully renamed user '$userName' to '$newUserName'", $output); |
||
74 | |||
75 | //and: The RenamedUserOEvent was Published |
||
76 | $events = InMemoryEventPublisher::get(UserRenamedOEvent::class); |
||
77 | self::assertCount(1, $events); |
||
78 | self::assertEquals($userName, $events[0]->getData()['oldLogin']); |
||
79 | self::assertEquals($newUserName, $events[0]->getData()['newLogin']); |
||
80 | |||
81 | //when: the user is created using CLI Command |
||
82 | $newPassword = "itPasswordUpdated"; |
||
83 | $command = $application->find('app:security:change-password'); |
||
84 | $commandTester = new CommandTester($command); |
||
85 | $commandTester->execute(array( |
||
86 | 'command' => $command->getName(), |
||
87 | 'login' => $newUserName, |
||
88 | 'password' => $newPassword |
||
89 | )); |
||
90 | |||
91 | //then: the password was changed successfully |
||
92 | $output = $commandTester->getDisplay(); |
||
93 | $this->assertStringStartsWith("Successfully changed password for user '$newUserName'.", $output); |
||
94 | |||
144 | } |