mirror of
https://github.com/Intervention/image.git
synced 2025-01-17 12:18:14 +01:00
destroy() now also frees memory of backup
This commit is contained in:
parent
b3ccde879d
commit
6554d8165e
@ -12,6 +12,14 @@ class DestroyCommand extends \Intervention\Image\Commands\AbstractCommand
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
return imagedestroy($image->getCore());
|
||||
// destroy image core
|
||||
imagedestroy($image->getCore());
|
||||
|
||||
// destroy backups
|
||||
foreach ($image->getBackups() as $backup) {
|
||||
imagedestroy($backup);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,14 @@ class DestroyCommand extends \Intervention\Image\Commands\AbstractCommand
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
return $image->getCore()->clear();
|
||||
// destroy image core
|
||||
$image->getCore()->clear();
|
||||
|
||||
// destroy backups
|
||||
foreach ($image->getBackups() as $backup) {
|
||||
$backup->clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,15 @@ class DestroyCommandTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGd()
|
||||
{
|
||||
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
||||
$resource = imagecreatefrompng(__DIR__.'/images/tile.png');
|
||||
$backups = array(
|
||||
imagecreatefrompng(__DIR__.'/images/tile.png'),
|
||||
imagecreatefrompng(__DIR__.'/images/tile.png')
|
||||
);
|
||||
|
||||
$image = Mockery::mock('Intervention\Image\Image');
|
||||
$image->shouldReceive('getCore')->once()->andReturn($resource);
|
||||
$image->shouldReceive('getBackups')->once()->andReturn($backups);
|
||||
$command = new DestroyGd(array());
|
||||
$result = $command->execute($image);
|
||||
$this->assertTrue($result);
|
||||
@ -24,8 +30,14 @@ class DestroyCommandTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$imagick = Mockery::mock('Imagick');
|
||||
$imagick->shouldReceive('clear')->with()->andReturn(true);
|
||||
|
||||
$backup = Mockery::mock('Imagick');
|
||||
$backup->shouldReceive('clear')->with()->andReturn(true);
|
||||
$backups = array($backup);
|
||||
|
||||
$image = Mockery::mock('Intervention\Image\Image');
|
||||
$image->shouldReceive('getCore')->once()->andReturn($imagick);
|
||||
$image->shouldReceive('getBackups')->once()->andReturn($backups);
|
||||
$command = new DestroyImagick(array());
|
||||
$result = $command->execute($image);
|
||||
$this->assertTrue($result);
|
||||
|
@ -1562,8 +1562,12 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
||||
public function testDestroy()
|
||||
{
|
||||
$img = $this->manager()->make('tests/images/trim.png');
|
||||
$img->backup();
|
||||
$img->destroy();
|
||||
// destroy should affect core
|
||||
$this->assertEquals(get_resource_type($img->getCore()), 'Unknown');
|
||||
// destroy should affect backup
|
||||
$this->assertEquals(get_resource_type($img->getBackup()), 'Unknown');
|
||||
}
|
||||
|
||||
public function testStringConversion()
|
||||
|
@ -1555,6 +1555,17 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
|
||||
$img->getCore()->getImageWidth(); // try to get width (should throw exception)
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testDestroyWithBackup()
|
||||
{
|
||||
$img = $this->manager()->make('tests/images/trim.png');
|
||||
$img->backup();
|
||||
$img->destroy();
|
||||
$img->getBackup()->getImageWidth(); // try to get width (should throw exception)
|
||||
}
|
||||
|
||||
public function testStringConversion()
|
||||
{
|
||||
$img = $this->manager()->make('tests/images/trim.png');
|
||||
|
Loading…
x
Reference in New Issue
Block a user