| Conditions | 1 |
| Paths | 1 |
| Total Lines | 67 |
| Lines | 67 |
| Ratio | 100 % |
| 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 |
||
| 155 | public function testCreateFromRequestWithInvalidAdminClass() |
||
| 156 | { |
||
| 157 | $resource = $this->getMockWithoutConstructor(AdminResource::class); |
||
| 158 | $resource |
||
| 159 | ->expects($this->atLeastOnce()) |
||
| 160 | ->method('getName') |
||
| 161 | ->willReturn('MyLittleTaunTaun') |
||
| 162 | ; |
||
| 163 | |||
| 164 | $resourceCollection = $this->getMockWithoutConstructor(ResourceCollection::class); |
||
| 165 | $resourceCollection |
||
| 166 | ->expects($this->once()) |
||
| 167 | ->method('has') |
||
| 168 | ->with('MyLittleTaunTaun') |
||
| 169 | ->willReturn(true) |
||
| 170 | ; |
||
| 171 | $resourceCollection |
||
| 172 | ->expects($this->once()) |
||
| 173 | ->method('get') |
||
| 174 | ->with('MyLittleTaunTaun') |
||
| 175 | ->willReturn($resource) |
||
| 176 | ; |
||
| 177 | |||
| 178 | $adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class); |
||
| 179 | $adminConfiguration |
||
| 180 | ->expects($this->once()) |
||
| 181 | ->method('getParameter') |
||
| 182 | ->with('class') |
||
| 183 | ->willReturn(FakeAdmin::class) |
||
| 184 | ; |
||
| 185 | |||
| 186 | $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class); |
||
| 187 | $configurationFactory |
||
| 188 | ->expects($this->once()) |
||
| 189 | ->method('createAdminConfiguration') |
||
| 190 | ->with('MyLittleTaunTaun') |
||
| 191 | ->willReturn($adminConfiguration) |
||
| 192 | ; |
||
| 193 | |||
| 194 | $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class); |
||
| 195 | |||
| 196 | $applicationConfiguration = new ApplicationConfiguration(); |
||
| 197 | $applicationConfigurationStorage = $this->getMockWithoutConstructor(ApplicationConfigurationStorage::class); |
||
| 198 | $applicationConfigurationStorage |
||
| 199 | ->expects($this->once()) |
||
| 200 | ->method('getConfiguration') |
||
| 201 | ->willReturn($applicationConfiguration) |
||
| 202 | ; |
||
| 203 | |||
| 204 | $request = new Request([ |
||
| 205 | '_admin' => 'MyLittleTaunTaun', |
||
| 206 | '_route_params' => [ |
||
| 207 | '_admin' => 'MyLittleTaunTaun', |
||
| 208 | '_action' => 'jump', |
||
| 209 | ], |
||
| 210 | ]); |
||
| 211 | |||
| 212 | $adminFactory = new AdminFactory( |
||
| 213 | $resourceCollection, |
||
| 214 | $eventDispatcher, |
||
| 215 | $configurationFactory, |
||
| 216 | $applicationConfigurationStorage |
||
| 217 | ); |
||
| 218 | |||
| 219 | $this->expectException(Exception::class); |
||
| 220 | $adminFactory->createFromRequest($request); |
||
| 221 | } |
||
| 222 | } |
||
| 223 |