1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Knp\Bundle\SnappyBundle\Tests\Snappy; |
4
|
|
|
|
5
|
|
|
use Knp\Bundle\SnappyBundle\Snappy\Generator\LoggableGenerator; |
6
|
|
|
|
7
|
|
|
class LoggableGeneratorTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testGenerate() |
10
|
|
|
{ |
11
|
|
|
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); |
12
|
|
|
$internal |
13
|
|
|
->expects($this->once()) |
14
|
|
|
->method('generate') |
15
|
|
|
->with( |
16
|
|
|
$this->equalTo('the_input_file'), |
17
|
|
|
$this->equalTo('the_output_file'), |
18
|
|
|
$this->equalTo(['foo' => 'bar']), |
19
|
|
|
$this->equalTo(true) |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
23
|
|
|
$logger |
24
|
|
|
->expects($this->once()) |
25
|
|
|
->method('debug') |
26
|
|
|
->with($this->equalTo('Generate from file (the_input_file) to file (the_output_file).')); |
27
|
|
|
|
28
|
|
|
$generator = new LoggableGenerator($internal, $logger); |
29
|
|
|
$generator->generate('the_input_file', 'the_output_file', ['foo' => 'bar'], true); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGenerateFromHtml() |
33
|
|
|
{ |
34
|
|
|
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); |
35
|
|
|
$internal |
36
|
|
|
->expects($this->once()) |
37
|
|
|
->method('generateFromHtml') |
38
|
|
|
->with( |
39
|
|
|
$this->equalTo('<html>foo</html>'), |
40
|
|
|
$this->equalTo('the_output_file'), |
41
|
|
|
$this->equalTo(['foo' => 'bar']), |
42
|
|
|
$this->equalTo(true) |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
46
|
|
|
$logger |
47
|
|
|
->expects($this->once()) |
48
|
|
|
->method('debug') |
49
|
|
|
->with($this->equalTo('Generate from HTML (<html>foo</html>) to file (the_output_file).')); |
50
|
|
|
|
51
|
|
|
$generator = new LoggableGenerator($internal, $logger); |
52
|
|
|
$generator->generateFromHtml('<html>foo</html>', 'the_output_file', ['foo' => 'bar'], true); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGenerateFromHtmlWithHtmlArray() |
56
|
|
|
{ |
57
|
|
|
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); |
58
|
|
|
$internal |
59
|
|
|
->expects($this->once()) |
60
|
|
|
->method('generateFromHtml') |
61
|
|
|
->with( |
62
|
|
|
$this->equalTo(['<html>foo</html>', '<html>bar</html>']), |
63
|
|
|
$this->equalTo('the_output_file'), |
64
|
|
|
$this->equalTo(['foo' => 'bar']), |
65
|
|
|
$this->equalTo(true) |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
69
|
|
|
$logger |
70
|
|
|
->expects($this->once()) |
71
|
|
|
->method('debug') |
72
|
|
|
->with($this->equalTo('Generate from HTML (<html>foo</html>, <html>bar</html>) to file (the_output_file).')); |
73
|
|
|
|
74
|
|
|
$generator = new LoggableGenerator($internal, $logger); |
75
|
|
|
$generator->generateFromHtml(['<html>foo</html>', '<html>bar</html>'], 'the_output_file', ['foo' => 'bar'], true); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testOutput() |
79
|
|
|
{ |
80
|
|
|
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); |
81
|
|
|
$internal |
82
|
|
|
->expects($this->once()) |
83
|
|
|
->method('getOutput') |
84
|
|
|
->with( |
85
|
|
|
$this->equalTo('the_input_file'), |
86
|
|
|
$this->equalTo(['foo' => 'bar']) |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
90
|
|
|
$logger |
91
|
|
|
->expects($this->once()) |
92
|
|
|
->method('debug') |
93
|
|
|
->with($this->equalTo('Output from file (the_input_file).')); |
94
|
|
|
|
95
|
|
|
$generator = new LoggableGenerator($internal, $logger); |
96
|
|
|
$generator->getOutput('the_input_file', ['foo' => 'bar'], true); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testOutputFromHtml() |
100
|
|
|
{ |
101
|
|
|
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); |
102
|
|
|
$internal |
103
|
|
|
->expects($this->once()) |
104
|
|
|
->method('getOutputFromHtml') |
105
|
|
|
->with( |
106
|
|
|
$this->equalTo('<html>foo</html>'), |
107
|
|
|
$this->equalTo(['foo' => 'bar']) |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
111
|
|
|
$logger |
112
|
|
|
->expects($this->once()) |
113
|
|
|
->method('debug') |
114
|
|
|
->with($this->equalTo('Output from HTML (<html>foo</html>).')); |
115
|
|
|
|
116
|
|
|
$generator = new LoggableGenerator($internal, $logger); |
117
|
|
|
$generator->getOutputFromHtml('<html>foo</html>', ['foo' => 'bar'], true); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testOutputFromHtmlWithHtmlArray() |
121
|
|
|
{ |
122
|
|
|
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); |
123
|
|
|
$internal |
124
|
|
|
->expects($this->once()) |
125
|
|
|
->method('getOutputFromHtml') |
126
|
|
|
->with( |
127
|
|
|
$this->equalTo(['<html>foo</html>']), |
128
|
|
|
$this->equalTo(['foo' => 'bar']) |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
132
|
|
|
$logger |
133
|
|
|
->expects($this->once()) |
134
|
|
|
->method('debug') |
135
|
|
|
->with($this->equalTo('Output from HTML (<html>foo</html>).')); |
136
|
|
|
|
137
|
|
|
$generator = new LoggableGenerator($internal, $logger); |
138
|
|
|
$generator->getOutputFromHtml(['<html>foo</html>'], ['foo' => 'bar'], true); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testSetOption() |
142
|
|
|
{ |
143
|
|
|
$internal = $this->getMock('Knp\Snappy\Image'); |
144
|
|
|
$internal |
145
|
|
|
->expects($this->at(0)) |
146
|
|
|
->method('setOption') |
147
|
|
|
->with( |
148
|
|
|
$this->equalTo('foo'), |
149
|
|
|
$this->equalTo('bar') |
150
|
|
|
); |
151
|
|
|
$internal |
152
|
|
|
->expects($this->at(1)) |
153
|
|
|
->method('setOption') |
154
|
|
|
->with( |
155
|
|
|
$this->equalTo('foo'), |
156
|
|
|
$this->equalTo(['bar'=>'baz']) |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
160
|
|
|
$logger |
161
|
|
|
->expects($this->at(0)) |
162
|
|
|
->method('debug') |
163
|
|
|
->with($this->equalTo('Set option foo = \'bar\'.')); |
164
|
|
|
$logger |
165
|
|
|
->expects($this->at(1)) |
166
|
|
|
->method('debug') |
167
|
|
|
->with($this->equalTo( |
168
|
|
|
'Set option foo = array ( |
169
|
|
|
\'bar\' => \'baz\', |
170
|
|
|
).' |
171
|
|
|
)); |
172
|
|
|
|
173
|
|
|
$generator = new LoggableGenerator($internal, $logger); |
174
|
|
|
$generator->setOption('foo', 'bar'); |
175
|
|
|
$generator->setOption('foo', ['bar'=>'baz']); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.