Nextrek
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
|
<?php
use Intervention\Image\Gd\Commands\MaskCommand as MaskGd;
use Intervention\Image\Imagick\Commands\MaskCommand as MaskImagick;
class MaskCommandTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
Mockery::close();
}
public function testGd()
{
$mask_path = __DIR__.'images/star.png';
$mask_image = Mockery::mock('Intervention\Image\Image');
$mask_size = Mockery::mock('Intervention\Image\Size', array(32, 32));
$mask_image->shouldReceive('getSize')->once()->andReturn($mask_size);
$mask_image->shouldReceive('pickColor')->andReturn(array(0,0,0,0));
$canvas_image = Mockery::mock('Intervention\Image\Image');
$canvas_core = imagecreatetruecolor(32, 32);
$canvas_image->shouldReceive('getCore')->times(2)->andReturn($canvas_core);
$canvas_image->shouldReceive('pixel');
$driver = Mockery::mock('Intervention\Image\Gd\Driver');
$driver->shouldReceive('newImage')->with(32, 32, array(0,0,0,0))->once()->andReturn($canvas_image);
$driver->shouldReceive('init')->with($mask_path)->once()->andReturn($mask_image);
$image_size = Mockery::mock('Intervention\Image\Size', array(32, 32));
$image_core = imagecreatefrompng(__DIR__.'/images/trim.png');
$image = Mockery::mock('Intervention\Image\Image');
$image->shouldReceive('getSize')->once()->andReturn($image_size);
$image->shouldReceive('getDriver')->times(2)->andReturn($driver);
$image->shouldReceive('pickColor')->andReturn(array(0,0,0,0));
$image->shouldReceive('setCore')->with($canvas_core)->once();
$command = new MaskGd(array($mask_path, true));
$result = $command->execute($image);
$this->assertTrue($result);
}
public function testImagick()
{
$mask_core = Mockery::mock('Imagick');
$mask_path = __DIR__.'images/star.png';
$mask_image = Mockery::mock('Intervention\Image\Image');
$mask_image->shouldReceive('getCore')->once()->andReturn($mask_core);
$mask_size = Mockery::mock('Intervention\Image\Size', array(32, 32));
$mask_image->shouldReceive('getSize')->once()->andReturn($mask_size);
$driver = Mockery::mock('Intervention\Image\Imagick\Driver');
$driver->shouldReceive('init')->with($mask_path)->once()->andReturn($mask_image);
$imagick = Mockery::mock('Imagick');
$imagick->shouldReceive('setimagematte')->with(true)->once();
$imagick->shouldReceive('compositeimage')->with($mask_core, \Imagick::COMPOSITE_DSTIN, 0, 0)->once();
$image = Mockery::mock('Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$image_size = Mockery::mock('Intervention\Image\Size', array(32, 32));
$image->shouldReceive('getSize')->once()->andReturn($image_size);
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$command = new MaskImagick(array($mask_path, true));
$result = $command->execute($image);
$this->assertTrue($result);
}
}
|
Revision |
Author |
Commited |
Message |
1464
|
MOliva
|
Tue 13 Oct, 2020 11:16:56 +0000 |
|