Code Duplication    Length = 59-61 lines in 3 locations

Tests/Imagine/Filter/FilterManagerTest.php 3 locations

@@ 45-104 (lines=60) @@
42
        $filterManager->applyFilter($binary, 'thumbnail');
43
    }
44
45
    public function testReturnFilteredBinaryWithExpectedContentOnApplyFilter()
46
    {
47
        $originalContent = 'aOriginalContent';
48
        $expectedFilteredContent = 'theFilteredContent';
49
50
        $binary = new Binary($originalContent, 'image/png', 'png');
51
52
        $thumbConfig = array(
53
            'size' => array(180, 180),
54
            'mode' => 'outbound',
55
        );
56
57
        $config = $this->createFilterConfigurationMock();
58
        $config
59
            ->expects($this->atLeastOnce())
60
            ->method('get')
61
            ->with('thumbnail')
62
            ->will($this->returnValue(array(
63
                'filters' => array(
64
                    'thumbnail' => $thumbConfig,
65
                ),
66
                'post_processors' => array(),
67
            )))
68
        ;
69
70
        $image = $this->getMockImage();
71
        $image
72
            ->expects($this->once())
73
            ->method('get')
74
            ->will($this->returnValue($expectedFilteredContent))
75
        ;
76
77
        $imagine = $this->createImagineMock();
78
        $imagine
79
            ->expects($this->once())
80
            ->method('load')
81
            ->with($originalContent)
82
            ->will($this->returnValue($image))
83
        ;
84
85
        $loader = $this->getMockLoader();
86
        $loader
87
            ->expects($this->once())
88
            ->method('load')
89
            ->with($this->identicalTo($image), $thumbConfig)
90
            ->will($this->returnArgument(0))
91
        ;
92
93
        $filterManager = new FilterManager(
94
            $config,
95
            $imagine,
96
            $this->getMockMimeTypeGuesser()
97
        );
98
        $filterManager->addLoader('thumbnail', $loader);
99
100
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
101
102
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
103
        $this->assertEquals($expectedFilteredContent, $filteredBinary->getContent());
104
    }
105
106
    public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApplyFilter()
107
    {
@@ 106-164 (lines=59) @@
103
        $this->assertEquals($expectedFilteredContent, $filteredBinary->getContent());
104
    }
105
106
    public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApplyFilter()
107
    {
108
        $originalContent = 'aOriginalContent';
109
        $expectedFormat = 'png';
110
111
        $binary = new Binary($originalContent, 'image/png', $expectedFormat);
112
113
        $thumbConfig = array(
114
            'size' => array(180, 180),
115
            'mode' => 'outbound',
116
        );
117
118
        $config = $this->createFilterConfigurationMock();
119
        $config
120
            ->expects($this->atLeastOnce())
121
            ->method('get')
122
            ->with('thumbnail')
123
            ->will($this->returnValue(array(
124
                'filters' => array(
125
                    'thumbnail' => $thumbConfig,
126
                ),
127
                'post_processors' => array(),
128
            )))
129
        ;
130
131
        $image = $this->getMockImage();
132
        $image
133
            ->expects($this->once())
134
            ->method('get')
135
            ->will($this->returnValue('aFilteredContent'))
136
        ;
137
138
        $imagine = $this->createImagineMock();
139
        $imagine
140
            ->expects($this->once())
141
            ->method('load')
142
            ->will($this->returnValue($image))
143
        ;
144
145
        $loader = $this->getMockLoader();
146
        $loader
147
            ->expects($this->once())
148
            ->method('load')
149
            ->with($this->identicalTo($image), $thumbConfig)
150
            ->will($this->returnArgument(0))
151
        ;
152
153
        $filterManager = new FilterManager(
154
            $config,
155
            $imagine,
156
            $this->getMockMimeTypeGuesser()
157
        );
158
        $filterManager->addLoader('thumbnail', $loader);
159
160
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
161
162
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
163
        $this->assertEquals($expectedFormat, $filteredBinary->getFormat());
164
    }
165
166
    public function testReturnFilteredBinaryWithCustomFormatIfSetOnApplyFilter()
167
    {
@@ 166-226 (lines=61) @@
163
        $this->assertEquals($expectedFormat, $filteredBinary->getFormat());
164
    }
165
166
    public function testReturnFilteredBinaryWithCustomFormatIfSetOnApplyFilter()
167
    {
168
        $originalContent = 'aOriginalContent';
169
        $originalFormat = 'png';
170
        $expectedFormat = 'jpg';
171
172
        $binary = new Binary($originalContent, 'image/png', $originalFormat);
173
174
        $thumbConfig = array(
175
            'size' => array(180, 180),
176
            'mode' => 'outbound',
177
        );
178
179
        $config = $this->createFilterConfigurationMock();
180
        $config
181
            ->expects($this->atLeastOnce())
182
            ->method('get')
183
            ->with('thumbnail')
184
            ->will($this->returnValue(array(
185
                'format' => $expectedFormat,
186
                'filters' => array(
187
                    'thumbnail' => $thumbConfig,
188
                ),
189
                'post_processors' => array(),
190
            )))
191
        ;
192
193
        $image = $this->getMockImage();
194
        $image
195
            ->expects($this->once())
196
            ->method('get')
197
            ->will($this->returnValue('aFilteredContent'))
198
        ;
199
200
        $imagine = $this->createImagineMock();
201
        $imagine
202
            ->expects($this->once())
203
            ->method('load')
204
            ->will($this->returnValue($image))
205
        ;
206
207
        $loader = $this->getMockLoader();
208
        $loader
209
            ->expects($this->once())
210
            ->method('load')
211
            ->with($this->identicalTo($image), $thumbConfig)
212
            ->will($this->returnArgument(0))
213
        ;
214
215
        $filterManager = new FilterManager(
216
            $config,
217
            $imagine,
218
            $this->getMockMimeTypeGuesser()
219
        );
220
        $filterManager->addLoader('thumbnail', $loader);
221
222
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
223
224
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
225
        $this->assertEquals($expectedFormat, $filteredBinary->getFormat());
226
    }
227
228
    public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApplyFilter()
229
    {