|
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; |
|
|
|
|
|
|
25
|
|
|
}; |
|
26
|
|
|
|
|
27
|
|
|
$canvasWidth = 12345; |
|
28
|
|
|
$canvasHeight = 54321; |
|
29
|
|
|
|
|
30
|
|
|
$imageText = m::mock(Image::class) |
|
31
|
|
|
->shouldReceive('text') |
|
|
|
|
|
|
32
|
|
|
->with('', null, null, m::on($textExpectation)) |
|
33
|
|
|
->shouldReceive('resize') |
|
|
|
|
|
|
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
|
|
|
|
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.