diff --git a/src/Factory/Psr17Factory.php b/src/Factory/Psr17Factory.php index 0726b68..f304baa 100644 --- a/src/Factory/Psr17Factory.php +++ b/src/Factory/Psr17Factory.php @@ -40,15 +40,15 @@ public function createStreamFromFile(string $filename, string $mode = 'r'): Stre try { $resource = @\fopen($filename, $mode); } catch (\Throwable $e) { - throw new \RuntimeException('The file ' . $filename . ' cannot be opened.'); + throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $filename)); } if (false === $resource) { if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true)) { - throw new \InvalidArgumentException('The mode ' . $mode . ' is invalid.'); + throw new \InvalidArgumentException(\sprintf('The mode "%s" is invalid.', $mode)); } - throw new \RuntimeException('The file ' . $filename . ' cannot be opened.'); + throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $filename)); } return Stream::create($resource); diff --git a/src/Stream.php b/src/Stream.php index fee0c63..f1dc804 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -210,7 +210,7 @@ public function seek($offset, $whence = \SEEK_SET): void } if (-1 === \fseek($this->stream, $offset, $whence)) { - throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . \var_export($whence, true)); + throw new \RuntimeException('Unable to seek to stream position "' . $offset . '" with whence ' . \var_export($whence, true)); } } diff --git a/src/UploadedFile.php b/src/UploadedFile.php index 3c0d098..198cd33 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -117,7 +117,7 @@ public function getStream(): StreamInterface try { return Stream::create(\fopen($this->file, 'r')); } catch (\Throwable $e) { - throw new \RuntimeException('The file ' . $this->file . ' cannot be opened.'); + throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $this->file)); } } @@ -141,7 +141,7 @@ public function moveTo($targetPath): void // Copy the contents of a stream into another stream until end-of-file. $dest = Stream::create(\fopen($targetPath, 'w')); } catch (\Throwable $e) { - throw new \RuntimeException('The file ' . $targetPath . ' cannot be opened.'); + throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $targetPath)); } while (!$stream->eof()) { @@ -154,7 +154,7 @@ public function moveTo($targetPath): void } if (false === $this->moved) { - throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath)); + throw new \RuntimeException(\sprintf('Uploaded file could not be moved to "%s"', $targetPath)); } } diff --git a/src/Uri.php b/src/Uri.php index eee304f..13fbf72 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -50,7 +50,7 @@ public function __construct(string $uri = '') { if ('' !== $uri) { if (false === $parts = \parse_url($uri)) { - throw new \InvalidArgumentException("Unable to parse URI: $uri"); + throw new \InvalidArgumentException(\sprintf('Unable to parse URI: "%s"', $uri)); } // Apply parse_url parts to a URI. diff --git a/tests/RequestTest.php b/tests/RequestTest.php index ddac6d2..392b032 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -28,7 +28,7 @@ public function testRequestUriMayBeUri() public function testValidateRequestUri() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Unable to parse URI: ///'); + $this->expectExceptionMessage('Unable to parse URI: "///"'); new Request('GET', '///'); }