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