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

Commit 98fc75e

Browse files
committed
support php 8.2
1 parent f2a12e5 commit 98fc75e

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/StringStream.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public function __construct(private string $content)
1414
{
1515
}
1616

17-
public function __toString()
17+
public function __toString(): string
1818
{
1919
return $this->content;
2020
}
2121

22-
public function close()
22+
public function close(): void
2323
{
2424
}
2525

@@ -34,74 +34,72 @@ public function detach()
3434
return $handle;
3535
}
3636

37-
public function getSize()
37+
public function getSize(): int
3838
{
3939
return \strlen($this->content);
4040
}
4141

42-
public function tell()
42+
public function tell(): int
4343
{
4444
return $this->position;
4545
}
4646

47-
public function eof()
47+
public function eof(): bool
4848
{
4949
return $this->position >= \strlen($this->content);
5050
}
5151

52-
public function isSeekable()
52+
public function isSeekable(): bool
5353
{
5454
return true;
5555
}
5656

57-
public function seek($offset, $whence = SEEK_SET)
57+
public function seek(int $offset, int $whence = SEEK_SET): void
5858
{
5959
$length = \strlen($this->content);
6060
if ($length < $offset) {
6161
$offset = $length;
6262
}
6363

6464
$this->position = $offset;
65-
return 0;
6665
}
6766

68-
public function rewind()
67+
public function rewind(): void
6968
{
7069
$this->position = 0;
71-
return true;
7270
}
7371

74-
public function isWritable()
72+
public function isWritable(): bool
7573
{
7674
return true;
7775
}
7876

79-
public function write($string)
77+
public function write(string $string): int
8078
{
8179
$this->content = \substr_replace($this->content, $string, $this->position, \strlen($string));
8280
$bytesWritten = \strlen($string);
8381
$this->content += $bytesWritten;
8482
return $bytesWritten;
8583
}
8684

87-
public function isReadable()
85+
public function isReadable(): bool
8886
{
8987
return true;
9088
}
9189

92-
public function read($length)
90+
public function read(int $length): string
9391
{
9492
$result = \substr($this->content, $this->position, $length);
9593
$this->position += \strlen($result);
9694
return $result;
9795
}
9896

99-
public function getContents()
97+
public function getContents(): string
10098
{
10199
return \substr($this->content, $this->position);
102100
}
103101

104-
public function getMetadata($key = null)
102+
public function getMetadata(?string $key = null)
105103
{
106104
return [];
107105
}

test/Integration/ErrorResponseTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Genkgo\Api\Connection;
88
use Genkgo\Api\Exception\ResponseException;
9+
use Genkgo\Api\StringStream;
910
use GuzzleHttp\Client;
1011
use GuzzleHttp\Exception\ServerException;
1112
use GuzzleHttp\Psr7\HttpFactory;
@@ -28,7 +29,7 @@ public function testClientError(): void
2829
$httpResponse
2930
->expects($this->any())
3031
->method('getBody')
31-
->willReturn('error message');
32+
->willReturn(new StringStream('error message'));
3233

3334
$client
3435
->expects($this->once())

test/Integration/JsonResponseTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Genkgo\Api\Connection;
88
use Genkgo\Api\Response;
9+
use Genkgo\Api\StringStream;
910
use GuzzleHttp\Client;
1011
use GuzzleHttp\Psr7\HttpFactory;
1112
use PHPUnit\Framework\TestCase;
@@ -36,7 +37,7 @@ function (RequestInterface $request) {
3637
$httpResponse
3738
->expects($this->once())
3839
->method('getBody')
39-
->willReturn(\json_encode([['id' => 1, 'name' => 'Top Element']]));
40+
->willReturn(new StringStream(\json_encode([['id' => 1, 'name' => 'Top Element']])));
4041

4142
$httpResponse
4243
->expects($this->once())
@@ -66,7 +67,7 @@ public function testJsonWithCharset(): void
6667
$httpResponse
6768
->expects($this->once())
6869
->method('getBody')
69-
->willReturn(\json_encode([['id' => 1, 'name' => 'Top Element']]));
70+
->willReturn(new StringStream(\json_encode([['id' => 1, 'name' => 'Top Element']])));
7071

7172
$httpResponse
7273
->expects($this->once())

test/Integration/TextResponseTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Genkgo\Api\Connection;
88
use Genkgo\Api\Response;
9+
use Genkgo\Api\StringStream;
910
use GuzzleHttp\Client;
1011
use GuzzleHttp\Psr7\HttpFactory;
1112
use PHPUnit\Framework\TestCase;
@@ -28,7 +29,7 @@ public function testText(): void
2829
$httpResponse
2930
->expects($this->once())
3031
->method('getBody')
31-
->willReturn('true');
32+
->willReturn(new StringStream('true'));
3233

3334
$httpResponse
3435
->expects($this->once())

0 commit comments

Comments
 (0)