Completed
Branch master (4d68bf)
by John
02:46
created

RendererDocumentTest::testRender()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 73
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 62
nc 1
nop 0
dl 0
loc 73
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 \SimpleXMLElement;
13
use Graze\CiffRenderer\Renderer\RendererDocument;
14
15
class RendererDocumentTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function testRender()
18
    {
19
        $posX = 1;
20
        $posY = 3;
21
        $width = 2;
22
        $height = 4;
23
        $image = m::mock(Image::class);
24
        $canvas = m::mock(Image::class)
25
            ->shouldReceive('insert')
26
            ->with($image, 'top-left', (int) $posX, (int) $posY)
27
            ->once()
28
            ->getMock();
29
        $imageManager = m::mock(ImageManager::class)
30
            ->shouldReceive('canvas')
31
            ->with($width, $height, '#fff')
32
            ->once()
33
            ->andReturn($canvas)
34
            ->getMock();
35
36
        $xml = new SimpleXMLElement('<root/>');
37
38
        $fieldParser = m::mock(FieldParserInterface::class)
39
            ->shouldReceive('isDisplayed')
40
            ->andReturn(true)
41
            ->once()
42
            ->shouldReceive('getPositionX')
43
            ->andReturn($posX)
44
            ->once()
45
            ->shouldReceive('getPositionY')
46
            ->andReturn($posY)
47
            ->once()
48
            ->getMock();
49
50
        $parserDocument = m::mock(ParserDocument::class)
51
            ->shouldReceive('getFieldParsers')
52
            ->with($xml)
53
            ->andReturn([$fieldParser])
54
            ->once()
55
            ->shouldReceive('getWidth')
56
            ->with($xml)
57
            ->andReturn($width)
58
            ->once()
59
            ->shouldReceive('getHeight')
60
            ->andReturn($height)
61
            ->with($xml)
62
            ->once()
63
            ->getMock();
64
65
        $fontResolver = function () {}; // @codingStandardsIgnoreLine
66
        $graphicResolver = function () {}; // @codingStandardsIgnoreLine
67
        $fieldRenderer = m::mock(FieldRendererInterface::class)
68
            ->shouldReceive('render')
69
            ->with($imageManager, $fieldParser, $fontResolver, $graphicResolver)
70
            ->andReturn($image)
71
            ->once()
72
            ->getMock();
73
74
        $fieldRendererFactory = m::mock(FieldRendererFactory::class)
75
            ->shouldReceive('getFieldRenderer')
76
            ->with($fieldParser)
77
            ->andReturn($fieldRenderer)
78
            ->once()
79
            ->getMock();
80
81
        $rendererDocument = new RendererDocument(
82
            $parserDocument,
83
            $fieldRendererFactory,
84
            $imageManager
85
        );
86
87
        $imageActual = $rendererDocument->render($xml, $fontResolver, $graphicResolver);
88
89
        $this->assertSame($canvas, $imageActual);
90
    }
91
}
92