Completed
Push — master ( a30936...ebf12a )
by Roberto
05:49 queued 03:12
created

GraphicsTest::testInitialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Posprint\Tests\Graphics;
4
5
/**
6
 * Unit Tests form Graphics Class
7
 * 
8
 * @author Roberto L. Machado <linux dot rlm at gmail dot com>
9
 */
10
11
use Posprint\Graphics\Graphics;
12
13
class GraphicsTest extends \PHPUnit_Framework_TestCase
14
{
15
    
16
    public function testInitialize()
17
    {
18
        $graphics = new Graphics();
19
        $this->assertInstanceOf(Graphics::class, $graphics);
20
    }
21
    
22
    public function testLoadImage()
23
    {
24
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.png');
25
        $graphics = new Graphics($imagePath);
26
    }
27
    
28
    /**
29
     * @expectedException RunTimeException
30
     * @expectedExceptionMessage It is not possible to use or handle this type of image with GD
31
     */
32
    public function testLoaImageFailType()
33
    {
34
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.tiff');
35
        $graphics = new Graphics($imagePath);
36
    }
37
    
38
    /**
39
     * @expectedException InvalidArgumentException
40
     * @expectedExceptionMessage Image file not found.
41
     */
42
    public function testLoaImageFailNotFind()
43
    {
44
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.svg');
45
        $graphics = new Graphics($imagePath);
46
    }
47
    
48
    public function testLoadImageBMP()
49
    {
50
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.bmp');
51
        $graphics = new Graphics($imagePath);
52
    }
53
    
54
    public function testConvert2BMP()
55
    {
56
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.png');
57
        $graphics = new Graphics($imagePath);
58
        $result = $graphics->convert2BMP();
59
        $filename = realpath(dirname(__FILE__).'/../fixtures').DIRECTORY_SEPARATOR.'tux.bmp';
60
        $expected = file_get_contents($filename);
61
        $this->assertEquals($result, $expected);
62
    }
63
    
64
    public function testConvert2BMPSave()
65
    {
66
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.png');
67
        $graphics = new Graphics($imagePath);
68
        $filename = realpath(dirname(__FILE__).'/../fixtures').DIRECTORY_SEPARATOR.'new.bmp';
69
        $graphics->convert2BMP($filename);
70
        $result = file_get_contents($filename);
71
        $filename = realpath(dirname(__FILE__).'/../fixtures').DIRECTORY_SEPARATOR.'tux.bmp';
72
        $expected = file_get_contents($filename);
73
        $this->assertEquals($result, $expected);
74
    }
75
76
    /**
77
     * @expectedException InvalidArgumentException
78
     * @expectedExceptionMessage Cant open file /new.bmp. Check permissions.
79
     */    
80
    public function testeConvert2BMPSaveFail()
81
    {
82
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.png');
83
        $graphics = new Graphics($imagePath);
84
        $filename = realpath(dirname(__FILE__).'/../noexists').DIRECTORY_SEPARATOR.'new.bmp';
85
        $graphics->convert2BMP($filename);
86
    }
87
    
88
    public function testGetRaster()
89
    {
90
        $imagePath = realpath(dirname(__FILE__).'/../fixtures/tux.png');
91
        $graphics = new Graphics($imagePath);
92
        $result = $graphics->getRasterImage();
93
        $filename = realpath(dirname(__FILE__).'/../fixtures').DIRECTORY_SEPARATOR.'tux.raw';
94
        $expected = file_get_contents($filename);
95
        //$this->assertEquals($result, $expected);
96
    }
97
    
98
    public function testQRCode()
99
    {
100
        $graphics = new Graphics();
101
        $graphics->imageQRCode();
102
        $filename = realpath(dirname(__FILE__).'/../fixtures').DIRECTORY_SEPARATOR.'qr.png';
103
        $graphics->save($filename);
104
    }
105
}