Completed
Pull Request — master (#19)
by John
09:10 queued 04:43
created

RendererDocumentTest::testRender()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 72
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 62
nc 1
nop 0
dl 0
loc 72
rs 8.829
c 0
b 0
f 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\Unit\Renderer;
4
5
use Mockery as m;
6
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
7
use Graze\CiffRenderer\Parser\ParserDocument;
8
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererFactory;
9
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererInterface;
10
use Intervention\Image\ImageManager;
11
use Intervention\Image\Image;
12
use Graze\CiffRenderer\Renderer\RendererDocument;
13
14
class RendererDocumentTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function testRender()
17
    {
18
        $posX = 1;
19
        $posY = 3;
20
        $width = 2;
21
        $height = 4;
22
        $image = m::mock(Image::class);
23
        $canvas = m::mock(Image::class)
24
            ->shouldReceive('insert')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'insert'. ( Ignorable by Annotation )

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

24
            ->/** @scrutinizer ignore-call */ shouldReceive('insert')

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...
25
            ->with($image, 'top-left', (int) $posX, (int) $posY)
26
            ->once()
27
            ->getMock();
28
        $imageManager = m::mock(ImageManager::class)
29
            ->shouldReceive('canvas')
30
            ->with($width, $height, '#fff')
31
            ->once()
32
            ->andReturn($canvas)
33
            ->getMock();
34
35
        $fieldParser = m::mock(FieldParserInterface::class)
36
            ->shouldReceive('isDisplayed')
37
            ->andReturn(true)
38
            ->once()
39
            ->shouldReceive('getPositionX')
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

39
            ->/** @scrutinizer ignore-call */ shouldReceive('getPositionX')

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...
40
            ->andReturn($posX)
41
            ->once()
42
            ->shouldReceive('getPositionY')
43
            ->andReturn($posY)
44
            ->once()
45
            ->getMock();
46
47
        $xml = new \SimpleXMLElement('<xml/>');
48
        $parserDocument = m::mock(ParserDocument::class)
49
            ->shouldReceive('parse')
50
            ->with($xml)
51
            ->once()
52
            ->shouldReceive('getFieldParsers')
53
            ->andReturn([$fieldParser])
54
            ->once()
55
            ->shouldReceive('getWidth')
56
            ->andReturn($width)
57
            ->once()
58
            ->shouldReceive('getHeight')
59
            ->andReturn($height)
60
            ->once()
61
            ->getMock();
62
63
        $fontResolver = function () {}; // @codingStandardsIgnoreLine
64
        $graphicResolver = function () {}; // @codingStandardsIgnoreLine
65
        $fieldRenderer = m::mock(FieldRendererInterface::class)
66
            ->shouldReceive('render')
67
            ->with($imageManager, $fieldParser, $fontResolver, $graphicResolver)
68
            ->andReturn($image)
69
            ->once()
70
            ->getMock();
71
72
        $fieldRendererFactory = m::mock(FieldRendererFactory::class)
73
            ->shouldReceive('getFieldRenderer')
74
            ->with($fieldParser)
75
            ->andReturn($fieldRenderer)
76
            ->once()
77
            ->getMock();
78
79
        $rendererDocument = new RendererDocument(
80
            $parserDocument,
81
            $fieldRendererFactory,
0 ignored issues
show
Bug introduced by
$fieldRendererFactory of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Rende...er\FieldRendererFactory expected by parameter $fieldRendererFactory of Graze\CiffRenderer\Rende...Document::__construct(). ( Ignorable by Annotation )

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

81
            /** @scrutinizer ignore-type */ $fieldRendererFactory,
Loading history...
82
            $imageManager
0 ignored issues
show
Bug introduced by
$imageManager of type Mockery\MockInterface is incompatible with the type Intervention\Image\ImageManager expected by parameter $imageManager of Graze\CiffRenderer\Rende...Document::__construct(). ( Ignorable by Annotation )

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

82
            /** @scrutinizer ignore-type */ $imageManager
Loading history...
83
        );
84
85
        $imageActual = $rendererDocument->render($xml, $fontResolver, $graphicResolver);
86
87
        $this->assertSame($canvas, $imageActual);
88
    }
89
}
90