|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Test\Unit\Renderer\FieldRenderer; |
|
4
|
|
|
|
|
5
|
|
|
use Mockery as m; |
|
6
|
|
|
use Intervention\Image\Gd\Font; |
|
7
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface; |
|
8
|
|
|
use Intervention\Image\Image; |
|
9
|
|
|
use Intervention\Image\ImageManager; |
|
10
|
|
|
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererBarcode; |
|
11
|
|
|
|
|
12
|
|
|
class FieldRendererBarcodeTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testRender() |
|
15
|
|
|
{ |
|
16
|
|
|
$text = 'i am text'; |
|
17
|
|
|
$size = 12; |
|
18
|
|
|
$width = 104; |
|
19
|
|
|
$height = 102; |
|
20
|
|
|
$path = '/path/to/font'; |
|
21
|
|
|
$font = m::mock(Font::class) |
|
22
|
|
|
->shouldReceive('file') |
|
23
|
|
|
->with($path) |
|
24
|
|
|
->once() |
|
25
|
|
|
->shouldReceive('size') |
|
26
|
|
|
->with($size * FieldRendererBarcode::FONT_SIZE_MULTIPLIER) |
|
27
|
|
|
->once() |
|
28
|
|
|
->shouldReceive('color') |
|
29
|
|
|
->with('#fff') |
|
30
|
|
|
->once() |
|
31
|
|
|
->shouldReceive('align') |
|
32
|
|
|
->with('center') |
|
33
|
|
|
->once() |
|
34
|
|
|
->shouldReceive('valign') |
|
35
|
|
|
->with('middle') |
|
36
|
|
|
->once() |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
$textExpectation = function ($actualClosure) use ($font) { |
|
39
|
|
|
$actualClosure($font); |
|
40
|
|
|
return true; |
|
41
|
|
|
}; |
|
42
|
|
|
|
|
43
|
|
|
$parser = m::mock(FieldParserInterface::class) |
|
44
|
|
|
->shouldReceive('getWidth') |
|
45
|
|
|
->andReturn($width) |
|
46
|
|
|
->twice() |
|
47
|
|
|
->shouldReceive('getHeight') |
|
48
|
|
|
->andReturn($height) |
|
49
|
|
|
->twice() |
|
50
|
|
|
->shouldReceive('getFontSize') |
|
51
|
|
|
->andReturn($size) |
|
52
|
|
|
->once() |
|
53
|
|
|
->shouldReceive('getText') |
|
54
|
|
|
->andReturn($text) |
|
55
|
|
|
->once() |
|
56
|
|
|
->getMock(); |
|
57
|
|
|
|
|
58
|
|
|
$image = m::mock(Image::class) |
|
59
|
|
|
->shouldReceive('text') |
|
60
|
|
|
->with($text, $width / 2, $height, m::on($textExpectation)) |
|
61
|
|
|
->shouldReceive('resize') |
|
62
|
|
|
->getMock(); |
|
63
|
|
|
|
|
64
|
|
|
$imageManager = m::mock(ImageManager::class) |
|
65
|
|
|
->shouldReceive('canvas') |
|
66
|
|
|
->with($width, $height, '#000') |
|
67
|
|
|
->andReturn($image) |
|
68
|
|
|
->getMock(); |
|
69
|
|
|
|
|
70
|
|
|
$fontResolver = function () use ($path) { |
|
71
|
|
|
return $path; |
|
72
|
|
|
}; |
|
73
|
|
|
|
|
74
|
|
|
$renderer = new FieldRendererBarcode(); |
|
75
|
|
|
$imageActual = $renderer->render( |
|
76
|
|
|
$imageManager, |
|
77
|
|
|
$parser, |
|
78
|
|
|
$fontResolver |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertSame($image, $imageActual); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|