| Conditions | 1 |
| Paths | 1 |
| Total Lines | 91 |
| Code Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 26 | public function testGenerate() : void |
||
| 27 | { |
||
| 28 | $user = 'jwage'; |
||
| 29 | $repository = 'changelog-generator'; |
||
| 30 | $milestone = '1.0'; |
||
| 31 | |||
| 32 | $output = $this->createMock(OutputInterface::class); |
||
| 33 | |||
| 34 | $issue1 = $this->createMock(Issue::class); |
||
| 35 | $issue2 = $this->createMock(Issue::class); |
||
| 36 | $pullRequest1 = $this->createMock(Issue::class); |
||
| 37 | $pullRequest2 = $this->createMock(Issue::class); |
||
| 38 | |||
| 39 | $issueGroup = $this->createMock(IssueGroup::class); |
||
| 40 | |||
| 41 | $milestoneIssues = [$issue1, $issue2, $pullRequest1, $pullRequest2]; |
||
| 42 | $issueGroups = [$issueGroup]; |
||
| 43 | |||
| 44 | $this->issueRepository->expects($this->once()) |
||
| 45 | ->method('getMilestoneIssues') |
||
| 46 | ->with($user, $repository, $milestone) |
||
| 47 | ->willReturn($milestoneIssues); |
||
| 48 | |||
| 49 | $this->issueGrouper->expects($this->once()) |
||
| 50 | ->method('groupIssues') |
||
| 51 | ->with($milestoneIssues) |
||
| 52 | ->willReturn($issueGroups); |
||
| 53 | |||
| 54 | $issueGroup->expects($this->once()) |
||
| 55 | ->method('getName') |
||
| 56 | ->willReturn('Enhancement'); |
||
| 57 | |||
| 58 | $issueGroup->expects($this->once()) |
||
| 59 | ->method('getIssues') |
||
| 60 | ->willReturn([$issue1, $issue2]); |
||
| 61 | |||
| 62 | $issue1->expects($this->once()) |
||
| 63 | ->method('render') |
||
| 64 | ->willReturn('Issue #1'); |
||
| 65 | |||
| 66 | $issue1->expects($this->once()) |
||
| 67 | ->method('getUser') |
||
| 68 | ->willReturn('jwage'); |
||
| 69 | |||
| 70 | $issue2->expects($this->once()) |
||
| 71 | ->method('render') |
||
| 72 | ->willReturn('Issue #2'); |
||
| 73 | |||
| 74 | $issue2->expects($this->once()) |
||
| 75 | ->method('getUser') |
||
| 76 | ->willReturn('jwage'); |
||
| 77 | |||
| 78 | $pullRequest1->expects($this->any()) |
||
| 79 | ->method('isPullRequest') |
||
| 80 | ->willReturn(true); |
||
| 81 | |||
| 82 | $pullRequest1->expects($this->once()) |
||
| 83 | ->method('getUser') |
||
| 84 | ->willReturn('Ocramius'); |
||
| 85 | |||
| 86 | $pullRequest2->expects($this->any()) |
||
| 87 | ->method('isPullRequest') |
||
| 88 | ->willReturn(true); |
||
| 89 | |||
| 90 | $pullRequest2->expects($this->once()) |
||
| 91 | ->method('getUser') |
||
| 92 | ->willReturn('romanb'); |
||
| 93 | |||
| 94 | $output->expects($this->at(0)) |
||
| 95 | ->method('writeln') |
||
| 96 | ->with([ |
||
| 97 | '## 1.0', |
||
| 98 | '', |
||
| 99 | 'Total issues resolved: **2**', |
||
| 100 | 'Total pull requests resolved: **2**', |
||
| 101 | 'Total contributors: **3**', |
||
| 102 | ]); |
||
| 103 | |||
| 104 | $output->expects($this->at(1)) |
||
| 105 | ->method('writeln') |
||
| 106 | ->with([ |
||
| 107 | '', |
||
| 108 | '### Enhancement', |
||
| 109 | '', |
||
| 110 | ]); |
||
| 111 | |||
| 112 | $output->expects($this->at(2)) |
||
| 113 | ->method('writeln') |
||
| 114 | ->with('Issue #1'); |
||
| 115 | |||
| 116 | $this->changelogGenerator->generate($user, $repository, $milestone, $output); |
||
| 117 | } |
||
| 130 |