| Conditions | 2 |
| Paths | 2 |
| Total Lines | 85 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 60 | public function testIndex() { |
||
| 61 | $account1 = $this->getMock('OCA\Mail\Service\IAccount'); |
||
| 62 | $account2 = $this->getMock('OCA\Mail\Service\IAccount'); |
||
| 63 | |||
| 64 | $this->accountService->expects($this->once()) |
||
| 65 | ->method('findByUserId') |
||
| 66 | ->with($this->userId) |
||
| 67 | ->will($this->returnValue([ |
||
| 68 | $account1, |
||
| 69 | $account2, |
||
| 70 | ])); |
||
| 71 | $account1->expects($this->once()) |
||
| 72 | ->method('getConfiguration') |
||
| 73 | ->will($this->returnValue([ |
||
| 74 | 'accountId' => 1, |
||
| 75 | ])); |
||
| 76 | $account2->expects($this->once()) |
||
| 77 | ->method('getConfiguration') |
||
| 78 | ->will($this->returnValue([ |
||
| 79 | 'accountId' => 2, |
||
| 80 | ])); |
||
| 81 | $this->aliasesService->expects($this->exactly(2)) |
||
| 82 | ->method('findAll') |
||
| 83 | ->will($this->returnValueMap([ |
||
| 84 | [1, $this->userId, ['a11', 'a12']], |
||
| 85 | [2, $this->userId, ['a21', 'a22']], |
||
| 86 | ])); |
||
| 87 | $accountsJson = [ |
||
| 88 | [ |
||
| 89 | 'accountId' => 1, |
||
| 90 | 'aliases' => [ |
||
| 91 | 'a11', |
||
| 92 | 'a12', |
||
| 93 | ] |
||
| 94 | ], |
||
| 95 | [ |
||
| 96 | 'accountId' => 2, |
||
| 97 | 'aliases' => [ |
||
| 98 | 'a21', |
||
| 99 | 'a22', |
||
| 100 | ] |
||
| 101 | ], |
||
| 102 | ]; |
||
| 103 | |||
| 104 | $user = $this->getMockBuilder('\OCP\IUser')->getMock(); |
||
| 105 | $this->userSession->expects($this->once()) |
||
| 106 | ->method('getUser') |
||
| 107 | ->will($this->returnValue($user)); |
||
| 108 | $this->config->expects($this->once()) |
||
| 109 | ->method('getSystemValue') |
||
| 110 | ->with('debug', false) |
||
| 111 | ->will($this->returnValue(true)); |
||
| 112 | $this->config->expects($this->once()) |
||
| 113 | ->method('getAppValue') |
||
| 114 | ->with('mail', 'installed_version') |
||
| 115 | ->will($this->returnValue('1.2.3')); |
||
| 116 | $user->expects($this->once()) |
||
| 117 | ->method('getDisplayName') |
||
| 118 | ->will($this->returnValue('Jane Doe')); |
||
| 119 | $user->expects($this->once()) |
||
| 120 | ->method('getUID') |
||
| 121 | ->will($this->returnValue('jane')); |
||
| 122 | $this->config->expects($this->once()) |
||
| 123 | ->method('getUserValue') |
||
| 124 | ->with($this->equalTo('jane'), $this->equalTo('settings'), $this->equalTo('email'), $this->equalTo('')) |
||
| 125 | ->will($this->returnValue('[email protected]')); |
||
| 126 | |||
| 127 | $expected = new TemplateResponse($this->appName, 'index', [ |
||
| 128 | 'debug' => true, |
||
| 129 | 'app-version' => '1.2.3', |
||
| 130 | 'accounts' => base64_encode(json_encode($accountsJson)), |
||
| 131 | 'prefill_displayName' => 'Jane Doe', |
||
| 132 | 'prefill_email' => '[email protected]', |
||
| 133 | ]); |
||
| 134 | // set csp rules for ownCloud 8.1 |
||
| 135 | if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { |
||
| 136 | $csp = new ContentSecurityPolicy(); |
||
| 137 | $csp->addAllowedFrameDomain('\'self\''); |
||
| 138 | $expected->setContentSecurityPolicy($csp); |
||
| 139 | } |
||
| 140 | |||
| 141 | $response = $this->controller->index(); |
||
| 142 | |||
| 143 | $this->assertEquals($expected, $response); |
||
| 144 | } |
||
| 145 | |||
| 210 |