| Conditions | 8 |
| Paths | 64 |
| Total Lines | 76 |
| Code Lines | 44 |
| 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 |
||
| 102 | |||
| 103 | $request3 = m::mock(Request::class)->makePartial(); |
||
| 104 | $request3->shouldReceive('pathinfo')->andReturn('some1/a/b/c'); |
||
| 105 | |||
| 106 | $request4 = m::mock(Request::class)->makePartial(); |
||
| 107 | $request4->shouldReceive('pathinfo')->andReturn('app3/a/b/c'); |
||
| 108 | |||
| 109 | $request5 = m::mock(Request::class)->makePartial(); |
||
| 110 | $request5->shouldReceive('pathinfo')->andReturn('some2/a/b/c'); |
||
| 111 | |||
| 112 | return [ |
||
| 113 | [$request1, true, 'app1'], |
||
| 114 | [$request2, true, 'app2'], |
||
| 115 | [$request3, true, 'app3'], |
||
| 116 | [$request4, true, null], |
||
| 117 | [$request5, true, 'some2', 'path'], |
||
| 118 | [$request1, false, 'some3'], |
||
| 119 | ]; |
||
| 120 | } |
||
| 121 | |||
| 122 | public function testRunWithException() |
||
| 123 | { |
||
| 124 | $request = m::mock(Request::class); |
||
| 125 | $response = m::mock(Response::class); |
||
| 126 | |||
| 127 | $this->app->shouldReceive('instance')->once()->with('request', $request); |
||
| 128 | |||
| 129 | $exception = new Exception(); |
||
| 130 | |||
| 131 | $this->http->shouldReceive('runWithRequest')->once()->with($request)->andThrow($exception); |
||
| 132 | |||
| 133 | $handle = m::mock(Handle::class); |
||
| 134 | |||
| 135 | $handle->shouldReceive('report')->once()->with($exception); |
||
| 136 | $handle->shouldReceive('render')->once()->with($request, $exception)->andReturn($response); |
||
| 137 | |||
| 138 | $this->app->shouldReceive('make')->with(Handle::class)->andReturn($handle); |
||
| 139 | |||
| 140 | $response->shouldReceive('setCookie')->andReturn($response); |
||
| 141 | |||
| 142 | $this->assertEquals($response, $this->http->run($request)); |
||
| 143 | } |
||
| 144 | |||
| 145 | public function testEnd() |
||
| 146 | { |
||
| 147 | $response = m::mock(Response::class); |
||
| 148 | $event = m::mock(Event::class); |
||
| 149 | $event->shouldReceive('trigger')->once()->with(HttpEnd::class, $response); |
||
| 150 | $this->app->shouldReceive('get')->once()->with('event')->andReturn($event); |
||
| 151 | $log = m::mock(Log::class); |
||
| 152 | $log->shouldReceive('save')->once(); |
||
| 153 | $this->app->shouldReceive('get')->once()->with('log')->andReturn($log); |
||
| 154 | |||
| 155 | $this->http->end($response); |
||
| 156 | } |
||
| 157 | |||
| 158 | } |
||
| 159 |