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; |
|
|
|
|
23
|
|
|
$actualClosure($actualFont); |
24
|
|
|
|
25
|
|
|
return $actualFont->getText() == $text && $actualFont->getSize() == $fontSize; |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
$canvas = m::mock(Image::class) |
|
|
|
|
29
|
|
|
->shouldReceive('text') |
30
|
|
|
->with('', null, null, m::on($textExpectation)) |
31
|
|
|
->shouldReceive('resize') |
32
|
|
|
->shouldReceive('rotate') |
33
|
|
|
->with(360 - $orientation) |
34
|
|
|
->getMock(); |
35
|
|
|
|
36
|
|
|
$imageManager = m::mock(ImageManager::class) |
37
|
|
|
->shouldReceive('canvas') |
38
|
|
|
->with(m::type('int'), m::type('int'), $tracerColour) |
39
|
|
|
->andReturn($canvas) |
40
|
|
|
->getMock(); |
41
|
|
|
|
42
|
|
|
$renderer = m::mock(FixedTextRenderer::class) |
43
|
|
|
->shouldAllowMockingProtectedMethods() |
44
|
|
|
->shouldReceive('getImageManager') |
45
|
|
|
->andReturn($imageManager) |
46
|
|
|
->shouldReceive('getFontResolver') |
47
|
|
|
->andReturn($fontResolver) |
48
|
|
|
->shouldReceive('getFontFace') |
49
|
|
|
->shouldReceive('getFontSize') |
50
|
|
|
->andReturn($fontSize) |
51
|
|
|
->shouldReceive('getText') |
52
|
|
|
->andReturn($text) |
53
|
|
|
->shouldReceive('getOrientation') |
54
|
|
|
->andReturn($orientation) |
55
|
|
|
->shouldReceive('getTracerColour') |
56
|
|
|
->andReturn($tracerColour) |
57
|
|
|
->getMock() |
58
|
|
|
->makePartial(); |
59
|
|
|
|
60
|
|
|
$this->assertSame($canvas, $renderer->render()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.