diff --git a/src/Drivers/Abstract/Decoders/AbstractDecoder.php b/src/Drivers/Abstract/Decoders/AbstractDecoder.php index 93740041..953ba942 100644 --- a/src/Drivers/Abstract/Decoders/AbstractDecoder.php +++ b/src/Drivers/Abstract/Decoders/AbstractDecoder.php @@ -15,16 +15,16 @@ abstract class AbstractDecoder // } - final public function handle($input): null|ImageInterface|ColorInterface + final public function handle($input): ImageInterface|ColorInterface { try { $decoded = $this->decode($input); } catch (DecoderException $e) { - if ($this->hasSuccessor()) { - return $this->successor->handle($input); + if (!$this->hasSuccessor()) { + $this->fail(); } - $this->fail(); + return $this->successor->handle($input); } return $decoded; diff --git a/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php b/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php index 157c3474..7d567344 100644 --- a/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php +++ b/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php @@ -6,6 +6,7 @@ namespace Intervention\Image\Tests\Drivers\Abstract\Decoders; use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder; use Intervention\Image\Exceptions\DecoderException; +use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Tests\TestCase; use Mockery; @@ -16,31 +17,36 @@ class AbstractDecoderTest extends TestCase { public function testHandle(): void { + $result = Mockery::mock(ColorInterface::class); $decoder = Mockery::mock(AbstractDecoder::class)->makePartial(); - $decoder->shouldReceive('decode')->with('input string')->andReturn(null); + $decoder->shouldReceive('decode')->with('test input')->andReturn($result); - $decoder->handle('input string'); + $decoder->handle('test input'); } public function testHandleFail(): void { $decoder = Mockery::mock(AbstractDecoder::class, [])->makePartial()->shouldAllowMockingProtectedMethods(); - $decoder->shouldReceive('decode')->with('input string')->andThrow(DecoderException::class); + $decoder->shouldReceive('decode')->with('test input')->andThrow(DecoderException::class); $this->expectException(DecoderException::class); $this->expectExceptionMessage('Unable to decode given input.'); - $decoder->handle('input string'); + $decoder->handle('test input'); } public function testHandleFailWithSuccessor(): void { + $result = Mockery::mock(ColorInterface::class); $successor = Mockery::mock(AbstractDecoder::class)->makePartial(); - $successor->shouldReceive('decode')->with('input string')->andReturn(null); + $successor->shouldReceive('decode')->with('test input')->andReturn($result); - $decoder = Mockery::mock(AbstractDecoder::class, [$successor])->makePartial()->shouldAllowMockingProtectedMethods(); - $decoder->shouldReceive('decode')->with('input string')->andThrow(DecoderException::class); + $decoder = Mockery::mock( + AbstractDecoder::class, + [$successor] + )->makePartial()->shouldAllowMockingProtectedMethods(); + $decoder->shouldReceive('decode')->with('test input')->andThrow(DecoderException::class); - $decoder->handle('input string'); + $decoder->handle('test input'); } }