Completed
Pull Request — master (#19)
by John
05:56 queued 03:42
created

RendererDocumentTest::testRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 73
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 73
rs 9.0675
c 1
b 0
f 0
cc 1
eloc 63
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\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')
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')
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,
82
            $imageManager
83
        );
84
85
        $imageActual = $rendererDocument->render($xml, $fontResolver, $graphicResolver);
86
87
        $this->assertSame($canvas, $imageActual);
88
    }
89
}
90