diff --git a/src/Intervention/Image/Gd/Commands/DestroyCommand.php b/src/Intervention/Image/Gd/Commands/DestroyCommand.php index a039b5fc..403e8b80 100644 --- a/src/Intervention/Image/Gd/Commands/DestroyCommand.php +++ b/src/Intervention/Image/Gd/Commands/DestroyCommand.php @@ -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; } } diff --git a/src/Intervention/Image/Imagick/Commands/DestroyCommand.php b/src/Intervention/Image/Imagick/Commands/DestroyCommand.php index 6aed1b46..28b9a4c3 100644 --- a/src/Intervention/Image/Imagick/Commands/DestroyCommand.php +++ b/src/Intervention/Image/Imagick/Commands/DestroyCommand.php @@ -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; } } diff --git a/tests/DestroyCommandTest.php b/tests/DestroyCommandTest.php index 999a7b9c..f2571964 100644 --- a/tests/DestroyCommandTest.php +++ b/tests/DestroyCommandTest.php @@ -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); diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php index 950aa3a9..5fdcd339 100644 --- a/tests/GdSystemTest.php +++ b/tests/GdSystemTest.php @@ -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() diff --git a/tests/ImagickSystemTest.php b/tests/ImagickSystemTest.php index 8cf597cc..89b8f8ee 100644 --- a/tests/ImagickSystemTest.php +++ b/tests/ImagickSystemTest.php @@ -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');