From 6dd434c2949bca912927a8dc960c1958061f88d8 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 22 May 2022 10:59:38 +0200 Subject: [PATCH] Add exception message to AbstractDecoder::fail() --- src/Drivers/Abstract/Decoders/AbstractDecoder.php | 6 +++--- tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Drivers/Abstract/Decoders/AbstractDecoder.php b/src/Drivers/Abstract/Decoders/AbstractDecoder.php index a40e0264..a1ee53ea 100644 --- a/src/Drivers/Abstract/Decoders/AbstractDecoder.php +++ b/src/Drivers/Abstract/Decoders/AbstractDecoder.php @@ -22,7 +22,7 @@ abstract class AbstractDecoder implements DecoderInterface $decoded = $this->decode($input); } catch (DecoderException $e) { if (!$this->hasSuccessor()) { - $this->fail(); + $this->fail($e->getMessage()); } return $this->successor->handle($input); @@ -36,9 +36,9 @@ abstract class AbstractDecoder implements DecoderInterface return $this->successor !== null; } - protected function fail(): void + protected function fail(string $message = 'Unable to decode given input.'): void { - throw new DecoderException("Unable to decode given input."); + throw new DecoderException($message); } protected function inputType($input): AbstractType diff --git a/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php b/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php index 7d567344..b6d7f261 100644 --- a/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php +++ b/tests/Drivers/Abstract/Decoders/AbstractDecoderTest.php @@ -30,7 +30,6 @@ class AbstractDecoderTest extends TestCase $decoder->shouldReceive('decode')->with('test input')->andThrow(DecoderException::class); $this->expectException(DecoderException::class); - $this->expectExceptionMessage('Unable to decode given input.'); $decoder->handle('test input'); }