Passed
Push — master ( 3c6756...8b3b37 )
by Michael
14:24 queued 07:02
created

TGATest::testLoadEmptyFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
	/**
3
    This file is part of WideImage.
4
5
    WideImage is free software; you can redistribute it and/or modify
6
    it under the terms of the GNU Lesser General Public License as published by
7
    the Free Software Foundation; either version 2.1 of the License, or
8
    (at your option) any later version.
9
10
    WideImage is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU Lesser General Public License for more details.
14
15
    You should have received a copy of the GNU Lesser General Public License
16
    along with WideImage; if not, write to the Free Software
17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19
    * @package Tests
20
  **/
21
22
namespace Test\WideImage\Mapper;
23
24
use WideImage\WideImage;
25
use Test\WideImage_TestCase;
26
use WideImage\MapperFactory;
27
use WideImage\vendor\de77;
28
29
/**
30
 * @package Tests
31
 * @group mapper
32
 */
33
class TGATest extends WideImage_TestCase
34
{
35
	/**
36
	 * @var WideImage_Mapper_TGA
0 ignored issues
show
Bug introduced by
The type Test\WideImage\Mapper\WideImage_Mapper_TGA was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
	 */
38
	protected $mapper;
39
40
	public function setup()
41
	{
42
		$this->mapper = MapperFactory::selectMapper(null, 'tga');
0 ignored issues
show
Documentation Bug introduced by
It seems like WideImage\MapperFactory:...lectMapper(null, 'tga') can also be of type false. However, the property $mapper is declared as type Test\WideImage\Mapper\WideImage_Mapper_TGA. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
43
	}
44
45
	public function teardown()
46
	{
47
		$this->mapper = null;
48
	}
49
50
	public function testLoad()
51
	{
52
		$handle = $this->mapper->load(IMG_PATH . 'splat.tga');
53
		$this->assertTrue(WideImage::isValidImageHandle($handle));
54
		$this->assertEquals(100, imagesx($handle));
55
		$this->assertEquals(100, imagesy($handle));
56
		imagedestroy($handle);
57
	}
58
59
	public function testLoadEmptyFile()
60
	{
61
		$handle = $this->mapper->load(IMG_PATH . 'empty.tga');
62
		$this->assertFalse($handle);
63
	}
64
65
	/**
66
	 * @expectedException WideImage\Exception\Exception
67
	 */
68
	public function testSaveToStringNotSupported()
69
	{
70
		$handle = de77\BMP::imagecreatefrombmp(IMG_PATH . 'splat.tga');
71
		$this->mapper->save($handle);
72
	}
73
74
	/**
75
	 * @expectedException WideImage\Exception\Exception
76
	 */
77
	public function testSaveToFileNotSupported()
78
	{
79
		$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
80
		$this->mapper->save($handle, IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.bmp');
81
	}
82
}
83