mirror of
https://github.com/Intervention/image.git
synced 2025-08-16 19:04:00 +02:00
destroy() now also frees memory of backup
This commit is contained in:
@@ -12,6 +12,14 @@ class DestroyCommand extends \Intervention\Image\Commands\AbstractCommand
|
|||||||
*/
|
*/
|
||||||
public function execute($image)
|
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)
|
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()
|
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 = Mockery::mock('Intervention\Image\Image');
|
||||||
$image->shouldReceive('getCore')->once()->andReturn($resource);
|
$image->shouldReceive('getCore')->once()->andReturn($resource);
|
||||||
|
$image->shouldReceive('getBackups')->once()->andReturn($backups);
|
||||||
$command = new DestroyGd(array());
|
$command = new DestroyGd(array());
|
||||||
$result = $command->execute($image);
|
$result = $command->execute($image);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
@@ -24,8 +30,14 @@ class DestroyCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$imagick = Mockery::mock('Imagick');
|
$imagick = Mockery::mock('Imagick');
|
||||||
$imagick->shouldReceive('clear')->with()->andReturn(true);
|
$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 = Mockery::mock('Intervention\Image\Image');
|
||||||
$image->shouldReceive('getCore')->once()->andReturn($imagick);
|
$image->shouldReceive('getCore')->once()->andReturn($imagick);
|
||||||
|
$image->shouldReceive('getBackups')->once()->andReturn($backups);
|
||||||
$command = new DestroyImagick(array());
|
$command = new DestroyImagick(array());
|
||||||
$result = $command->execute($image);
|
$result = $command->execute($image);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
@@ -1562,8 +1562,12 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/trim.png');
|
$img = $this->manager()->make('tests/images/trim.png');
|
||||||
|
$img->backup();
|
||||||
$img->destroy();
|
$img->destroy();
|
||||||
|
// destroy should affect core
|
||||||
$this->assertEquals(get_resource_type($img->getCore()), 'Unknown');
|
$this->assertEquals(get_resource_type($img->getCore()), 'Unknown');
|
||||||
|
// destroy should affect backup
|
||||||
|
$this->assertEquals(get_resource_type($img->getBackup()), 'Unknown');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStringConversion()
|
public function testStringConversion()
|
||||||
|
@@ -1555,6 +1555,17 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$img->getCore()->getImageWidth(); // try to get width (should throw exception)
|
$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()
|
public function testStringConversion()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/trim.png');
|
$img = $this->manager()->make('tests/images/trim.png');
|
||||||
|
Reference in New Issue
Block a user