Completed
Pull Request — master (#9)
by Laurens
02:02
created

fileIsNotAnImage_shouldThrowException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Tests\Unit\API\Image;
6
7
use LauLamanApps\IzettleApi\API\Image\ProductImageUpload;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * @small
12
 */
13
final class ProductImageUploadTest extends TestCase
14
{
15
    /**
16
     * @test
17
     */
18
    public function productImageUpload_withURL(): void
19
    {
20
        $imageUrl = 'https://example.com/image.png';
21
22
        $productImageUpload = ProductImageUpload::url($imageUrl);
23
24
        self::assertInstanceOf(ProductImageUpload::class, $productImageUpload);
25
        self::assertAttributeEquals($imageUrl, 'imageUrl', $productImageUpload);
26
        self::assertSame(['imageUrl' => $imageUrl], $productImageUpload->getArrayData());
27
    }
28
29
    /**
30
     * @test
31
     */
32
    public function productImageUpload_withImage(): void
33
    {
34
        $file = dirname(__FILE__) . '/files/50x50-good.png';
35
        $imageFormat = 'PNG';
36
        $imageData = file_get_contents($file);
37
        $productImageUpload = ProductImageUpload::file($file);
38
39
        self::assertInstanceOf(ProductImageUpload::class, $productImageUpload);
40
        self::assertAttributeEquals($imageFormat, 'imageFormat', $productImageUpload);
41
        self::assertAttributeEquals($imageData, 'imageData', $productImageUpload);
42
        self::assertSame(['imageFormat' => $imageFormat, 'imageData' => $imageData], $productImageUpload->getArrayData());
43
    }
44
45
    /**
46
     * @test
47
     * @expectedException \LauLamanApps\IzettleApi\API\Image\Exceptions\MaximumImageFileSizeExcededException
48
     */
49
    public function fileSizeIsToBig_shouldThrowException(): void
50
    {
51
        ProductImageUpload::file(dirname(__FILE__) . '/files/3840x2160-filesize-to-big.png');
52
    }
53
54
    /**
55
     * @test
56
     * @expectedException \LauLamanApps\IzettleApi\API\Image\Exceptions\FileIsNotAnImageException
57
     */
58
    public function fileIsNotAnImage_shouldThrowException(): void
59
    {
60
        ProductImageUpload::file(dirname(__FILE__) . '/files/text.txt');
61
    }
62
63
    /**
64
     * @test
65
     * @expectedException \LauLamanApps\IzettleApi\API\Image\Exceptions\ImageTypeNotAllowedException
66
     */
67
    public function notAllowedFileType_shouldThrowException(): void
68
    {
69
        ProductImageUpload::file(dirname(__FILE__) . '/files/50x50-file-type-not-allowed.swf');
70
    }
71
72
    /**
73
     * @test
74
     * @expectedException \LauLamanApps\IzettleApi\API\Image\Exceptions\ImageIsToSmallException
75
     */
76
    public function toSmallImageSize_shouldThrowException(): void
77
    {
78
        ProductImageUpload::file(dirname(__FILE__) . '/files/1x1-to-small.png');
79
    }
80
}
81