LoggableGeneratorTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 171
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGenerate() 0 22 1
A testGenerateFromHtml() 0 22 1
A testGenerateFromHtmlWithHtmlArray() 0 22 1
A testOutput() 0 20 1
A testOutputFromHtml() 0 20 1
A testOutputFromHtmlWithHtmlArray() 0 20 1
A testSetOption() 0 36 1
1
<?php
2
3
namespace Knp\Bundle\SnappyBundle\Tests\Snappy\Generator;
4
5
use Knp\Bundle\SnappyBundle\Snappy\Generator\LoggableGenerator;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * @group legacy
10
 */
11
class LoggableGeneratorTest extends TestCase
12
{
13
    public function testGenerate()
14
    {
15
        $internal = $this->createMock('Knp\Snappy\GeneratorInterface');
16
        $internal
17
            ->expects($this->once())
18
            ->method('generate')
19
            ->with(
20
                $this->equalTo('the_input_file'),
21
                $this->equalTo('the_output_file'),
22
                $this->equalTo(['foo' => 'bar']),
23
                $this->equalTo(true)
24
            );
25
26
        $logger = $this->createMock('Psr\Log\LoggerInterface');
27
        $logger
28
            ->expects($this->once())
29
            ->method('debug')
30
            ->with($this->equalTo('Generate from file (the_input_file) to file (the_output_file).'));
31
32
        $generator = new LoggableGenerator($internal, $logger);
0 ignored issues
show
Deprecated Code introduced by
The class Knp\Bundle\SnappyBundle\...rator\LoggableGenerator has been deprecated with message: Logging capability is now directly integrated in Snappy. You should use it rather than this Decorator.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
33
        $generator->generate('the_input_file', 'the_output_file', ['foo' => 'bar'], true);
34
    }
35
36
    public function testGenerateFromHtml()
37
    {
38
        $internal = $this->createMock('Knp\Snappy\GeneratorInterface');
39
        $internal
40
            ->expects($this->once())
41
            ->method('generateFromHtml')
42
            ->with(
43
                $this->equalTo('<html>foo</html>'),
44
                $this->equalTo('the_output_file'),
45
                $this->equalTo(['foo' => 'bar']),
46
                $this->equalTo(true)
47
            );
48
49
        $logger = $this->createMock('Psr\Log\LoggerInterface');
50
        $logger
51
            ->expects($this->once())
52
            ->method('debug')
53
            ->with($this->equalTo('Generate from HTML (<html>foo</html>) to file (the_output_file).'));
54
55
        $generator = new LoggableGenerator($internal, $logger);
0 ignored issues
show
Deprecated Code introduced by
The class Knp\Bundle\SnappyBundle\...rator\LoggableGenerator has been deprecated with message: Logging capability is now directly integrated in Snappy. You should use it rather than this Decorator.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
56
        $generator->generateFromHtml('<html>foo</html>', 'the_output_file', ['foo' => 'bar'], true);
57
    }
58
59
    public function testGenerateFromHtmlWithHtmlArray()
60
    {
61
        $internal = $this->createMock('Knp\Snappy\GeneratorInterface');
62
        $internal
63
            ->expects($this->once())
64
            ->method('generateFromHtml')
65
            ->with(
66
                $this->equalTo(['<html>foo</html>', '<html>bar</html>']),
67
                $this->equalTo('the_output_file'),
68
                $this->equalTo(['foo' => 'bar']),
69
                $this->equalTo(true)
70
            );
71
72
        $logger = $this->createMock('Psr\Log\LoggerInterface');
73
        $logger
74
            ->expects($this->once())
75
            ->method('debug')
76
            ->with($this->equalTo('Generate from HTML (<html>foo</html>, <html>bar</html>) to file (the_output_file).'));
77
78
        $generator = new LoggableGenerator($internal, $logger);
0 ignored issues
show
Deprecated Code introduced by
The class Knp\Bundle\SnappyBundle\...rator\LoggableGenerator has been deprecated with message: Logging capability is now directly integrated in Snappy. You should use it rather than this Decorator.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
79
        $generator->generateFromHtml(['<html>foo</html>', '<html>bar</html>'], 'the_output_file', ['foo' => 'bar'], true);
80
    }
81
82
    public function testOutput()
83
    {
84
        $internal = $this->createMock('Knp\Snappy\GeneratorInterface');
85
        $internal
86
            ->expects($this->once())
87
            ->method('getOutput')
88
            ->with(
89
                $this->equalTo('the_input_file'),
90
                $this->equalTo(['foo' => 'bar'])
91
            );
92
93
        $logger = $this->createMock('Psr\Log\LoggerInterface');
94
        $logger
95
            ->expects($this->once())
96
            ->method('debug')
97
            ->with($this->equalTo('Output from file (the_input_file).'));
98
99
        $generator = new LoggableGenerator($internal, $logger);
0 ignored issues
show
Deprecated Code introduced by
The class Knp\Bundle\SnappyBundle\...rator\LoggableGenerator has been deprecated with message: Logging capability is now directly integrated in Snappy. You should use it rather than this Decorator.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
100
        $generator->getOutput('the_input_file', ['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...
101
    }
102
103
    public function testOutputFromHtml()
104
    {
105
        $internal = $this->createMock('Knp\Snappy\GeneratorInterface');
106
        $internal
107
            ->expects($this->once())
108
            ->method('getOutputFromHtml')
109
            ->with(
110
                $this->equalTo('<html>foo</html>'),
111
                $this->equalTo(['foo' => 'bar'])
112
            );
113
114
        $logger = $this->createMock('Psr\Log\LoggerInterface');
115
        $logger
116
            ->expects($this->once())
117
            ->method('debug')
118
            ->with($this->equalTo('Output from HTML (<html>foo</html>).'));
119
120
        $generator = new LoggableGenerator($internal, $logger);
0 ignored issues
show
Deprecated Code introduced by
The class Knp\Bundle\SnappyBundle\...rator\LoggableGenerator has been deprecated with message: Logging capability is now directly integrated in Snappy. You should use it rather than this Decorator.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
121
        $generator->getOutputFromHtml('<html>foo</html>', ['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...
122
    }
123
124
    public function testOutputFromHtmlWithHtmlArray()
125
    {
126
        $internal = $this->createMock('Knp\Snappy\GeneratorInterface');
127
        $internal
128
            ->expects($this->once())
129
            ->method('getOutputFromHtml')
130
            ->with(
131
                $this->equalTo(['<html>foo</html>']),
132
                $this->equalTo(['foo' => 'bar'])
133
            );
134
135
        $logger = $this->createMock('Psr\Log\LoggerInterface');
136
        $logger
137
            ->expects($this->once())
138
            ->method('debug')
139
            ->with($this->equalTo('Output from HTML (<html>foo</html>).'));
140
141
        $generator = new LoggableGenerator($internal, $logger);
0 ignored issues
show
Deprecated Code introduced by
The class Knp\Bundle\SnappyBundle\...rator\LoggableGenerator has been deprecated with message: Logging capability is now directly integrated in Snappy. You should use it rather than this Decorator.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
142
        $generator->getOutputFromHtml(['<html>foo</html>'], ['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...
143
    }
144
145
    public function testSetOption()
146
    {
147
        $internal = $this->createMock('Knp\Snappy\Image');
148
        $internal
149
            ->expects($this->at(0))
150
            ->method('setOption')
151
            ->with(
152
                $this->equalTo('foo'),
153
                $this->equalTo('bar')
154
            );
155
        $internal
156
            ->expects($this->at(1))
157
            ->method('setOption')
158
            ->with(
159
                $this->equalTo('foo'),
160
                $this->equalTo(['bar'=>'baz'])
161
            );
162
163
        $logger = $this->createMock('Psr\Log\LoggerInterface');
164
        $logger
165
            ->expects($this->at(0))
166
            ->method('debug')
167
            ->with($this->equalTo('Set option foo = \'bar\'.'));
168
        $logger
169
            ->expects($this->at(1))
170
            ->method('debug')
171
            ->with($this->equalTo(
172
                'Set option foo = array (
173
  \'bar\' => \'baz\',
174
).'
175
            ));
176
177
        $generator = new LoggableGenerator($internal, $logger);
0 ignored issues
show
Deprecated Code introduced by
The class Knp\Bundle\SnappyBundle\...rator\LoggableGenerator has been deprecated with message: Logging capability is now directly integrated in Snappy. You should use it rather than this Decorator.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
178
        $generator->setOption('foo', 'bar');
179
        $generator->setOption('foo', ['bar'=>'baz']);
180
    }
181
}
182