Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
support php 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Sep 8, 2023
1 parent f2a12e5 commit 98fc75e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
30 changes: 14 additions & 16 deletions src/StringStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand All @@ -34,74 +34,72 @@ 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) {
$offset = $length;
}

$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);
$this->content += $bytesWritten;
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 [];
}
Expand Down
3 changes: 2 additions & 1 deletion test/Integration/ErrorResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions test/Integration/JsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion test/Integration/TextResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,7 @@ public function testText(): void
$httpResponse
->expects($this->once())
->method('getBody')
->willReturn('true');
->willReturn(new StringStream('true'));

$httpResponse
->expects($this->once())
Expand Down

0 comments on commit 98fc75e

Please sign in to comment.