|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Christian Gripp <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Core23\DompdfBundle\Tests\Wrapper; |
|
11
|
|
|
|
|
12
|
|
|
use Core23\DompdfBundle\Factory\DompdfFactory; |
|
13
|
|
|
use Core23\DompdfBundle\Factory\DompdfFactoryInterface; |
|
14
|
|
|
use Core23\DompdfBundle\Wrapper\DompdfWrapper; |
|
15
|
|
|
use Dompdf\Dompdf; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class DompdfWrapperTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|DompdfFactory |
|
22
|
|
|
*/ |
|
23
|
|
|
private $dompdfFactory; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var DompdfWrapper |
|
27
|
|
|
*/ |
|
28
|
|
|
private $dompdfWrapper; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|Dompdf |
|
32
|
|
|
*/ |
|
33
|
|
|
private $dompdf; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function setUp() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->dompdf = $this->createMock(Dompdf::class); |
|
41
|
|
|
$this->dompdfFactory = $this->createMock(DompdfFactoryInterface::class); |
|
42
|
|
|
|
|
43
|
|
|
$this->dompdfWrapper = new DompdfWrapper($this->dompdfFactory); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
public function testStreamHtml() |
|
47
|
|
|
{ |
|
48
|
|
|
$input = "<h1>Foo</h1>Bar <b>baz</b><img src='img/foo'>"; |
|
49
|
|
|
|
|
50
|
|
|
$this->dompdfFactory->expects($this->any()) |
|
|
|
|
|
|
51
|
|
|
->method('create') |
|
52
|
|
|
->will($this->returnValue($this->dompdf)); |
|
53
|
|
|
|
|
54
|
|
|
$this->dompdf->expects($this->once()) |
|
55
|
|
|
->method('loadHtml') |
|
56
|
|
|
->with($this->equalTo($input)); |
|
57
|
|
|
$this->dompdf->expects($this->once()) |
|
58
|
|
|
->method('render'); |
|
59
|
|
|
$this->dompdf->expects($this->once()) |
|
60
|
|
|
->method('stream') |
|
61
|
|
|
->with($this->equalTo('file.pdf')); |
|
62
|
|
|
|
|
63
|
|
|
$this->dompdfWrapper->streamHtml($input, 'file.pdf'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testStreamHtmlWithImg() |
|
67
|
|
|
{ |
|
68
|
|
|
$input = "<h1>Foo</h1>Bar <b>baz</b><img src='img/foo'>"; |
|
69
|
|
|
$output = "<h1>Foo</h1>Bar <b>baz</b><img src='img/foo'>"; |
|
70
|
|
|
|
|
71
|
|
|
$this->dompdfFactory->expects($this->any()) |
|
|
|
|
|
|
72
|
|
|
->method('create') |
|
73
|
|
|
->with($this->equalTo(array('tempDir' => 'bar'))) |
|
74
|
|
|
->will($this->returnValue($this->dompdf)); |
|
75
|
|
|
|
|
76
|
|
|
$this->dompdf->expects($this->once()) |
|
77
|
|
|
->method('loadHtml') |
|
78
|
|
|
->with($this->equalTo($output)); |
|
79
|
|
|
$this->dompdf->expects($this->once()) |
|
80
|
|
|
->method('render'); |
|
81
|
|
|
$this->dompdf->expects($this->once()) |
|
82
|
|
|
->method('stream') |
|
83
|
|
|
->with($this->equalTo('file.pdf')); |
|
84
|
|
|
|
|
85
|
|
|
$this->dompdfWrapper->streamHtml($input, 'file.pdf', array('tempDir' => 'bar')); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
View Code Duplication |
public function testGetPdf() |
|
89
|
|
|
{ |
|
90
|
|
|
$input = "<h1>Foo</h1>Bar <b>baz</b><img src='img/foo'>"; |
|
91
|
|
|
|
|
92
|
|
|
$this->dompdfFactory->expects($this->any()) |
|
|
|
|
|
|
93
|
|
|
->method('create') |
|
94
|
|
|
->will($this->returnValue($this->dompdf)); |
|
95
|
|
|
|
|
96
|
|
|
$this->dompdf->expects($this->once()) |
|
97
|
|
|
->method('loadHtml') |
|
98
|
|
|
->with($this->equalTo($input)); |
|
99
|
|
|
$this->dompdf->expects($this->once()) |
|
100
|
|
|
->method('render'); |
|
101
|
|
|
$this->dompdf->expects($this->once()) |
|
102
|
|
|
->method('output') |
|
103
|
|
|
->willReturn('BINARY_CONTENT'); |
|
104
|
|
|
|
|
105
|
|
|
$this->dompdfWrapper->getPdf($input, array('tempDir' => 'bar')); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: