Completed
Pull Request — master (#170)
by Albin
07:01
created

LoggableGeneratorTest::testGenerateFromHtml()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace Knp\Bundle\SnappyBundle\Tests\Snappy;
4
5
use Knp\Bundle\SnappyBundle\Snappy\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(array('foo' => 'bar')),
19
                $this->equalTo(true)
20
            )
21
        ;
22
23
        $logger = $this->getMock('Psr\Log\LoggerInterface');
24
        $logger
25
            ->expects($this->once())
26
            ->method('debug')
27
            ->with($this->equalTo('Generate from file (the_input_file) to file (the_output_file).'))
28
        ;
29
30
        $generator = new LoggableGenerator($internal, $logger);
31
        $generator->generate('the_input_file', 'the_output_file', array('foo' => 'bar'), true);
32
    }
33
34
    public function testGenerateFromHtml()
35
    {
36
        $internal = $this->getMock('Knp\Snappy\GeneratorInterface');
37
        $internal
38
            ->expects($this->once())
39
            ->method('generateFromHtml')
40
            ->with(
41
                $this->equalTo('<html>foo</html>'),
42
                $this->equalTo('the_output_file'),
43
                $this->equalTo(array('foo' => 'bar')),
44
                $this->equalTo(true)
45
            )
46
        ;
47
48
        $logger = $this->getMock('Psr\Log\LoggerInterface');
49
        $logger
50
            ->expects($this->once())
51
            ->method('debug')
52
            ->with($this->equalTo('Generate from HTML (<html>foo</html>) to file (the_output_file).'))
53
        ;
54
55
        $generator = new LoggableGenerator($internal, $logger);
56
        $generator->generateFromHtml('<html>foo</html>', 'the_output_file', array('foo' => 'bar'), true);
57
    }
58
59
    public function testGenerateFromHtmlWithHtmlArray()
60
    {
61
        $internal = $this->getMock('Knp\Snappy\GeneratorInterface');
62
        $internal
63
            ->expects($this->once())
64
            ->method('generateFromHtml')
65
            ->with(
66
                $this->equalTo(array('<html>foo</html>', '<html>bar</html>')),
67
                $this->equalTo('the_output_file'),
68
                $this->equalTo(array('foo' => 'bar')),
69
                $this->equalTo(true)
70
            )
71
        ;
72
73
        $logger = $this->getMock('Psr\Log\LoggerInterface');
74
        $logger
75
            ->expects($this->once())
76
            ->method('debug')
77
            ->with($this->equalTo('Generate from HTML (<html>foo</html>, <html>bar</html>) to file (the_output_file).'))
78
        ;
79
80
        $generator = new LoggableGenerator($internal, $logger);
81
        $generator->generateFromHtml(array('<html>foo</html>', '<html>bar</html>'), 'the_output_file', array('foo' => 'bar'), true);
82
    }
83
84
    public function testOutput()
85
    {
86
        $internal = $this->getMock('Knp\Snappy\GeneratorInterface');
87
        $internal
88
            ->expects($this->once())
89
            ->method('getOutput')
90
            ->with(
91
                $this->equalTo('the_input_file'),
92
                $this->equalTo(array('foo' => 'bar'))
93
            )
94
        ;
95
96
        $logger = $this->getMock('Psr\Log\LoggerInterface');
97
        $logger
98
            ->expects($this->once())
99
            ->method('debug')
100
            ->with($this->equalTo('Output from file (the_input_file).'))
101
        ;
102
103
        $generator = new LoggableGenerator($internal, $logger);
104
        $generator->getOutput('the_input_file', array('foo' => 'bar'), true);
0 ignored issues
show
Unused Code introduced by
The call to LoggableGenerator::getOutput() has too many arguments starting with true.

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.

Loading history...
105
    }
106
107
    public function testOutputFromHtml()
108
    {
109
        $internal = $this->getMock('Knp\Snappy\GeneratorInterface');
110
        $internal
111
            ->expects($this->once())
112
            ->method('getOutputFromHtml')
113
            ->with(
114
                $this->equalTo('<html>foo</html>'),
115
                $this->equalTo(array('foo' => 'bar'))
116
            )
117
        ;
118
119
        $logger = $this->getMock('Psr\Log\LoggerInterface');
120
        $logger
121
            ->expects($this->once())
122
            ->method('debug')
123
            ->with($this->equalTo('Output from HTML (<html>foo</html>).'))
124
        ;
125
126
        $generator = new LoggableGenerator($internal, $logger);
127
        $generator->getOutputFromHtml('<html>foo</html>', array('foo' => 'bar'), true);
0 ignored issues
show
Unused Code introduced by
The call to LoggableGenerator::getOutputFromHtml() has too many arguments starting with true.

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.

Loading history...
128
    }
129
130
    public function testOutputFromHtmlWithHtmlArray()
131
    {
132
        $internal = $this->getMock('Knp\Snappy\GeneratorInterface');
133
        $internal
134
            ->expects($this->once())
135
            ->method('getOutputFromHtml')
136
            ->with(
137
                $this->equalTo(array('<html>foo</html>')),
138
                $this->equalTo(array('foo' => 'bar'))
139
            )
140
        ;
141
142
        $logger = $this->getMock('Psr\Log\LoggerInterface');
143
        $logger
144
            ->expects($this->once())
145
            ->method('debug')
146
            ->with($this->equalTo('Output from HTML (<html>foo</html>).'))
147
        ;
148
149
        $generator = new LoggableGenerator($internal, $logger);
150
        $generator->getOutputFromHtml(array('<html>foo</html>'), array('foo' => 'bar'), true);
0 ignored issues
show
Unused Code introduced by
The call to LoggableGenerator::getOutputFromHtml() has too many arguments starting with true.

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.

Loading history...
151
    }
152
153
    public function testSetOption()
154
    {
155
        $internal = $this->getMock('Knp\Snappy\Image');
156
        $internal
157
            ->expects($this->at(0))
158
            ->method('setOption')
159
            ->with(
160
                $this->equalTo('foo'),
161
                $this->equalTo('bar')
162
            )
163
        ;
164
        $internal
165
            ->expects($this->at(1))
166
            ->method('setOption')
167
            ->with(
168
                $this->equalTo('foo'),
169
                $this->equalTo(array('bar'=>'baz'))
170
            )
171
        ;
172
173
        $logger = $this->getMock('Psr\Log\LoggerInterface');
174
        $logger
175
            ->expects($this->at(0))
176
            ->method('debug')
177
            ->with($this->equalTo('Set option foo = \'bar\'.'))
178
        ;
179
        $logger
180
            ->expects($this->at(1))
181
            ->method('debug')
182
            ->with($this->equalTo(
183
'Set option foo = array (
184
  \'bar\' => \'baz\',
185
).'
186
            ))
187
        ;
188
189
        $generator = new LoggableGenerator($internal, $logger);
190
        $generator->setOption('foo', 'bar');
191
        $generator->setOption('foo', array('bar'=>'baz'));
192
    }
193
}
194