Completed
Pull Request — master (#21)
by Chad
01:06
created

ImageTest::resizeLargeBoxWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TraderInteractive\Util;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Util\Image
9
 */
10
final class ImageTest extends TestCase
11
{
12
    private $sourceFilesDir;
13
    private $tempDir;
14
15
    public function setUp()
16
    {
17
        $this->sourceFilesDir = __DIR__ . '/_files';
18
        $this->tempDir = sys_get_temp_dir() . '/imageUtilTest';
19
        if (is_dir($this->tempDir)) {
20
            foreach (glob("{$this->tempDir}/*") as $file) {
21
                unlink($file);
22
            }
23
24
            rmdir($this->tempDir);
25
        }
26
    }
27
28
    /**
29
     * Downsize ratio 2.0 to 0.25
30
     *
31
     * @test
32
     * @covers ::resize
33
     * @covers ::resizeMulti
34
     */
35
    public function resizeDownsizeToMoreVerticalAspect()
36
    {
37
        $source = new \Imagick('pattern:gray0');
38
        $source->scaleImage(100, 50);
39
40
        $imagick = Image::resize($source, 10, 40, ['color' => 'white', 'maxWidth' => 10000, 'maxHeight' => 10000]);
41
42
        //making sure source didnt resize
43
        $this->assertSame(100, $source->getImageWidth());
44
        $this->assertSame(50, $source->getImageHeight());
45
46
        $this->assertSame(10, $imagick->getImageWidth());
47
        $this->assertSame(40, $imagick->getImageHeight());
48
49
        $whiteBarTop = $imagick->getImagePixelColor(4, 16)->getHsl();
50
        $whiteBarBottom = $imagick->getImagePixelColor(4, 22)->getHsl();
51
52
        $imageLeft = $imagick->getImagePixelColor(0, 19)->getHsl();
53
        $imageRight = $imagick->getImagePixelColor(9, 19)->getHsl();
54
        $imageTop = $imagick->getImagePixelColor(4, 17)->getHsl();
55
        $imageBottom = $imagick->getImagePixelColor(4, 21)->getHsl();
56
57
        $this->assertGreaterThan(0.9, $whiteBarTop['luminosity']);
58
        $this->assertGreaterThan(0.9, $whiteBarBottom['luminosity']);
59
60
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
61
        $this->assertLessThan(0.1, $imageRight['luminosity']);
62
        $this->assertLessThan(0.1, $imageTop['luminosity']);
63
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
64
    }
65
66
    /**
67
     * Downsize ratio 2.0 to 4.0
68
     *
69
     * @test
70
     * @covers ::resize
71
     * @covers ::resizeMulti
72
     */
73 View Code Duplication
    public function resizeDownsizeToMoreHorizontalAspect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $source = new \Imagick('pattern:gray0');
76
        $source->scaleImage(100, 50);
77
78
        $imagick = Image::resize($source, 40, 10);
79
80
        //making sure source didnt resize
81
        $this->assertSame(100, $source->getImageWidth());
82
        $this->assertSame(50, $source->getImageHeight());
83
84
        $this->assertSame(40, $imagick->getImageWidth());
85
        $this->assertSame(10, $imagick->getImageHeight());
86
87
        $whiteBarLeft = $imagick->getImagePixelColor(9, 4)->getHsl();
88
        $whiteBarRight = $imagick->getImagePixelColor(30, 4)->getHsl();
89
90
        $imageLeft = $imagick->getImagePixelColor(10, 4)->getHsl();
91
        $imageRight = $imagick->getImagePixelColor(29, 4)->getHsl();
92
        $imageTop = $imagick->getImagePixelColor(19, 0)->getHsl();
93
        $imageBottom = $imagick->getImagePixelColor(19, 9)->getHsl();
94
95
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
96
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
97
98
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
99
        $this->assertLessThan(0.1, $imageRight['luminosity']);
100
        $this->assertLessThan(0.1, $imageTop['luminosity']);
101
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
102
    }
103
104
    /**
105
     * Upsize ratio 2.0 to 4.0
106
     *
107
     * @test
108
     * @covers ::resize
109
     * @covers ::resizeMulti
110
     */
111 View Code Duplication
    public function resizeUpsizeToMoreHorizontalAspectWithoutGrow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        $source = new \Imagick('pattern:gray0');
114
        $source->scaleImage(100, 50);
115
116
        $imagick = Image::resize($source, 400, 100);
117
118
        //making sure source didnt resize
119
        $this->assertSame(100, $source->getImageWidth());
120
        $this->assertSame(50, $source->getImageHeight());
121
122
        $this->assertSame(400, $imagick->getImageWidth());
123
        $this->assertSame(100, $imagick->getImageHeight());
124
125
        $whiteBarLeft = $imagick->getImagePixelColor(99, 49)->getHsl();
126
        $whiteBarRight = $imagick->getImagePixelColor(300, 49)->getHsl();
127
128
        $imageTop = $imagick->getImagePixelColor(200, 26)->getHsl();
129
        $imageBottom = $imagick->getImagePixelColor(200, 74)->getHsl();
130
        $imageLeft = $imagick->getImagePixelColor(151, 50)->getHsl();
131
        $imageRight = $imagick->getImagePixelColor(249, 50)->getHsl();
132
133
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
134
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
135
136
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
137
        $this->assertLessThan(0.1, $imageRight['luminosity']);
138
        $this->assertLessThan(0.1, $imageTop['luminosity']);
139
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
140
    }
141
142
    /**
143
     * Upsize ratio 2.0 to 4.0
144
     *
145
     * @test
146
     * @covers ::resize
147
     * @covers ::resizeMulti
148
     */
149 View Code Duplication
    public function resizeUpsizeToMoreHorizontalAspectWithGrow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
    {
151
        $source = new \Imagick('pattern:gray0');
152
        $source->scaleImage(100, 50);
153
154
        $imagick = Image::resize($source, 400, 100, ['upsize' => true]);
155
156
        //making sure source didnt resize
157
        $this->assertSame(100, $source->getImageWidth());
158
        $this->assertSame(50, $source->getImageHeight());
159
160
        $this->assertSame(400, $imagick->getImageWidth());
161
        $this->assertSame(100, $imagick->getImageHeight());
162
163
        $whiteBarLeft = $imagick->getImagePixelColor(99, 49)->getHsl();
164
        $whiteBarRight = $imagick->getImagePixelColor(300, 49)->getHsl();
165
166
        $imageTop = $imagick->getImagePixelColor(249, 0)->getHsl();
167
        $imageBottom = $imagick->getImagePixelColor(249, 99)->getHsl();
168
        $imageLeft = $imagick->getImagePixelColor(100, 49)->getHsl();
169
        $imageRight = $imagick->getImagePixelColor(299, 49)->getHsl();
170
171
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
172
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
173
174
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
175
        $this->assertLessThan(0.1, $imageRight['luminosity']);
176
        $this->assertLessThan(0.1, $imageTop['luminosity']);
177
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
178
    }
179
180
    /**
181
     * Upsize ratio 2.0 to 4.0
182
     *
183
     * @test
184
     * @covers ::resize
185
     * @covers ::resizeMulti
186
     */
187 View Code Duplication
    public function resizeUpsizeToMoreVerticalAspect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
188
    {
189
        $source = new \Imagick('pattern:gray0');
190
        $source->scaleImage(100, 50);
191
192
        $imagick = Image::resize($source, 200, 400);
193
194
        //making sure source didnt resize
195
        $this->assertSame(100, $source->getImageWidth());
196
        $this->assertSame(50, $source->getImageHeight());
197
198
        $this->assertSame(200, $imagick->getImageWidth());
199
        $this->assertSame(400, $imagick->getImageHeight());
200
201
        $whiteBarLeft = $imagick->getImagePixelColor(49, 200)->getHsl();
202
        $whiteBarRight = $imagick->getImagePixelColor(151, 200)->getHsl();
203
204
        $imageTop = $imagick->getImagePixelColor(100, 176)->getHsl();
205
        $imageBottom = $imagick->getImagePixelColor(100, 224)->getHsl();
206
        $imageLeft = $imagick->getImagePixelColor(51, 200)->getHsl();
207
        $imageRight = $imagick->getImagePixelColor(149, 200)->getHsl();
208
209
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
210
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
211
212
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
213
        $this->assertLessThan(0.1, $imageRight['luminosity']);
214
        $this->assertLessThan(0.1, $imageTop['luminosity']);
215
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
216
    }
217
218
    /**
219
     * @test
220
     * @covers ::resize
221
     * @covers ::resizeMulti
222
     */
223
    public function resizeWithUpsizeAndBestFit()
224
    {
225
        $source = new \Imagick('pattern:gray0');
226
        $source->scaleImage(85, 45);
227
        $notBestFit = Image::resize($source, 300, 300, ['upsize' => true, 'bestfit' => false]);
228
        $this->assertSame('srgb(0,0,0)', $notBestFit->getImagePixelColor(299, 100)->getColorAsString());
229
        $bestFit = Image::resize($source, 300, 300, ['upsize' => true, 'bestfit' => true]);
230
        $this->assertSame('srgb(255,255,255)', $bestFit->getImagePixelColor(299, 100)->getColorAsString());
231
    }
232
233
    /**
234
     * @test
235
     * @covers ::resize
236
     * @covers ::resizeMulti
237
     */
238
    public function resizeWithBurredBackground()
239
    {
240
        $source = new \Imagick();
241
        $source->readImage(__DIR__ . '/_files/portrait.jpg');
242
        $actual = Image::resize($source, 1024, 768, ['upsize' => true, 'bestfit' => false, 'color' => 'blur']);
243
244
        $expected = new \Imagick();
245
        $expected->readImage(__DIR__ . '/_files/blur.jpg');
246
        $comparison = $expected->compareImages($actual, \Imagick::METRIC_UNDEFINED);
247
        $this->assertGreaterThanOrEqual(.999, $comparison[1]);
248
    }
249
250
    /**
251
     * @test
252
     * @covers ::resize
253
     * @covers ::resizeMulti
254
     * @expectedException \InvalidArgumentException
255
     * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
256
     */
257
    public function resizeZeroBoxWidth()
258
    {
259
        Image::resize(new \Imagick(), 0, 10);
260
    }
261
262
    /**
263
     * @test
264
     * @covers ::resize
265
     * @covers ::resizeMulti
266
     * @expectedException \InvalidArgumentException
267
     * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
268
     */
269
    public function resizeLargeBoxWidth()
270
    {
271
        Image::resize(new \Imagick(), 10001, 10, ['maxWidth' => 10000]);
272
    }
273
274
    /**
275
     * @test
276
     * @covers ::resize
277
     * @covers ::resizeMulti
278
     * @expectedException \InvalidArgumentException
279
     * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
280
     */
281
    public function resizeZeroBoxHeight()
282
    {
283
        Image::resize(new \Imagick(), 10, 0);
284
    }
285
286
    /**
287
     * @test
288
     * @covers ::resize
289
     * @covers ::resizeMulti
290
     * @expectedException \InvalidArgumentException
291
     * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
292
     */
293
    public function resizeLargeBoxHeight()
294
    {
295
        Image::resize(new \Imagick(), 10, 10001, ['maxHeight' => 10000]);
296
    }
297
298
    /**
299
     * @test
300
     * @covers ::resize
301
     * @covers ::resizeMulti
302
     * @expectedException \InvalidArgumentException
303
     * @expectedExceptionMessage $options["color"] was not a string
304
     */
305
    public function resizeNonStringColor()
306
    {
307
        Image::resize(new \Imagick(), 10, 10, ['color' => 0]);
308
    }
309
310
    /**
311
     * @test
312
     * @covers ::resize
313
     * @covers ::resizeMulti
314
     * @expectedException \InvalidArgumentException
315
     * @expectedExceptionMessage $options["maxWidth"] was not an int
316
     */
317
    public function resizeonIntMaxWidth()
318
    {
319
        Image::resize(new \Imagick(), 10, 10, ['maxWidth' => 'not int']);
320
    }
321
322
    /**
323
     * @test
324
     * @covers ::resize
325
     * @covers ::resizeMulti
326
     * @expectedException \InvalidArgumentException
327
     * @expectedExceptionMessage $options["maxHeight"] was not an int
328
     */
329
    public function resizeNonIntMaxHeight()
330
    {
331
        Image::resize(new \Imagick(), 10, 10, ['maxHeight' => 'not int']);
332
    }
333
334
    /**
335
     * @test
336
     * @covers ::resize
337
     * @covers ::resizeMulti
338
     * @expectedException \InvalidArgumentException
339
     * @expectedExceptionMessage $options["upsize"] was not a bool
340
     */
341
    public function resizeNonBoolUpsize()
342
    {
343
        Image::resize(new \Imagick(), 10, 10, ['upsize' => 'not bool']);
344
    }
345
346
    /**
347
     * @test
348
     * @covers ::resize
349
     * @covers ::resizeMulti
350
     * @expectedException \InvalidArgumentException
351
     * @expectedExceptionMessage $options["bestfit"] was not a bool
352
     */
353
    public function resizeNonBoolBestFit()
354
    {
355
        Image::resize(new \Imagick(), 10, 10, ['bestfit' => 'not bool']);
356
    }
357
358
    /**
359
     * Verify images are rotated according to EXIF header
360
     * @test
361
     * @covers ::resize
362
     * @covers ::resizeMulti
363
     */
364
    public function resizeOrientation()
365
    {
366
        $files = [
367
            "{$this->sourceFilesDir}/bottom-right.jpg",
368
            "{$this->sourceFilesDir}/left-bottom.jpg",
369
            "{$this->sourceFilesDir}/right-top.jpg",
370
            "{$this->sourceFilesDir}/top-left.jpg",
371
        ];
372
373
        $imageResults = [];
374
375
        foreach ($files as $file) {
376
            $source = new \Imagick($file);
377
            $imageWidth = $source->getimagewidth();
378
            $imageHeight = $source->getimageheight();
379
            $imageResults[] = Image::resize($source, $imageWidth, $imageHeight, []);
380
        }
381
382
        $this->assertSame(
383
            ['r' => 254, 'g' => 0, 'b' => 0, 'a' => 1],
384
            $imageResults[0]->getImagePixelColor(0, 0)->getColor()
385
        );
386
        $this->assertSame(
387
            ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 1],
388
            $imageResults[1]->getImagePixelColor(0, 0)->getColor()
389
        );
390
        $this->assertSame(
391
            ['r' => 0, 'g' => 255, 'b' => 1, 'a' => 1],
392
            $imageResults[2]->getImagePixelColor(0, 0)->getColor()
393
        );
394
        $this->assertSame(
395
            ['r' => 0, 'g' => 0, 'b' => 254, 'a' => 1],
396
            $imageResults[3]->getImagePixelColor(0, 0)->getColor()
397
        );
398
    }
399
400
    /**
401
     * Downsize ratio 2.0 to 0.25 and 2.0 to 4.0
402
     *
403
     * @test
404
     * @covers ::resizeMulti
405
     */
406
    public function resizeMultiDownsizeToMoreVerticalAndMoreHorizontalAspect()
407
    {
408
        $source = new \Imagick('pattern:gray0');
409
        $source->scaleImage(100, 50);
410
411
        $results = Image::resizeMulti($source, [['width' => 10, 'height' => 40], ['width' => 40, 'height' => 10]]);
412
        $imagickOne = $results[0];
413
        $imagickTwo = $results[1];
414
415
        //making sure source didnt resize
416
        $this->assertSame(100, $source->getImageWidth());
417
        $this->assertSame(50, $source->getImageHeight());
418
419
        //check $imagick1
420
421
        $this->assertSame(10, $imagickOne->getImageWidth());
422
        $this->assertSame(40, $imagickOne->getImageHeight());
423
424
        $oneWhiteBarTop = $imagickOne->getImagePixelColor(4, 16)->getHsl();
425
        $oneWhiteBarBottom = $imagickOne->getImagePixelColor(4, 22)->getHsl();
426
427
        $oneImageLeft = $imagickOne->getImagePixelColor(0, 19)->getHsl();
428
        $oneImageRight = $imagickOne->getImagePixelColor(9, 19)->getHsl();
429
        $oneImageTop = $imagickOne->getImagePixelColor(4, 17)->getHsl();
430
        $oneImageBottom = $imagickOne->getImagePixelColor(4, 21)->getHsl();
431
432
        $this->assertGreaterThan(0.9, $oneWhiteBarTop['luminosity']);
433
        $this->assertGreaterThan(0.9, $oneWhiteBarBottom['luminosity']);
434
435
        $this->assertLessThan(0.1, $oneImageLeft['luminosity']);
436
        $this->assertLessThan(0.1, $oneImageRight['luminosity']);
437
        $this->assertLessThan(0.1, $oneImageTop['luminosity']);
438
        $this->assertLessThan(0.1, $oneImageBottom['luminosity']);
439
440
        //check $imagick2
441
442
        $this->assertSame(40, $imagickTwo->getImageWidth());
443
        $this->assertSame(10, $imagickTwo->getImageHeight());
444
445
        $twoWhiteBarLeft = $imagickTwo->getImagePixelColor(9, 4)->getHsl();
446
        $twoWhiteBarRight = $imagickTwo->getImagePixelColor(30, 4)->getHsl();
447
448
        $twoImageLeft = $imagickTwo->getImagePixelColor(10, 4)->getHsl();
449
        $twoImageRight = $imagickTwo->getImagePixelColor(29, 4)->getHsl();
450
        $twoImageTop = $imagickTwo->getImagePixelColor(19, 0)->getHsl();
451
        $twoImageBottom = $imagickTwo->getImagePixelColor(19, 9)->getHsl();
452
453
        $this->assertGreaterThan(0.9, $twoWhiteBarLeft['luminosity']);
454
        $this->assertGreaterThan(0.9, $twoWhiteBarRight['luminosity']);
455
456
        $this->assertLessThan(0.1, $twoImageLeft['luminosity']);
457
        $this->assertLessThan(0.1, $twoImageRight['luminosity']);
458
        $this->assertLessThan(0.1, $twoImageTop['luminosity']);
459
        $this->assertLessThan(0.1, $twoImageBottom['luminosity']);
460
    }
461
462
    /**
463
     * @test
464
     * @covers ::resizeMulti
465
     */
466
    public function resizeMultiPerformance()
467
    {
468
        $source = new \Imagick('pattern:gray0');
469
        $source->scaleImage(2000, 500);
470
471
        $count = 10;
472
473
        $beforeSingle = microtime(true);
474
        for ($i = 0; $i < $count; ++$i) {
475
            Image::resize($source, 1100, 400);
476
            Image::resize($source, 100, 400);
477
            Image::resize($source, 10, 40);
478
        }
479
480
        $singleTime = microtime(true) - $beforeSingle;
481
482
        $beforeMulti = microtime(true);
483
        for ($i = 0; $i < $count; ++$i) {
484
            Image::resizeMulti(
485
                $source,
486
                [['width' => 1100, 'height' => 400], ['width' => 100, 'height' => 400], ['width' => 10, 'height' => 40]]
487
            );
488
        }
489
490
        $multiTime = microtime(true) - $beforeMulti;
491
492
        $this->assertLessThan($singleTime, $multiTime * 0.75);
493
    }
494
495
    /**
496
     * @test
497
     * @covers ::resizeMulti
498
     * @expectedException \InvalidArgumentException
499
     * @expectedExceptionMessage a width in a $boxSizes value was not an int
500
     */
501
    public function resizeMultiNonIntWidth()
502
    {
503
        Image::resizeMulti(new \Imagick(), [['width' => true, 'height' => 10]]);
504
    }
505
506
    /**
507
     * @test
508
     * @covers ::resizeMulti
509
     * @expectedException \InvalidArgumentException
510
     * @expectedExceptionMessage a height in a $boxSizes value was not an int
511
     */
512
    public function resizeMultiNonIntHeight()
513
    {
514
        Image::resizeMulti(new \Imagick(), [['width' => 10, 'height' => true]]);
515
    }
516
517
    /**
518
     * @test
519
     * @covers ::write
520
     */
521
    public function write()
522
    {
523
        $destPath = "{$this->tempDir}/dest.jpeg";
524
525
        $source = new \Imagick("{$this->sourceFilesDir}/exif.jpg");
526
        $source->setImageFormat('png');
527
528
        Image::write(
529
            $source,
530
            $destPath,
531
            ['format' => 'jpeg', 'directoryMode' => 0775, 'fileMode' => 0776, 'stripHeaders' => true]
532
        );
533
534
        $destImage = new \Imagick($destPath);
535
536
        $this->assertSame(0, count($destImage->getImageProperties('exif:*')));
537
        $this->assertSame('JPEG', $destImage->getImageFormat());
538
539
        $directoryPermissions = substr(sprintf('%o', fileperms($this->tempDir)), -4);
540
        $filePermissions = substr(sprintf('%o', fileperms($destPath)), -4);
541
542
        $this->assertSame('0775', $directoryPermissions);
543
        $this->assertSame('0776', $filePermissions);
544
    }
545
546
    /**
547
     * @test
548
     * @covers ::write
549
     * @expectedException \InvalidArgumentException
550
     * @expectedExceptionMessage $options["directoryMode"] was not an int
551
     */
552
    public function writeNonIntDirectoryMode()
553
    {
554
        Image::write(new \Imagick(), 'not under test', ['directoryMode' => 'not int']);
555
    }
556
557
    /**
558
     * @test
559
     * @covers ::write
560
     * @expectedException \InvalidArgumentException
561
     * @expectedExceptionMessage $options["fileMode"] was not an int
562
     */
563
    public function writeNonIntFileMode()
564
    {
565
        Image::write(new \Imagick(), 'not under test', ['fileMode' => 'not int']);
566
    }
567
568
    /**
569
     * @test
570
     * @covers ::write
571
     * @expectedException \InvalidArgumentException
572
     * @expectedExceptionMessage $options["format"] was not a string
573
     */
574
    public function writeNonStringFormat()
575
    {
576
        Image::write(new \Imagick(), 'not under test', ['format' => true]);
577
    }
578
579
    /**
580
     * @test
581
     * @covers ::write
582
     * @expectedException \InvalidArgumentException
583
     * @expectedExceptionMessage $options["stripHeaders"] was not a bool
584
     */
585
    public function writeNonBoolStripHeaders()
586
    {
587
        Image::write(new \Imagick(), 'not under test', ['stripHeaders' => 'not bool']);
588
    }
589
590
    /**
591
     * Verify that stripHeaders strips exif headers.
592
     *
593
     * @test
594
     * @covers ::stripHeaders
595
     */
596
    public function stripHeaders()
597
    {
598
        $path = "{$this->tempDir}/stripHeaders.jpg";
599
600
        mkdir($this->tempDir);
601
        copy("{$this->sourceFilesDir}/exif.jpg", $path);
602
603
        Image::stripHeaders($path);
604
605
        $imagick = new \Imagick($path);
606
        $this->assertSame(0, count($imagick->getImageProperties('exif:*')));
607
    }
608
609
    /**
610
     * Verify that stripHeaders fails with a missing image.
611
     *
612
     * @test
613
     * @covers ::stripHeaders
614
     * @expectedException \ImagickException
615
     */
616
    public function stripHeadersMissingImage()
617
    {
618
        Image::stripHeaders("{$this->tempDir}/doesnotexist.jpg");
619
    }
620
}
621