| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 37 |
| 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 |
||
| 67 | public function testAddActionLogsFormErrorsIntoTheRbCommentNamespace() |
||
| 68 | { |
||
| 69 | //'contact' key is missing on purpose |
||
| 70 | $postMock = [ |
||
| 71 | 'author' => 'Tester', |
||
| 72 | 'content' => 'test', |
||
| 73 | 'uri' => '/test', |
||
| 74 | ]; |
||
| 75 | |||
| 76 | // Request Mock Setup |
||
| 77 | $this->requestMock->expects($this->once()) |
||
| 78 | ->method('isPost') |
||
| 79 | ->will($this->returnValue(true)); |
||
| 80 | |||
| 81 | $this->requestMock->expects($this->once()) |
||
| 82 | ->method('getPost') |
||
| 83 | ->will($this->returnValue($postMock)); |
||
| 84 | |||
| 85 | // FlashMessenger Mock |
||
| 86 | $flashMessengerMock = $this->createMock(FlashMessenger::class); |
||
| 87 | |||
| 88 | $flashMessengerMock->expects($this->once()) |
||
| 89 | ->method('setNamespace') |
||
| 90 | ->with('RbComment'); |
||
| 91 | |||
| 92 | // Redirect Mock |
||
| 93 | $redirectMock = $this->createMock(Redirect::class); |
||
| 94 | |||
| 95 | $redirectMock->expects($this->once()) |
||
| 96 | ->method('toUrl') |
||
| 97 | ->with($postMock['uri'] . '#rbcomment'); |
||
| 98 | |||
| 99 | // CommentController Mock |
||
| 100 | $commentControllerMock = |
||
| 101 | $this->getMockBuilder(CommentController::class) |
||
| 102 | ->setConstructorArgs([ |
||
| 103 | $this->configMock, |
||
| 104 | $this->commentTableMock, |
||
| 105 | $this->akismetServiceMock |
||
| 106 | ]) |
||
| 107 | ->setMethods(['getRequest', 'flashMessenger', 'redirect']) |
||
| 108 | ->getMock(); |
||
| 109 | |||
| 110 | $commentControllerMock->expects($this->once()) |
||
| 111 | ->method('getRequest') |
||
| 112 | ->will($this->returnValue($this->requestMock)); |
||
| 113 | |||
| 114 | $commentControllerMock->expects($this->exactly(2)) |
||
| 115 | ->method('flashMessenger') |
||
| 116 | ->will($this->returnValue($flashMessengerMock)); |
||
| 117 | |||
| 118 | $commentControllerMock->expects($this->once()) |
||
| 119 | ->method('redirect') |
||
| 120 | ->will($this->returnValue($redirectMock)); |
||
| 121 | |||
| 122 | $commentControllerMock->addAction(); |
||
| 123 | } |
||
| 124 | |||
| 193 |