Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 71 |
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 |
||
14 | public function testRender() |
||
15 | { |
||
16 | $text = 'i am text'; |
||
17 | $file = 'i am file'; |
||
18 | $size = 4.2; |
||
19 | $width = 2; |
||
20 | $height = 4; |
||
21 | $font = m::mock(Font::class) |
||
22 | ->shouldReceive('text') |
||
23 | ->with($text) |
||
24 | ->once() |
||
25 | ->shouldReceive('file') |
||
26 | ->with($file) |
||
27 | ->once() |
||
28 | ->shouldReceive('size') |
||
29 | ->with($size * FieldRendererFixedText::FONT_SIZE_MULTIPLIER) |
||
30 | ->once() |
||
31 | ->shouldReceive('color') |
||
32 | ->with('#000') |
||
33 | ->once() |
||
34 | ->shouldReceive('valign') |
||
35 | ->with('top') |
||
36 | ->once() |
||
37 | ->shouldReceive('getBoxSize') |
||
38 | ->andReturn(['width' => $width, 'height' => $height]) |
||
39 | ->once() |
||
40 | ->getMock(); |
||
41 | $textExpectation = function ($actualClosure) use ($font) { |
||
42 | $fontActual = null; |
||
43 | $actualClosure($fontActual); |
||
44 | return $fontActual == $font; |
||
45 | }; |
||
46 | $orientation = 90; |
||
47 | $canvas = m::mock(Image::class) |
||
48 | ->shouldReceive('text') |
||
49 | ->with('', null, null, m::on($textExpectation)) |
||
50 | ->shouldReceive('resize') |
||
51 | ->with($width * FieldRendererFixedText::LETTER_SPACING_ADJUSTMENT, $height) |
||
52 | ->once() |
||
53 | ->shouldReceive('rotate') |
||
54 | ->with(360 - $orientation) |
||
55 | ->once() |
||
56 | ->getMock(); |
||
57 | |||
58 | $imageManager = m::mock(ImageManager::class) |
||
59 | ->shouldReceive('canvas') |
||
60 | ->with($width, $height) |
||
61 | ->andReturn($canvas) |
||
62 | ->once() |
||
63 | ->getMock(); |
||
64 | |||
65 | $faceExpected = 'i am face'; |
||
66 | $parser = m::mock(FieldParserInterface::class) |
||
67 | ->shouldReceive('getText') |
||
68 | ->andReturn($text) |
||
69 | ->once() |
||
70 | ->shouldReceive('getFontFace') |
||
71 | ->andReturn($faceExpected) |
||
72 | ->once() |
||
73 | ->shouldReceive('getFontSize') |
||
74 | ->andReturn($size) |
||
75 | ->once() |
||
76 | ->shouldReceive('getOrientation') |
||
77 | ->andReturn($orientation) |
||
78 | ->once() |
||
79 | ->getMock(); |
||
80 | |||
81 | $fontResolver = function ($face) use ($faceExpected, $file) { |
||
82 | $this->assertEquals($faceExpected, $face); |
||
83 | return $file; |
||
84 | }; |
||
85 | |||
86 | $renderer = new FieldRendererFixedText($font); |
||
87 | $image = $renderer->render( |
||
88 | $imageManager, |
||
89 | $parser, |
||
90 | $fontResolver |
||
91 | ); |
||
92 | |||
93 | $this->assertEquals($canvas, $image); |
||
94 | } |
||
95 | } |
||
96 |