| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 39 |
| 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 |
||
| 28 | public function testGenerate() |
||
| 29 | { |
||
| 30 | $cacheManager = $this->prophesize(CacheManager::class); |
||
| 31 | $cacheManager->getBrowserPath()->willReturn('cache/media/default/0011/24/ASDASDAS.png'); |
||
| 32 | |||
| 33 | $thumbnail = new LiipImagineThumbnail($cacheManager); |
||
| 34 | |||
| 35 | $filesystem = new Filesystem(new InMemory(['myfile' => 'content'])); |
||
| 36 | $referenceFile = new File('myfile', $filesystem); |
||
| 37 | |||
| 38 | $formats = [ |
||
| 39 | 'admin' => ['height' => 50, 'width' => 50, 'quality' => 100], |
||
| 40 | 'mycontext_medium' => ['height' => 500, 'width' => 500, 'quality' => 100], |
||
| 41 | 'anothercontext_large' => ['height' => 500, 'width' => 500, 'quality' => 100], |
||
| 42 | ]; |
||
| 43 | |||
| 44 | $resizer = $this->prophesize(ResizerInterface::class); |
||
| 45 | $resizer->resize()->willReturn(true); |
||
| 46 | |||
| 47 | $media = new Media(); |
||
| 48 | $media->setName('ASDASDAS.png'); |
||
| 49 | $media->setProviderReference('ASDASDAS.png'); |
||
| 50 | $media->setId(1023456); |
||
| 51 | $media->setContext('default'); |
||
| 52 | |||
| 53 | $provider = $this->prophesize(MediaProviderInterface::class); |
||
| 54 | $provider->requireThumbnails()->willReturn(true); |
||
| 55 | $provider->getReferenceFile()->willReturn($referenceFile); |
||
| 56 | $provider->getFormats()->willReturn($formats); |
||
| 57 | $provider->getResizer()->willReturn($resizer); |
||
| 58 | $provider->generatePrivateUrl()->willReturn('/my/private/path'); |
||
| 59 | $provider->generatePublicUrl()->willReturn('/my/public/path'); |
||
| 60 | $provider->getFilesystem()->willReturn($filesystem); |
||
| 61 | $provider->getReferenceImage($media)->willReturn('default/0011/24/ASDASDAS.png'); |
||
| 62 | $provider->getCdnPath( |
||
| 63 | 'default/0011/24/ASDASDAS.png', |
||
| 64 | null |
||
| 65 | )->willReturn('cache/media/default/0011/24/ASDASDAS.png'); |
||
| 66 | |||
| 67 | $thumbnail->generate($provider->reveal(), $media); |
||
| 68 | $this->assertSame('default/0011/24/ASDASDAS.png', $thumbnail->generatePublicUrl( |
||
| 69 | $provider->reveal(), |
||
| 70 | $media, |
||
| 71 | MediaProviderInterface::FORMAT_ADMIN |
||
| 72 | )); |
||
| 73 | $this->assertSame('cache/media/default/0011/24/ASDASDAS.png', $thumbnail->generatePublicUrl( |
||
| 74 | $provider->reveal(), |
||
| 75 | $media, |
||
| 76 | 'mycontext_medium' |
||
| 77 | )); |
||
| 78 | } |
||
| 79 | |||
| 109 |