From 98fc75e377151b9cce746359fac6d754a47dd09a Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Fri, 8 Sep 2023 14:44:01 +0200 Subject: [PATCH] support php 8.2 --- src/StringStream.php | 30 ++++++++++++-------------- test/Integration/ErrorResponseTest.php | 3 ++- test/Integration/JsonResponseTest.php | 5 +++-- test/Integration/TextResponseTest.php | 3 ++- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/StringStream.php b/src/StringStream.php index 0690618..c7e1755 100644 --- a/src/StringStream.php +++ b/src/StringStream.php @@ -14,12 +14,12 @@ public function __construct(private string $content) { } - public function __toString() + public function __toString(): string { return $this->content; } - public function close() + public function close(): void { } @@ -34,27 +34,27 @@ public function detach() return $handle; } - public function getSize() + public function getSize(): int { return \strlen($this->content); } - public function tell() + public function tell(): int { return $this->position; } - public function eof() + public function eof(): bool { return $this->position >= \strlen($this->content); } - public function isSeekable() + public function isSeekable(): bool { return true; } - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { $length = \strlen($this->content); if ($length < $offset) { @@ -62,21 +62,19 @@ public function seek($offset, $whence = SEEK_SET) } $this->position = $offset; - return 0; } - public function rewind() + public function rewind(): void { $this->position = 0; - return true; } - public function isWritable() + public function isWritable(): bool { return true; } - public function write($string) + public function write(string $string): int { $this->content = \substr_replace($this->content, $string, $this->position, \strlen($string)); $bytesWritten = \strlen($string); @@ -84,24 +82,24 @@ public function write($string) return $bytesWritten; } - public function isReadable() + public function isReadable(): bool { return true; } - public function read($length) + public function read(int $length): string { $result = \substr($this->content, $this->position, $length); $this->position += \strlen($result); return $result; } - public function getContents() + public function getContents(): string { return \substr($this->content, $this->position); } - public function getMetadata($key = null) + public function getMetadata(?string $key = null) { return []; } diff --git a/test/Integration/ErrorResponseTest.php b/test/Integration/ErrorResponseTest.php index cd56085..fc6c4c4 100644 --- a/test/Integration/ErrorResponseTest.php +++ b/test/Integration/ErrorResponseTest.php @@ -6,6 +6,7 @@ use Genkgo\Api\Connection; use Genkgo\Api\Exception\ResponseException; +use Genkgo\Api\StringStream; use GuzzleHttp\Client; use GuzzleHttp\Exception\ServerException; use GuzzleHttp\Psr7\HttpFactory; @@ -28,7 +29,7 @@ public function testClientError(): void $httpResponse ->expects($this->any()) ->method('getBody') - ->willReturn('error message'); + ->willReturn(new StringStream('error message')); $client ->expects($this->once()) diff --git a/test/Integration/JsonResponseTest.php b/test/Integration/JsonResponseTest.php index 9d3cf89..95238da 100644 --- a/test/Integration/JsonResponseTest.php +++ b/test/Integration/JsonResponseTest.php @@ -6,6 +6,7 @@ use Genkgo\Api\Connection; use Genkgo\Api\Response; +use Genkgo\Api\StringStream; use GuzzleHttp\Client; use GuzzleHttp\Psr7\HttpFactory; use PHPUnit\Framework\TestCase; @@ -36,7 +37,7 @@ function (RequestInterface $request) { $httpResponse ->expects($this->once()) ->method('getBody') - ->willReturn(\json_encode([['id' => 1, 'name' => 'Top Element']])); + ->willReturn(new StringStream(\json_encode([['id' => 1, 'name' => 'Top Element']]))); $httpResponse ->expects($this->once()) @@ -66,7 +67,7 @@ public function testJsonWithCharset(): void $httpResponse ->expects($this->once()) ->method('getBody') - ->willReturn(\json_encode([['id' => 1, 'name' => 'Top Element']])); + ->willReturn(new StringStream(\json_encode([['id' => 1, 'name' => 'Top Element']]))); $httpResponse ->expects($this->once()) diff --git a/test/Integration/TextResponseTest.php b/test/Integration/TextResponseTest.php index d55240c..03e1f26 100644 --- a/test/Integration/TextResponseTest.php +++ b/test/Integration/TextResponseTest.php @@ -6,6 +6,7 @@ use Genkgo\Api\Connection; use Genkgo\Api\Response; +use Genkgo\Api\StringStream; use GuzzleHttp\Client; use GuzzleHttp\Psr7\HttpFactory; use PHPUnit\Framework\TestCase; @@ -28,7 +29,7 @@ public function testText(): void $httpResponse ->expects($this->once()) ->method('getBody') - ->willReturn('true'); + ->willReturn(new StringStream('true')); $httpResponse ->expects($this->once())