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 |
||
78 | public function shouldCreateNewUserAndUpdateIt(): void |
||
79 | { |
||
80 | //given: There is a new user to be created |
||
81 | $userName = "[email protected]"; |
||
82 | $password = "itPassword"; |
||
83 | $roles = "ROLE_ADMIN"; |
||
84 | |||
85 | //and: the CLI application is bootable |
||
86 | $application = $this->setupKernel(); |
||
87 | |||
88 | //when: the user is created using CLI Command |
||
89 | $command = $application->find('app:security:create-user'); |
||
90 | $commandTester = new CommandTester($command); |
||
91 | $commandTester->execute(array( |
||
92 | 'command' => $command->getName(), |
||
93 | 'login' => $userName, |
||
94 | 'password' => $password, |
||
95 | 'roles' => $roles, |
||
96 | )); |
||
97 | |||
98 | //then: the user was created successfully |
||
99 | $output = $commandTester->getDisplay(); |
||
100 | $this->assertStringStartsWith("Successfully created user '$userName' with id", $output); |
||
101 | |||
102 | //when: the user is created using CLI Command |
||
103 | $newUserName = "[email protected]"; |
||
104 | $command = $application->find('app:security:rename-user'); |
||
105 | $commandTester = new CommandTester($command); |
||
106 | $commandTester->execute(array( |
||
107 | 'command' => $command->getName(), |
||
108 | 'login' => $userName, |
||
109 | 'newLogin' => $newUserName, |
||
110 | )); |
||
111 | |||
112 | //then: the user was renamed successfully |
||
113 | $output = $commandTester->getDisplay(); |
||
114 | $this->assertStringStartsWith("Successfully renamed user '$userName' to '$newUserName'", $output); |
||
115 | |||
116 | //and: The RenamedUserOEvent was Published |
||
117 | $events = InMemoryEventPublisher::get(UserRenamedOEvent::class); |
||
118 | self::assertCount(1, $events); |
||
119 | self::assertEquals($userName, $events[0]->getData()['oldLogin']); |
||
120 | self::assertEquals($newUserName, $events[0]->getData()['newLogin']); |
||
121 | |||
122 | //when: the user is created using CLI Command |
||
123 | $newPassword = "itPasswordUpdated"; |
||
124 | $command = $application->find('app:security:change-password'); |
||
125 | $commandTester = new CommandTester($command); |
||
126 | $commandTester->execute(array( |
||
127 | 'command' => $command->getName(), |
||
128 | 'login' => $newUserName, |
||
129 | 'password' => $newPassword |
||
130 | )); |
||
131 | |||
132 | //then: the password was changed successfully |
||
133 | $output = $commandTester->getDisplay(); |
||
134 | $this->assertStringStartsWith("Successfully changed password for user '$newUserName'.", $output); |
||
135 | |||
185 | } |