| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 42 |
| 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 |
||
| 11 | public function testGetImageFromCache() |
||
| 12 | { |
||
| 13 | $cacheManager = $this->createMock('HtImgModule\Service\CacheManagerInterface'); |
||
| 14 | $cacheManager->expects($this->once()) |
||
| 15 | ->method('cacheExists') |
||
| 16 | ->will($this->returnValue(true)); |
||
| 17 | $cacheManager->expects($this->once()) |
||
| 18 | ->method('getCachePath') |
||
| 19 | ->will($this->returnValue(RESOURCES_DIR.'/flowers.jpg')); |
||
| 20 | $imagine = $this->createMock('Imagine\Image\ImagineInterface'); |
||
| 21 | $filterManager = $this->createMock('HtImgModule\Imagine\Filter\FilterManagerInterface'); |
||
| 22 | $loaderManager = $this->createMock('HtImgModule\Imagine\Loader\LoaderManagerInterface'); |
||
| 23 | $imageService = new ImageService( |
||
| 24 | $cacheManager, |
||
| 25 | $imagine, |
||
| 26 | $filterManager, |
||
| 27 | $loaderManager |
||
| 28 | ); |
||
| 29 | |||
| 30 | $relativePath = 'path/to/image/flowers.jpg'; |
||
| 31 | $filterName = 'foo_filter'; |
||
| 32 | |||
| 33 | $binary = $this->createMock('HtImgModule\Binary\BinaryInterface'); |
||
| 34 | $loaderManager->expects($this->once()) |
||
| 35 | ->method('loadBinary') |
||
| 36 | ->with($relativePath, $filterName) |
||
| 37 | ->will($this->returnValue($binary)); |
||
| 38 | |||
| 39 | $filterOptions = ['format' => 'gif', 'quality' => 87, 'animated' => true]; |
||
| 40 | |||
| 41 | $filterManager->expects($this->once()) |
||
| 42 | ->method('getFilterOptions') |
||
| 43 | ->with('foo_filter') |
||
| 44 | ->will($this->returnValue($filterOptions)); |
||
| 45 | |||
| 46 | $cacheManager->expects($this->once()) |
||
| 47 | ->method('isCachingEnabled') |
||
| 48 | ->with('foo_filter', $filterOptions) |
||
| 49 | ->will($this->returnValue(true)); |
||
| 50 | |||
| 51 | $image = $this->createMock('Imagine\Image\ImageInterface'); |
||
| 52 | $imagine->expects($this->once()) |
||
| 53 | ->method('open') |
||
| 54 | ->with(RESOURCES_DIR.'/flowers.jpg') |
||
| 55 | ->will($this->returnValue($image)); |
||
| 56 | |||
| 57 | $imageData = $imageService->getImage('path/to/image/flowers.jpg', 'foo_filter'); |
||
| 58 | |||
| 59 | $this->assertEquals($image, $imageData['image']); |
||
| 60 | $this->assertEquals('gif', $imageData['format']); |
||
| 61 | $this->assertEquals(87, $imageData['imageOutputOptions']['quality']); |
||
| 62 | $this->assertEquals(true, $imageData['imageOutputOptions']['animated']); |
||
| 63 | } |
||
| 64 | |||
| 131 |