| 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 |
||
| 25 | public function shouldCreateNewUserAndUpdateIt(): void |
||
| 26 | { |
||
| 27 | //given: There is a new user to be created |
||
| 28 | $userName = "[email protected]"; |
||
| 29 | $password = "itPassword"; |
||
| 30 | $roles = "ROLE_ADMIN"; |
||
| 31 | |||
| 32 | //and: the CLI application is bootable |
||
| 33 | $application = $this->setupKernel(); |
||
| 34 | |||
| 35 | //when: the user is created using CLI Command |
||
| 36 | $command = $application->find('app:security:create-user'); |
||
| 37 | $commandTester = new CommandTester($command); |
||
| 38 | $commandTester->execute(array( |
||
| 39 | 'command' => $command->getName(), |
||
| 40 | 'login' => $userName, |
||
| 41 | 'password' => $password, |
||
| 42 | 'roles' => $roles, |
||
| 43 | )); |
||
| 44 | |||
| 45 | //then: the user was created successfully |
||
| 46 | $output = $commandTester->getDisplay(); |
||
| 47 | $this->assertStringStartsWith("Successfully created user '$userName' with id", $output); |
||
| 48 | |||
| 49 | //when: the user is created using CLI Command |
||
| 50 | $newUserName = "[email protected]"; |
||
| 51 | $command = $application->find('app:security:rename-user'); |
||
| 52 | $commandTester = new CommandTester($command); |
||
| 53 | $commandTester->execute(array( |
||
| 54 | 'command' => $command->getName(), |
||
| 55 | 'login' => $userName, |
||
| 56 | 'newLogin' => $newUserName, |
||
| 57 | )); |
||
| 58 | |||
| 59 | //then: the user was renamed successfully |
||
| 60 | $output = $commandTester->getDisplay(); |
||
| 61 | $this->assertStringStartsWith("Successfully renamed user '$userName' to '$newUserName'", $output); |
||
| 62 | |||
| 63 | //and: The RenamedUserOEvent was Published |
||
| 64 | $events = InMemoryEventPublisher::get(UserRenamedOEvent::class); |
||
| 65 | self::assertCount(1, $events); |
||
| 66 | self::assertEquals($userName, $events[0]->getData()['oldLogin']); |
||
| 67 | self::assertEquals($newUserName, $events[0]->getData()['newLogin']); |
||
| 68 | |||
| 69 | //when: the user is created using CLI Command |
||
| 70 | $newPassword = "itPasswordUpdated"; |
||
| 71 | $command = $application->find('app:security:change-password'); |
||
| 72 | $commandTester = new CommandTester($command); |
||
| 73 | $commandTester->execute(array( |
||
| 74 | 'command' => $command->getName(), |
||
| 75 | 'login' => $newUserName, |
||
| 76 | 'password' => $newPassword |
||
| 77 | )); |
||
| 78 | |||
| 79 | //then: the password was changed successfully |
||
| 80 | $output = $commandTester->getDisplay(); |
||
| 81 | $this->assertStringStartsWith("Successfully changed password for user '$newUserName'.", $output); |
||
| 82 | |||
| 132 | } |