From effb7e299977b9e2039297f7cf3fd77197ced02e Mon Sep 17 00:00:00 2001 From: fenric Date: Sun, 18 Nov 2018 13:55:22 +0300 Subject: [PATCH] All exceptions inherit RuntimeException --- src/Exception/Exception.php | 23 --------------------- src/Exception/InvalidArgumentException.php | 18 ---------------- src/Exception/UnopenableStreamException.php | 7 ++++++- src/Exception/UnreadableStreamException.php | 7 ++++++- src/Exception/UnseekableStreamException.php | 7 ++++++- src/Exception/UntellableStreamException.php | 7 ++++++- src/Exception/UnwritableStreamException.php | 7 ++++++- src/Stream.php | 4 ++-- tests/StreamTest.php | 16 ++++++-------- 9 files changed, 38 insertions(+), 58 deletions(-) delete mode 100644 src/Exception/Exception.php delete mode 100644 src/Exception/InvalidArgumentException.php diff --git a/src/Exception/Exception.php b/src/Exception/Exception.php deleted file mode 100644 index e393a97..0000000 --- a/src/Exception/Exception.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @copyright Copyright (c) 2018, Anatoly Fenric - * @license https://github.com/sunrise-php/stream/blob/master/LICENSE - * @link https://github.com/sunrise-php/stream - */ - -namespace Sunrise\Stream\Exception; - -/** - * Import classes - */ -use RuntimeException; - -/** - * Exception - */ -class Exception extends RuntimeException -{} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php deleted file mode 100644 index 6ee93f9..0000000 --- a/src/Exception/InvalidArgumentException.php +++ /dev/null @@ -1,18 +0,0 @@ - - * @copyright Copyright (c) 2018, Anatoly Fenric - * @license https://github.com/sunrise-php/stream/blob/master/LICENSE - * @link https://github.com/sunrise-php/stream - */ - -namespace Sunrise\Stream\Exception; - -/** - * InvalidArgumentException - */ -class InvalidArgumentException extends Exception -{} diff --git a/src/Exception/UnopenableStreamException.php b/src/Exception/UnopenableStreamException.php index fc73f92..9acfde7 100644 --- a/src/Exception/UnopenableStreamException.php +++ b/src/Exception/UnopenableStreamException.php @@ -11,8 +11,13 @@ namespace Sunrise\Stream\Exception; +/** + * Import classes + */ +use RuntimeException; + /** * UnopenableStreamException */ -class UnopenableStreamException extends Exception +class UnopenableStreamException extends RuntimeException {} diff --git a/src/Exception/UnreadableStreamException.php b/src/Exception/UnreadableStreamException.php index 0e42650..316435d 100644 --- a/src/Exception/UnreadableStreamException.php +++ b/src/Exception/UnreadableStreamException.php @@ -11,8 +11,13 @@ namespace Sunrise\Stream\Exception; +/** + * Import classes + */ +use RuntimeException; + /** * UnreadableStreamException */ -class UnreadableStreamException extends Exception +class UnreadableStreamException extends RuntimeException {} diff --git a/src/Exception/UnseekableStreamException.php b/src/Exception/UnseekableStreamException.php index e065787..6721b3d 100644 --- a/src/Exception/UnseekableStreamException.php +++ b/src/Exception/UnseekableStreamException.php @@ -11,8 +11,13 @@ namespace Sunrise\Stream\Exception; +/** + * Import classes + */ +use RuntimeException; + /** * UnseekableStreamException */ -class UnseekableStreamException extends Exception +class UnseekableStreamException extends RuntimeException {} diff --git a/src/Exception/UntellableStreamException.php b/src/Exception/UntellableStreamException.php index 7dc08b1..52fac44 100644 --- a/src/Exception/UntellableStreamException.php +++ b/src/Exception/UntellableStreamException.php @@ -11,8 +11,13 @@ namespace Sunrise\Stream\Exception; +/** + * Import classes + */ +use RuntimeException; + /** * UntellableStreamException */ -class UntellableStreamException extends Exception +class UntellableStreamException extends RuntimeException {} diff --git a/src/Exception/UnwritableStreamException.php b/src/Exception/UnwritableStreamException.php index 4224a7c..93c4d5c 100644 --- a/src/Exception/UnwritableStreamException.php +++ b/src/Exception/UnwritableStreamException.php @@ -11,8 +11,13 @@ namespace Sunrise\Stream\Exception; +/** + * Import classes + */ +use RuntimeException; + /** * UnwritableStreamException */ -class UnwritableStreamException extends Exception +class UnwritableStreamException extends RuntimeException {} diff --git a/src/Stream.php b/src/Stream.php index f525aff..90a4955 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -36,13 +36,13 @@ class Stream implements StreamInterface * * @param resource $resource * - * @throws Exception\InvalidArgumentException + * @throws \InvalidArgumentException */ public function __construct($resource) { if (! \is_resource($resource)) { - throw new Exception\InvalidArgumentException('Invalid stream resource'); + throw new \InvalidArgumentException('Invalid stream resource'); } $this->resource = $resource; diff --git a/tests/StreamTest.php b/tests/StreamTest.php index efc9e10..a72cecb 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -4,8 +4,6 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\StreamInterface; -use Sunrise\Stream\Exception\Exception; -use Sunrise\Stream\Exception\InvalidArgumentException; use Sunrise\Stream\Exception\UnopenableStreamException; use Sunrise\Stream\Exception\UnreadableStreamException; use Sunrise\Stream\Exception\UnseekableStreamException; @@ -261,7 +259,7 @@ public function testToString() public function testConstructorWithInvalidResource() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid stream resource'); new Stream(''); @@ -402,13 +400,11 @@ public function testToStringUnreadable() public function testExceptions() { - $this->assertInstanceOf(\RuntimeException::class, new Exception('')); - $this->assertInstanceOf(Exception::class, new InvalidArgumentException('')); - $this->assertInstanceOf(Exception::class, new UnopenableStreamException('')); - $this->assertInstanceOf(Exception::class, new UnreadableStreamException('')); - $this->assertInstanceOf(Exception::class, new UnseekableStreamException('')); - $this->assertInstanceOf(Exception::class, new UntellableStreamException('')); - $this->assertInstanceOf(Exception::class, new UnwritableStreamException('')); + $this->assertInstanceOf(\RuntimeException::class, new UnopenableStreamException('')); + $this->assertInstanceOf(\RuntimeException::class, new UnreadableStreamException('')); + $this->assertInstanceOf(\RuntimeException::class, new UnseekableStreamException('')); + $this->assertInstanceOf(\RuntimeException::class, new UntellableStreamException('')); + $this->assertInstanceOf(\RuntimeException::class, new UnwritableStreamException('')); } private function assertStreamResourceEquals(StreamInterface $stream, $expected)