Completed
Push — refactor-04-parser-tests ( dc4950...bd4663 )
by John
06:06
created

RendererDocumentTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
lcom 0
cbo 5
dl 0
loc 71
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testRender() 0 68 1
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)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
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
        $parserDocument = m::mock(ParserDocument::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
48
            ->shouldReceive('getFieldParsers')
49
            ->andReturn([$fieldParser])
50
            ->once()
51
            ->shouldReceive('getWidth')
52
            ->andReturn($width)
53
            ->once()
54
            ->shouldReceive('getHeight')
55
            ->andReturn($height)
56
            ->once()
57
            ->getMock();
58
59
        $fontResolver = function () {}; // @codingStandardsIgnoreLine
60
        $graphicResolver = function () {}; // @codingStandardsIgnoreLine
61
        $fieldRenderer = m::mock(FieldRendererInterface::class)
62
            ->shouldReceive('render')
63
            ->with($imageManager, $fieldParser, $fontResolver, $graphicResolver)
64
            ->andReturn($image)
65
            ->once()
66
            ->getMock();
67
68
        $fieldRendererFactory = m::mock(FieldRendererFactory::class)
69
            ->shouldReceive('getFieldRenderer')
70
            ->with($fieldParser)
71
            ->andReturn($fieldRenderer)
72
            ->once()
73
            ->getMock();
74
75
        $rendererDocument = new RendererDocument(
76
            $fieldRendererFactory,
77
            $imageManager
78
        );
79
80
        $imageActual = $rendererDocument->render($parserDocument, $fontResolver, $graphicResolver);
81
82
        $this->assertSame($canvas, $imageActual);
83
    }
84
}
85