|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Test\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Mockery as m; |
|
6
|
|
|
use Graze\CiffRenderer\Renderer\RendererDocument; |
|
7
|
|
|
use Graze\CiffRenderer\CiffRenderer; |
|
8
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
9
|
|
|
use Intervention\Image\Image; |
|
10
|
|
|
|
|
11
|
|
|
class CiffRendererTest extends \PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
private $xmlString = '<xml/>'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var Image |
|
20
|
|
|
*/ |
|
21
|
|
|
private $imageExpected; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Filesystem |
|
25
|
|
|
*/ |
|
26
|
|
|
private $filesystem; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var CiffRenderer |
|
30
|
|
|
*/ |
|
31
|
|
|
private $ciffRenderer; |
|
32
|
|
|
|
|
33
|
|
|
public function setUp() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->imageExpected = m::mock(Image::class); |
|
|
|
|
|
|
36
|
|
|
$this->filesystem = m::mock(Filesystem::class); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$fontResolver = function () {}; // @codingStandardsIgnoreLine |
|
39
|
|
|
$graphicResolver = function () {}; // @codingStandardsIgnoreLine |
|
40
|
|
|
$argumentValidator = function (\SimpleXMLElement $xmlActual) { |
|
41
|
|
|
return (string) new \SimpleXMLElement($this->xmlString) == (string) $xmlActual; |
|
42
|
|
|
}; |
|
43
|
|
|
$rendererDocument = m::mock(RendererDocument::class) |
|
44
|
|
|
->shouldReceive('render') |
|
|
|
|
|
|
45
|
|
|
->with(m::on($argumentValidator), $fontResolver, $graphicResolver) |
|
46
|
|
|
->andReturn($this->imageExpected) |
|
47
|
|
|
->once() |
|
48
|
|
|
->getMock(); |
|
49
|
|
|
|
|
50
|
|
|
$this->ciffRenderer = new CiffRenderer($this->filesystem, $rendererDocument); |
|
|
|
|
|
|
51
|
|
|
$this->ciffRenderer->setFontResolver($fontResolver); |
|
52
|
|
|
$this->ciffRenderer->setGraphicResolver($graphicResolver); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testRenderFile() |
|
56
|
|
|
{ |
|
57
|
|
|
$path = '/path/to/file'; |
|
58
|
|
|
$this->filesystem |
|
59
|
|
|
->shouldReceive('get') |
|
60
|
|
|
->with($path) |
|
61
|
|
|
->andReturn($this->xmlString) |
|
62
|
|
|
->once() |
|
63
|
|
|
->getMock(); |
|
64
|
|
|
|
|
65
|
|
|
$imageActual = $this->ciffRenderer->renderFile($path); |
|
66
|
|
|
$this->assertSame($this->imageExpected, $imageActual); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testRenderString() |
|
70
|
|
|
{ |
|
71
|
|
|
$imageActual = $this->ciffRenderer->renderString($this->xmlString); |
|
72
|
|
|
$this->assertSame($this->imageExpected, $imageActual); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..