-
Notifications
You must be signed in to change notification settings - Fork 456
Expand file tree
/
Copy pathImageTest.php
More file actions
82 lines (65 loc) · 2 KB
/
ImageTest.php
File metadata and controls
82 lines (65 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
use PHPUnit\Framework\TestCase;
use SimpleSoftwareIO\QrCode\Image;
class ImageTest extends TestCase
{
/**
* The location to save the testing image.
*
* @var string
*/
protected $testImageSaveLocation;
/**
* The location to save the compare image.
*
* @var string
*/
protected $compareTestSaveLocation;
/**
* The path to the image used to test.
*
* @var string
*/
protected $imagePath;
/**
* The Image object.
*
* @var Image
*/
protected $image;
public function setUp(): void
{
$this->imagePath = file_get_contents(dirname(__FILE__).'/Images/simplesoftware-icon-grey-blue.png');
$this->image = new Image($this->imagePath);
$this->testImageSaveLocation = dirname(__FILE__).'/testImage.png';
$this->compareTestSaveLocation = dirname(__FILE__).'/compareImage.png';
}
public function tearDown(): void
{
@unlink($this->testImageSaveLocation);
@unlink($this->compareTestSaveLocation);
}
/**
* Must test that the outputted PNG is the same because you can not compare resources.
*/
public function test_it_loads_an_image_string_into_a_resource()
{
imagepng(imagecreatefromstring($this->imagePath), $this->compareTestSaveLocation);
imagepng($this->image->getImageResource(), $this->testImageSaveLocation);
$correctImage = file_get_contents($this->compareTestSaveLocation);
$testImage = file_get_contents($this->testImageSaveLocation);
$this->assertEquals($correctImage, $testImage);
}
public function test_it_gets_the_correct_height()
{
$correctHeight = 512;
$testHeight = $this->image->getHeight();
$this->assertEquals($correctHeight, $testHeight);
}
public function test_it_gets_the_correct_width()
{
$correctWidth = 512;
$testWidth = $this->image->getWidth();
$this->assertEquals($correctWidth, $testWidth);
}
}