| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 50 |
| 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 |
||
| 65 | public function testGetImageFromRelativePathAndCreateCache() |
||
| 66 | { |
||
| 67 | $cacheManager = $this->createMock('HtImgModule\Service\CacheManagerInterface'); |
||
| 68 | $imagine = $this->createMock('Imagine\Image\ImagineInterface'); |
||
| 69 | $filterManager = $this->createMock('HtImgModule\Imagine\Filter\FilterManagerInterface'); |
||
| 70 | $loaderManager = $this->createMock('HtImgModule\Imagine\Loader\LoaderManagerInterface'); |
||
| 71 | $imageService = new ImageService( |
||
| 72 | $cacheManager, |
||
| 73 | $imagine, |
||
| 74 | $filterManager, |
||
| 75 | $loaderManager |
||
| 76 | ); |
||
| 77 | |||
| 78 | $binaryContent = '35345fascxzcasdfhj;alsdkf4asldfkja;sldf65854'; |
||
| 79 | $relativePath = 'relative/path/to/image'; |
||
| 80 | $filterName = 'foo-bar-filter'; |
||
| 81 | |||
| 82 | $filterOptions = ['quality' => 87]; |
||
| 83 | |||
| 84 | $filterManager->expects($this->once()) |
||
| 85 | ->method('getFilterOptions') |
||
| 86 | ->with($filterName) |
||
| 87 | ->will($this->returnValue($filterOptions)); |
||
| 88 | |||
| 89 | $binary = $this->createMock('HtImgModule\Binary\BinaryInterface'); |
||
| 90 | $binary->expects($this->once()) |
||
| 91 | ->method('getContent') |
||
| 92 | ->will($this->returnValue($binaryContent)); |
||
| 93 | $loaderManager->expects($this->once()) |
||
| 94 | ->method('loadBinary') |
||
| 95 | ->with($relativePath, $filterName) |
||
| 96 | ->will($this->returnValue($binary)); |
||
| 97 | |||
| 98 | $image = $this->createMock('Imagine\Image\ImageInterface'); |
||
| 99 | |||
| 100 | $imagine->expects($this->once()) |
||
| 101 | ->method('load') |
||
| 102 | ->with($binaryContent) |
||
| 103 | ->will($this->returnValue($image)); |
||
| 104 | |||
| 105 | $filteredImage = $this->createMock('Imagine\Image\ImageInterface'); |
||
| 106 | $filter = $this->createMock('Imagine\Filter\FilterInterface'); |
||
| 107 | $filter->expects($this->once()) |
||
| 108 | ->method('apply') |
||
| 109 | ->with($image) |
||
| 110 | ->will($this->returnValue($filteredImage)); |
||
| 111 | |||
| 112 | $filterManager->expects($this->once()) |
||
| 113 | ->method('getFilter') |
||
| 114 | ->with($filterName) |
||
| 115 | ->will($this->returnValue($filter)); |
||
| 116 | |||
| 117 | $cacheManager->expects($this->any()) |
||
| 118 | ->method('isCachingEnabled') |
||
| 119 | ->with($filterName, $filterOptions) |
||
| 120 | ->will($this->returnValue(true)); |
||
| 121 | |||
| 122 | $cacheManager->expects($this->once()) |
||
| 123 | ->method('createCache') |
||
| 124 | ->with($relativePath, $filterName, $filteredImage, 'png', $filterOptions); |
||
| 125 | |||
| 126 | $imageData = $imageService->getImage($relativePath, $filterName); |
||
| 127 | |||
| 128 | $this->assertEquals($image, $imageData['image']); |
||
| 129 | } |
||
| 130 | } |
||
| 131 |