diff --git a/CHANGELOG.md b/CHANGELOG.md index a544ff0..ca306b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,6 @@ Security - in case of vulnerabilities. _TBD_ -## [0.1.0] 2018-12-08 +## [1.0.0] 2018-12-23 Initial release. diff --git a/src/BadFunctionCallException.php b/src/BadFunctionCallException.php index d519e91..d440166 100644 --- a/src/BadFunctionCallException.php +++ b/src/BadFunctionCallException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class BadFunctionCallException extends \BadFunctionCallException implements Throwable +class BadFunctionCallException extends \BadFunctionCallException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/BadMethodCallException.php b/src/BadMethodCallException.php index 7e4c00a..ea1bc93 100644 --- a/src/BadMethodCallException.php +++ b/src/BadMethodCallException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class BadMethodCallException extends \BadMethodCallException implements Throwable +class BadMethodCallException extends \BadMethodCallException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/DomainException.php b/src/DomainException.php index d64870b..3d42328 100644 --- a/src/DomainException.php +++ b/src/DomainException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class DomainException extends \DomainException implements Throwable +class DomainException extends \DomainException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/Throwable.php b/src/InformativeException.php similarity index 64% rename from src/Throwable.php rename to src/InformativeException.php index 5f75c02..7ae9d3c 100644 --- a/src/Throwable.php +++ b/src/InformativeException.php @@ -8,7 +8,7 @@ /** * Marker interface for exceptions with context information. */ -interface Throwable extends \Throwable +interface InformativeException extends \Throwable { - public function getContext() : array; + public function getContext(): array; } diff --git a/src/InvalidArgumentException.php b/src/InvalidArgumentException.php index 16d23be..7512dd5 100644 --- a/src/InvalidArgumentException.php +++ b/src/InvalidArgumentException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class InvalidArgumentException extends \InvalidArgumentException implements Throwable +class InvalidArgumentException extends \InvalidArgumentException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/LengthException.php b/src/LengthException.php index d657aa8..47dc88a 100644 --- a/src/LengthException.php +++ b/src/LengthException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class LengthException extends \LengthException implements Throwable +class LengthException extends \LengthException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/LogicException.php b/src/LogicException.php index 2f9aef9..a3fdb8b 100644 --- a/src/LogicException.php +++ b/src/LogicException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class LogicException extends \LogicException implements Throwable +class LogicException extends \LogicException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/OutOfBoundsException.php b/src/OutOfBoundsException.php index 823aea5..1bb3758 100644 --- a/src/OutOfBoundsException.php +++ b/src/OutOfBoundsException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class OutOfBoundsException extends \OutOfBoundsException implements Throwable +class OutOfBoundsException extends \OutOfBoundsException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/OutOfRangeException.php b/src/OutOfRangeException.php index 980c2e3..32a0d62 100644 --- a/src/OutOfRangeException.php +++ b/src/OutOfRangeException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class OutOfRangeException extends \OutOfRangeException implements Throwable +class OutOfRangeException extends \OutOfRangeException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/OverflowException.php b/src/OverflowException.php index 2ba2af7..dc4814b 100644 --- a/src/OverflowException.php +++ b/src/OverflowException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class OverflowException extends \OverflowException implements Throwable +class OverflowException extends \OverflowException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/RangeException.php b/src/RangeException.php index a60b3c7..7021340 100644 --- a/src/RangeException.php +++ b/src/RangeException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class RangeException extends \RangeException implements Throwable +class RangeException extends \RangeException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/RuntimeException.php b/src/RuntimeException.php index 65496c0..5958e79 100644 --- a/src/RuntimeException.php +++ b/src/RuntimeException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class RuntimeException extends \RuntimeException implements Throwable +class RuntimeException extends \RuntimeException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/ThrowableContextTrait.php b/src/ThrowableContextTrait.php index 09970b7..6efcbd1 100644 --- a/src/ThrowableContextTrait.php +++ b/src/ThrowableContextTrait.php @@ -9,14 +9,14 @@ trait ThrowableContextTrait { private $context = []; - public function __construct(string $message = '', array $context = [], int $code = 0, Throwable $previous = null) + public function __construct(string $message = '', array $context = [], int $code = 0, \Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->context = $context; } - public function getContext() : array + public function getContext(): array { return $this->context; } diff --git a/src/UnderflowException.php b/src/UnderflowException.php index 7fcb23f..8b45c9b 100644 --- a/src/UnderflowException.php +++ b/src/UnderflowException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class UnderflowException extends \UnderflowException implements Throwable +class UnderflowException extends \UnderflowException implements InformativeException { use ThrowableContextTrait; } diff --git a/src/UnexpectedValueException.php b/src/UnexpectedValueException.php index aeb6f5d..46da70f 100644 --- a/src/UnexpectedValueException.php +++ b/src/UnexpectedValueException.php @@ -5,7 +5,7 @@ namespace Zee\Exceptions; -class UnexpectedValueException extends \UnexpectedValueException implements Throwable +class UnexpectedValueException extends \UnexpectedValueException implements InformativeException { use ThrowableContextTrait; } diff --git a/tests/ReadExceptionContextTest.php b/tests/ReadExceptionContextTest.php index 4f80d12..2fbfafa 100644 --- a/tests/ReadExceptionContextTest.php +++ b/tests/ReadExceptionContextTest.php @@ -19,13 +19,15 @@ public function exceptionObjectShouldContainContext(string $exceptionClass): voi $message = 'Something went wrong'; $code = PHP_INT_MAX; $context = ['foo' => 'bar']; + $previous = new \Exception('Something went wrong'); - $exception = new $exceptionClass($message, $context, $code); + $exception = new $exceptionClass($message, $context, $code, $previous); - if ($exception instanceof Exceptions\Throwable) { + if ($exception instanceof Exceptions\InformativeException) { self::assertSame($message, $exception->getMessage()); self::assertSame($context, $exception->getContext()); self::assertSame($code, $exception->getCode()); + self::assertSame($previous, $exception->getPrevious()); } else { self::fail('Invalid exception class'); }