Passed
Push — add-field-types-OPS-2210 ( 5f1d71...6faa7b )
by John
03:54 queued 02:13
created

FixedTextRendererTest::testRender()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 69
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 58
dl 0
loc 69
rs 8.9163
c 0
b 0
f 0
cc 2
nc 1
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace Graze\CiffRenderer\Test\Field\Renderer;
4
5
use \Mockery as m;
6
use Graze\CiffRenderer\Field\Renderer\FixedTextRenderer;
7
use Intervention\Image\ImageManager;
8
use Intervention\Image\Image;
9
10
class FixedTextRendererTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testRender()
13
    {
14
        $fontResolver = function () {
15
        };
16
        $text = 'this is some text';
17
        $fontSize = 42;
18
        $orientation = 90;
19
        $tracerColour = '#ccc';
20
21
        $textExpectation = function ($actualClosure) use ($text, $fontSize) {
22
            $actualFont = null;
23
            $actualClosure($actualFont);
24
            return $actualFont->getText() == $text && $actualFont->getSize() == $fontSize;
0 ignored issues
show
Bug introduced by
The method getText() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
            return $actualFont->/** @scrutinizer ignore-call */ getText() == $text && $actualFont->getSize() == $fontSize;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
        };
26
27
        $canvasWidth = 12345;
28
        $canvasHeight = 54321;
29
30
        $imageText = m::mock(Image::class)
31
            ->shouldReceive('text')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'text'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            ->/** @scrutinizer ignore-call */ shouldReceive('text')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
32
            ->with('', null, null, m::on($textExpectation))
33
            ->shouldReceive('resize')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Mockery\Expectation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            ->/** @scrutinizer ignore-call */ shouldReceive('resize')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
            ->shouldReceive('getWidth')
35
            ->andReturn($canvasWidth)
36
            ->once()
37
            ->shouldReceive('getHeight')
38
            ->andReturn($canvasHeight)
39
            ->once()
40
            ->getMock();
41
42
        $imageCanvas = m::mock(Image::class)
43
            ->shouldReceive('insert')
44
            ->with($imageText, 'top-left', 0, 0)
45
            ->once()
46
            ->shouldReceive('rotate')
47
            ->with(360 - $orientation)
48
            ->once()
49
            ->getMock();
50
51
        $imageManager = m::mock(ImageManager::class)
52
            ->shouldReceive('canvas')
53
            ->with(m::type('int'), m::type('int'), $tracerColour)
54
            ->andReturn($imageText)
55
            ->once()
56
            ->shouldReceive('canvas')
57
            ->with($canvasWidth, $canvasHeight, $tracerColour)
58
            ->andReturn($imageCanvas)
59
            ->once()
60
            ->getMock();
61
62
        $renderer = m::mock(FixedTextRenderer::class)
63
            ->shouldAllowMockingProtectedMethods()
64
            ->shouldReceive('getImageManager')
65
            ->andReturn($imageManager)
66
            ->shouldReceive('getFontResolver')
67
            ->andReturn($fontResolver)
68
            ->shouldReceive('getFontFace')
69
            ->shouldReceive('getFontSize')
70
            ->andReturn($fontSize)
71
            ->shouldReceive('getText')
72
            ->andReturn($text)
73
            ->shouldReceive('getOrientation')
74
            ->andReturn($orientation)
75
            ->shouldReceive('getTracerColour')
76
            ->andReturn($tracerColour)
77
            ->getMock()
78
            ->makePartial();
79
80
        $this->assertSame($imageCanvas, $renderer->render());
81
    }
82
}
83