Completed
Pull Request — master (#26)
by Chad
09:50
created

tests/ImageTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace TraderInteractive\Util;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Util\Image
9
 * @covers ::<private>
10
 */
11
final class ImageTest extends TestCase
12
{
13
    private $sourceFilesDir;
14
    private $tempDir;
15
16
    public function setUp()
17
    {
18
        $this->sourceFilesDir = __DIR__ . '/_files';
19
        $this->tempDir = sys_get_temp_dir() . '/imageUtilTest';
20
        if (is_dir($this->tempDir)) {
21
            foreach (glob("{$this->tempDir}/*") as $file) {
22
                unlink($file);
23
            }
24
25
            rmdir($this->tempDir);
26
        }
27
    }
28
29
    /**
30
     * Downsize ratio 2.0 to 0.25
31
     *
32
     * @test
33
     * @covers ::resize
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
     */
72 View Code Duplication
    public function resizeDownsizeToMoreHorizontalAspect()
73
    {
74
        $source = new \Imagick('pattern:gray0');
75
        $source->scaleImage(100, 50);
76
77
        $imagick = Image::resize($source, 40, 10);
78
79
        //making sure source didnt resize
80
        $this->assertSame(100, $source->getImageWidth());
81
        $this->assertSame(50, $source->getImageHeight());
82
83
        $this->assertSame(40, $imagick->getImageWidth());
84
        $this->assertSame(10, $imagick->getImageHeight());
85
86
        $whiteBarLeft = $imagick->getImagePixelColor(9, 4)->getHsl();
87
        $whiteBarRight = $imagick->getImagePixelColor(30, 4)->getHsl();
88
89
        $imageLeft = $imagick->getImagePixelColor(10, 4)->getHsl();
90
        $imageRight = $imagick->getImagePixelColor(29, 4)->getHsl();
91
        $imageTop = $imagick->getImagePixelColor(19, 0)->getHsl();
92
        $imageBottom = $imagick->getImagePixelColor(19, 9)->getHsl();
93
94
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
95
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
96
97
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
98
        $this->assertLessThan(0.1, $imageRight['luminosity']);
99
        $this->assertLessThan(0.1, $imageTop['luminosity']);
100
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
101
    }
102
103
    /**
104
     * Upsize ratio 2.0 to 4.0
105
     *
106
     * @test
107
     * @covers ::resize
108
     */
109 View Code Duplication
    public function resizeUpsizeToMoreHorizontalAspectWithoutGrow()
110
    {
111
        $source = new \Imagick('pattern:gray0');
112
        $source->scaleImage(100, 50);
113
114
        $imagick = Image::resize($source, 400, 100);
115
116
        //making sure source didnt resize
117
        $this->assertSame(100, $source->getImageWidth());
118
        $this->assertSame(50, $source->getImageHeight());
119
120
        $this->assertSame(400, $imagick->getImageWidth());
121
        $this->assertSame(100, $imagick->getImageHeight());
122
123
        $whiteBarLeft = $imagick->getImagePixelColor(99, 49)->getHsl();
124
        $whiteBarRight = $imagick->getImagePixelColor(300, 49)->getHsl();
125
126
        $imageTop = $imagick->getImagePixelColor(200, 26)->getHsl();
127
        $imageBottom = $imagick->getImagePixelColor(200, 74)->getHsl();
128
        $imageLeft = $imagick->getImagePixelColor(151, 50)->getHsl();
129
        $imageRight = $imagick->getImagePixelColor(249, 50)->getHsl();
130
131
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
132
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
133
134
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
135
        $this->assertLessThan(0.1, $imageRight['luminosity']);
136
        $this->assertLessThan(0.1, $imageTop['luminosity']);
137
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
138
    }
139
140
    /**
141
     * Upsize ratio 2.0 to 4.0
142
     *
143
     * @test
144
     * @covers ::resize
145
     */
146 View Code Duplication
    public function resizeUpsizeToMoreHorizontalAspectWithGrow()
147
    {
148
        $source = new \Imagick('pattern:gray0');
149
        $source->scaleImage(100, 50);
150
151
        $imagick = Image::resize($source, 400, 100, ['upsize' => true]);
152
153
        //making sure source didnt resize
154
        $this->assertSame(100, $source->getImageWidth());
155
        $this->assertSame(50, $source->getImageHeight());
156
157
        $this->assertSame(400, $imagick->getImageWidth());
158
        $this->assertSame(100, $imagick->getImageHeight());
159
160
        $whiteBarLeft = $imagick->getImagePixelColor(99, 49)->getHsl();
161
        $whiteBarRight = $imagick->getImagePixelColor(300, 49)->getHsl();
162
163
        $imageTop = $imagick->getImagePixelColor(249, 0)->getHsl();
164
        $imageBottom = $imagick->getImagePixelColor(249, 99)->getHsl();
165
        $imageLeft = $imagick->getImagePixelColor(100, 49)->getHsl();
166
        $imageRight = $imagick->getImagePixelColor(299, 49)->getHsl();
167
168
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
169
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
170
171
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
172
        $this->assertLessThan(0.1, $imageRight['luminosity']);
173
        $this->assertLessThan(0.1, $imageTop['luminosity']);
174
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
175
    }
176
177
    /**
178
     * Upsize ratio 2.0 to 4.0
179
     *
180
     * @test
181
     * @covers ::resize
182
     */
183 View Code Duplication
    public function resizeUpsizeToMoreVerticalAspect()
184
    {
185
        $source = new \Imagick('pattern:gray0');
186
        $source->scaleImage(100, 50);
187
188
        $imagick = Image::resize($source, 200, 400);
189
190
        //making sure source didnt resize
191
        $this->assertSame(100, $source->getImageWidth());
192
        $this->assertSame(50, $source->getImageHeight());
193
194
        $this->assertSame(200, $imagick->getImageWidth());
195
        $this->assertSame(400, $imagick->getImageHeight());
196
197
        $whiteBarLeft = $imagick->getImagePixelColor(49, 200)->getHsl();
198
        $whiteBarRight = $imagick->getImagePixelColor(151, 200)->getHsl();
199
200
        $imageTop = $imagick->getImagePixelColor(100, 176)->getHsl();
201
        $imageBottom = $imagick->getImagePixelColor(100, 224)->getHsl();
202
        $imageLeft = $imagick->getImagePixelColor(51, 200)->getHsl();
203
        $imageRight = $imagick->getImagePixelColor(149, 200)->getHsl();
204
205
        $this->assertGreaterThan(0.9, $whiteBarLeft['luminosity']);
206
        $this->assertGreaterThan(0.9, $whiteBarRight['luminosity']);
207
208
        $this->assertLessThan(0.1, $imageLeft['luminosity']);
209
        $this->assertLessThan(0.1, $imageRight['luminosity']);
210
        $this->assertLessThan(0.1, $imageTop['luminosity']);
211
        $this->assertLessThan(0.1, $imageBottom['luminosity']);
212
    }
213
214
    /**
215
     * @test
216
     * @covers ::resize
217
     */
218
    public function resizeWithUpsizeAndBestFit()
219
    {
220
        $source = new \Imagick('pattern:gray0');
221
        $source->scaleImage(85, 45);
222
        $notBestFit = Image::resize($source, 300, 300, ['upsize' => true, 'bestfit' => false]);
223
        $this->assertSame('srgb(0,0,0)', $notBestFit->getImagePixelColor(299, 100)->getColorAsString());
224
        $bestFit = Image::resize($source, 300, 300, ['upsize' => true, 'bestfit' => true]);
225
        $this->assertSame('srgb(255,255,255)', $bestFit->getImagePixelColor(299, 100)->getColorAsString());
226
    }
227
228
    /**
229
     * @test
230
     * @covers ::resize
231
     */
232 View Code Duplication
    public function resizeWithColorOfBlur()
233
    {
234
        $source = new \Imagick();
235
        $source->readImage(__DIR__ . '/_files/portrait.jpg');
236
        $actual = Image::resize($source, 1024, 768, ['upsize' => true, 'bestfit' => false, 'color' => 'blur']);
237
        $expected = new \Imagick();
238
        $expected->readImage(__DIR__ . '/_files/blur.jpg');
239
        $comparison = $expected->compareImages($actual, \Imagick::METRIC_UNDEFINED);
240
        $this->assertGreaterThanOrEqual(.99, $comparison[1]);
241
    }
242
243
    /**
244
     * @test
245
     * @covers ::resize
246
     */
247 View Code Duplication
    public function resizeWithBlurBackground()
248
    {
249
        $source = new \Imagick();
250
        $source->readImage(__DIR__ . '/_files/portrait.jpg');
251
        $actual = Image::resize($source, 1024, 768, ['upsize' => true, 'bestfit' => false, 'blurBackground' => true]);
252
253
        $expected = new \Imagick();
254
        $expected->readImage(__DIR__ . '/_files/blur.jpg');
255
        $comparison = $expected->compareImages($actual, \Imagick::METRIC_UNDEFINED);
256
        $this->assertGreaterThanOrEqual(.99, $comparison[1]);
257
    }
258
259
    /**
260
     * @test
261
     * @covers ::resize
262
     */
263 View Code Duplication
    public function resizeWithBurredBackgroundWithCustomBlurValue()
0 ignored issues
show
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...
264
    {
265
        $source = new \Imagick();
266
        $source->readImage(__DIR__ . '/_files/portrait.jpg');
267
        $options = ['upsize' => true, 'bestfit' => false, 'blurBackground' => true, 'blurValue' => 30.0];
268
        $actual = Image::resize($source, 1024, 768, $options);
269
270
        $expected = new \Imagick();
271
        $expected->readImage(__DIR__ . '/_files/blur-30.jpg');
272
        $comparison = $expected->compareImages($actual, \Imagick::METRIC_UNDEFINED);
273
        $this->assertGreaterThanOrEqual(.999, $comparison[1]);
274
    }
275
276
    /**
277
     * @test
278
     * @covers ::resize
279
     * @covers ::resizeMulti
280
     * @expectedException \InvalidArgumentException
281
     * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
282
     */
283
    public function resizeZeroBoxWidth()
284
    {
285
        Image::resize(new \Imagick(), 0, 10);
286
    }
287
288
    /**
289
     * @test
290
     * @covers ::resize
291
     * @covers ::resizeMulti
292
     * @expectedException \InvalidArgumentException
293
     * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
294
     */
295
    public function resizeLargeBoxWidth()
296
    {
297
        Image::resize(new \Imagick(), 10001, 10, ['maxWidth' => 10000]);
298
    }
299
300
    /**
301
     * @test
302
     * @covers ::resize
303
     * @covers ::resizeMulti
304
     * @expectedException \InvalidArgumentException
305
     * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
306
     */
307
    public function resizeZeroBoxHeight()
308
    {
309
        Image::resize(new \Imagick(), 10, 0);
310
    }
311
312
    /**
313
     * @test
314
     * @covers ::resize
315
     * @covers ::resizeMulti
316
     * @expectedException \InvalidArgumentException
317
     * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
318
     */
319
    public function resizeLargeBoxHeight()
320
    {
321
        Image::resize(new \Imagick(), 10, 10001, ['maxHeight' => 10000]);
322
    }
323
324
    /**
325
     * @test
326
     * @covers ::resize
327
     * @covers ::resizeMulti
328
     * @expectedException \InvalidArgumentException
329
     * @expectedExceptionMessage $options["color"] was not a string
330
     */
331
    public function resizeNonStringColor()
332
    {
333
        Image::resize(new \Imagick(), 10, 10, ['color' => 0]);
334
    }
335
336
    /**
337
     * @test
338
     * @covers ::resize
339
     * @covers ::resizeMulti
340
     * @expectedException \InvalidArgumentException
341
     * @expectedExceptionMessage $options["maxWidth"] was not an int
342
     */
343
    public function resizeonIntMaxWidth()
344
    {
345
        Image::resize(new \Imagick(), 10, 10, ['maxWidth' => 'not int']);
346
    }
347
348
    /**
349
     * @test
350
     * @covers ::resize
351
     * @covers ::resizeMulti
352
     * @expectedException \InvalidArgumentException
353
     * @expectedExceptionMessage $options["maxHeight"] was not an int
354
     */
355
    public function resizeNonIntMaxHeight()
356
    {
357
        Image::resize(new \Imagick(), 10, 10, ['maxHeight' => 'not int']);
358
    }
359
360
    /**
361
     * @test
362
     * @covers ::resize
363
     * @covers ::resizeMulti
364
     * @expectedException \InvalidArgumentException
365
     * @expectedExceptionMessage $options["upsize"] was not a bool
366
     */
367
    public function resizeNonBoolUpsize()
368
    {
369
        Image::resize(new \Imagick(), 10, 10, ['upsize' => 'not bool']);
370
    }
371
372
    /**
373
     * @test
374
     * @covers ::resize
375
     * @covers ::resizeMulti
376
     * @expectedException \InvalidArgumentException
377
     * @expectedExceptionMessage $options["bestfit"] was not a bool
378
     */
379
    public function resizeNonBoolBestFit()
380
    {
381
        Image::resize(new \Imagick(), 10, 10, ['bestfit' => 'not bool']);
382
    }
383
384
    /**
385
     * Verify images are rotated according to EXIF header
386
     * @test
387
     * @covers ::resize
388
     */
389
    public function resizeOrientation()
390
    {
391
        $files = [
392
            "{$this->sourceFilesDir}/bottom-right.jpg",
393
            "{$this->sourceFilesDir}/left-bottom.jpg",
394
            "{$this->sourceFilesDir}/right-top.jpg",
395
            "{$this->sourceFilesDir}/top-left.jpg",
396
        ];
397
398
        $imageResults = [];
399
400
        foreach ($files as $file) {
401
            $source = new \Imagick($file);
402
            $imageWidth = $source->getimagewidth();
403
            $imageHeight = $source->getimageheight();
404
            $imageResults[] = Image::resize($source, $imageWidth, $imageHeight, []);
405
        }
406
407
        $this->assertSame(
408
            ['r' => 254, 'g' => 0, 'b' => 0, 'a' => 1],
409
            $imageResults[0]->getImagePixelColor(0, 0)->getColor()
410
        );
411
        $this->assertSame(
412
            ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 1],
413
            $imageResults[1]->getImagePixelColor(0, 0)->getColor()
414
        );
415
        $this->assertSame(
416
            ['r' => 0, 'g' => 255, 'b' => 1, 'a' => 1],
417
            $imageResults[2]->getImagePixelColor(0, 0)->getColor()
418
        );
419
        $this->assertSame(
420
            ['r' => 0, 'g' => 0, 'b' => 254, 'a' => 1],
421
            $imageResults[3]->getImagePixelColor(0, 0)->getColor()
422
        );
423
    }
424
425
    /**
426
     * Downsize ratio 2.0 to 0.25 and 2.0 to 4.0
427
     *
428
     * @test
429
     * @covers ::resizeMulti
430
     */
431
    public function resizeMultiDownsizeToMoreVerticalAndMoreHorizontalAspect()
432
    {
433
        $source = new \Imagick('pattern:gray0');
434
        $source->scaleImage(100, 50);
435
436
        $results = Image::resizeMulti($source, [['width' => 10, 'height' => 40], ['width' => 40, 'height' => 10]]);
437
        $imagickOne = $results[0];
438
        $imagickTwo = $results[1];
439
440
        //making sure source didnt resize
441
        $this->assertSame(100, $source->getImageWidth());
442
        $this->assertSame(50, $source->getImageHeight());
443
444
        //check $imagick1
445
446
        $this->assertSame(10, $imagickOne->getImageWidth());
447
        $this->assertSame(40, $imagickOne->getImageHeight());
448
449
        $oneWhiteBarTop = $imagickOne->getImagePixelColor(4, 16)->getHsl();
450
        $oneWhiteBarBottom = $imagickOne->getImagePixelColor(4, 22)->getHsl();
451
452
        $oneImageLeft = $imagickOne->getImagePixelColor(0, 19)->getHsl();
453
        $oneImageRight = $imagickOne->getImagePixelColor(9, 19)->getHsl();
454
        $oneImageTop = $imagickOne->getImagePixelColor(4, 17)->getHsl();
455
        $oneImageBottom = $imagickOne->getImagePixelColor(4, 21)->getHsl();
456
457
        $this->assertGreaterThan(0.9, $oneWhiteBarTop['luminosity']);
458
        $this->assertGreaterThan(0.9, $oneWhiteBarBottom['luminosity']);
459
460
        $this->assertLessThan(0.1, $oneImageLeft['luminosity']);
461
        $this->assertLessThan(0.1, $oneImageRight['luminosity']);
462
        $this->assertLessThan(0.1, $oneImageTop['luminosity']);
463
        $this->assertLessThan(0.1, $oneImageBottom['luminosity']);
464
465
        //check $imagick2
466
467
        $this->assertSame(40, $imagickTwo->getImageWidth());
468
        $this->assertSame(10, $imagickTwo->getImageHeight());
469
470
        $twoWhiteBarLeft = $imagickTwo->getImagePixelColor(9, 4)->getHsl();
471
        $twoWhiteBarRight = $imagickTwo->getImagePixelColor(30, 4)->getHsl();
472
473
        $twoImageLeft = $imagickTwo->getImagePixelColor(10, 4)->getHsl();
474
        $twoImageRight = $imagickTwo->getImagePixelColor(29, 4)->getHsl();
475
        $twoImageTop = $imagickTwo->getImagePixelColor(19, 0)->getHsl();
476
        $twoImageBottom = $imagickTwo->getImagePixelColor(19, 9)->getHsl();
477
478
        $this->assertGreaterThan(0.9, $twoWhiteBarLeft['luminosity']);
479
        $this->assertGreaterThan(0.9, $twoWhiteBarRight['luminosity']);
480
481
        $this->assertLessThan(0.1, $twoImageLeft['luminosity']);
482
        $this->assertLessThan(0.1, $twoImageRight['luminosity']);
483
        $this->assertLessThan(0.1, $twoImageTop['luminosity']);
484
        $this->assertLessThan(0.1, $twoImageBottom['luminosity']);
485
    }
486
487
    /**
488
     * @test
489
     * @covers ::resizeMulti
490
     */
491
    public function resizeMultiPerformance()
492
    {
493
        $source = new \Imagick('pattern:gray0');
494
        $source->scaleImage(2000, 500);
495
496
        $count = 10;
497
498
        $beforeSingle = microtime(true);
499
        for ($i = 0; $i < $count; ++$i) {
500
            Image::resizeMulti($source, [['width' => 1100, 'height' => 400]]);
501
            Image::resizeMulti($source, [['width' => 100, 'height' => 400]]);
502
            Image::resizeMulti($source, [['width' => 10, 'height' => 40]]);
503
        }
504
505
        $singleTime = microtime(true) - $beforeSingle;
506
507
        $beforeMulti = microtime(true);
508
        for ($i = 0; $i < $count; ++$i) {
509
            Image::resizeMulti(
510
                $source,
511
                [['width' => 1100, 'height' => 400], ['width' => 100, 'height' => 400], ['width' => 10, 'height' => 40]]
512
            );
513
        }
514
515
        $multiTime = microtime(true) - $beforeMulti;
516
517
        $this->assertLessThan($singleTime, $multiTime * 0.75);
518
    }
519
520
    /**
521
     * @test
522
     * @covers ::resizeMulti
523
     * @expectedException \InvalidArgumentException
524
     * @expectedExceptionMessage a width in a $boxSizes value was not an int
525
     */
526
    public function resizeMultiNonIntWidth()
527
    {
528
        Image::resizeMulti(new \Imagick(), [['width' => true, 'height' => 10]]);
529
    }
530
531
    /**
532
     * @test
533
     * @covers ::resizeMulti
534
     * @expectedException \InvalidArgumentException
535
     * @expectedExceptionMessage a height in a $boxSizes value was not an int
536
     */
537
    public function resizeMultiNonIntHeight()
538
    {
539
        Image::resizeMulti(new \Imagick(), [['width' => 10, 'height' => true]]);
540
    }
541
542
    /**
543
     * @test
544
     * @covers ::write
545
     */
546
    public function write()
547
    {
548
        $destPath = "{$this->tempDir}/dest.jpeg";
549
550
        $source = new \Imagick("{$this->sourceFilesDir}/exif.jpg");
551
        $source->setImageFormat('png');
552
553
        Image::write(
554
            $source,
555
            $destPath,
556
            ['format' => 'jpeg', 'directoryMode' => 0775, 'fileMode' => 0776, 'stripHeaders' => true]
557
        );
558
559
        $destImage = new \Imagick($destPath);
560
561
        $this->assertSame(0, count($destImage->getImageProperties('exif:*')));
562
        $this->assertSame('JPEG', $destImage->getImageFormat());
563
564
        $directoryPermissions = substr(sprintf('%o', fileperms($this->tempDir)), -4);
565
        $filePermissions = substr(sprintf('%o', fileperms($destPath)), -4);
566
567
        $this->assertSame('0775', $directoryPermissions);
568
        $this->assertSame('0776', $filePermissions);
569
    }
570
571
    /**
572
     * @test
573
     * @covers ::write
574
     * @expectedException \InvalidArgumentException
575
     * @expectedExceptionMessage $options["directoryMode"] was not an int
576
     */
577
    public function writeNonIntDirectoryMode()
578
    {
579
        Image::write(new \Imagick(), 'not under test', ['directoryMode' => 'not int']);
580
    }
581
582
    /**
583
     * @test
584
     * @covers ::write
585
     * @expectedException \InvalidArgumentException
586
     * @expectedExceptionMessage $options["fileMode"] was not an int
587
     */
588
    public function writeNonIntFileMode()
589
    {
590
        Image::write(new \Imagick(), 'not under test', ['fileMode' => 'not int']);
591
    }
592
593
    /**
594
     * @test
595
     * @covers ::write
596
     * @expectedException \InvalidArgumentException
597
     * @expectedExceptionMessage $options["format"] was not a string
598
     */
599
    public function writeNonStringFormat()
600
    {
601
        Image::write(new \Imagick(), 'not under test', ['format' => true]);
602
    }
603
604
    /**
605
     * @test
606
     * @covers ::write
607
     * @expectedException \InvalidArgumentException
608
     * @expectedExceptionMessage $options["stripHeaders"] was not a bool
609
     */
610
    public function writeNonBoolStripHeaders()
611
    {
612
        Image::write(new \Imagick(), 'not under test', ['stripHeaders' => 'not bool']);
613
    }
614
615
    /**
616
     * Verify that stripHeaders strips exif headers.
617
     *
618
     * @test
619
     * @covers ::stripHeaders
620
     */
621
    public function stripHeaders()
622
    {
623
        $path = "{$this->tempDir}/stripHeaders.jpg";
624
625
        mkdir($this->tempDir);
626
        copy("{$this->sourceFilesDir}/exif.jpg", $path);
627
628
        Image::stripHeaders($path);
629
630
        $imagick = new \Imagick($path);
631
        $this->assertSame(0, count($imagick->getImageProperties('exif:*')));
632
    }
633
634
    /**
635
     * Verify that stripHeaders fails with a missing image.
636
     *
637
     * @test
638
     * @covers ::stripHeaders
639
     * @expectedException \ImagickException
640
     */
641
    public function stripHeadersMissingImage()
642
    {
643
        Image::stripHeaders("{$this->tempDir}/doesnotexist.jpg");
644
    }
645
}
646