From 03431a215576a5ecb9e6dee66aa06bb84f98b3ce Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Fri, 11 Feb 2022 19:54:13 +0100 Subject: [PATCH] Fixed bug in ModifierStack, Added tests for apply method --- src/ModifierStack.php | 2 ++ tests/ModiferStackTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/ModifierStack.php b/src/ModifierStack.php index 13eac80a..109fbfc9 100644 --- a/src/ModifierStack.php +++ b/src/ModifierStack.php @@ -17,6 +17,8 @@ class ModifierStack implements ModifierInterface foreach ($this->modifiers as $modifier) { $modifier->apply($image); } + + return $image; } public function push(ModifierInterface $modifier): self diff --git a/tests/ModiferStackTest.php b/tests/ModiferStackTest.php index 8577d3c1..afe99234 100644 --- a/tests/ModiferStackTest.php +++ b/tests/ModiferStackTest.php @@ -3,7 +3,9 @@ namespace Intervention\Image\Tests; use Intervention\Image\Drivers\Gd\Modifiers\GreyscaleModifier; +use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\ModifierStack; +use Mockery; /** * @covers \Intervention\Image\ModifierStack @@ -22,4 +24,19 @@ class ModifierStackTest extends TestCase $result = $stack->push(new GreyscaleModifier()); $this->assertInstanceOf(ModifierStack::class, $result); } + + public function testApply(): void + { + $image = Mockery::mock(ImageInterface::class); + + $modifier1 = Mockery::mock(AbstractColor::class)->makePartial(); + $modifier1->shouldReceive('apply')->once()->with($image); + + $modifier2 = Mockery::mock(AbstractColor::class)->makePartial(); + $modifier2->shouldReceive('apply')->once()->with($image); + + $stack = new ModifierStack([$modifier1, $modifier2]); + $result = $stack->apply($image); + $this->assertInstanceOf(ImageInterface::class, $image); + } }