Completed
Pull Request — master (#22)
by Chad
01:04
created

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