Skip to content

Commit 7def906

Browse files
committed
Fix additional deprecations
1 parent fc0a20c commit 7def906

File tree

9 files changed

+54
-22
lines changed

9 files changed

+54
-22
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
php-version: ${{ matrix.php-versions }}
2424
coverage: none
2525
tools: phpunit
26+
ini-values: error_reporting=E_ALL
2627
- name: Setup Composer
2728
uses: ./.github/actions/setup-composer
2829
- name: Run PHPUnit

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
.phpunit.cache/
12
build/
23
vendor/
34
.php-cs-fixer.cache
4-
.phpunit.result.cache
55
composer.lock

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog #
22

3+
## v1.1.4 (2022-01-02) ##
4+
5+
* Improve Github action workflow
6+
* Fix additional PHP 8.1 deprecations
7+
* Fix issue with `JsonStream::getContents()` no returning buffer contents
8+
39
## v1.1.3 (2021-12-27) ##
410

511
* Add support for PHP 8.1

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"name": "violet/streaming-json-encoder",
3-
"type": "library",
43
"description": "Library for iteratively encoding large JSON documents piece by piece",
5-
"homepage": "http://violet.riimu.net",
4+
"license": "MIT",
5+
"type": "library",
66
"keywords": [
77
"streaming",
88
"json",
99
"encoder",
1010
"psr-7"
1111
],
12-
"license": "MIT",
1312
"authors": [
1413
{
1514
"name": "Riikka Kalliomäki",
1615
"email": "[email protected]",
1716
"homepage": "http://riimu.net"
1817
}
1918
],
19+
"homepage": "http://violet.riimu.net",
2020
"require": {
2121
"php": ">=5.6.0",
2222
"psr/http-message": "^1.0"

phpunit.xml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="tests/bootstrap.php">
3-
<testsuites>
4-
<testsuite name="Default">
5-
<directory suffix="Test.php">tests/tests/</directory>
6-
</testsuite>
7-
</testsuites>
8-
<filter>
9-
<whitelist processUncoveredFilesFromWhitelist="true">
10-
<directory suffix=".php">src/</directory>
11-
<exclude>
12-
<file>src/autoload.php</file>
13-
</exclude>
14-
</whitelist>
15-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheResultFile=".phpunit.cache/test-results"
6+
executionOrder="depends,defects"
7+
beStrictAboutCoversAnnotation="true"
8+
beStrictAboutOutputDuringTests="true"
9+
beStrictAboutTodoAnnotatedTests="true"
10+
convertDeprecationsToExceptions="true"
11+
failOnRisky="true"
12+
failOnWarning="true"
13+
verbose="true">
14+
<testsuites>
15+
<testsuite name="default">
16+
<directory>tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<coverage cacheDirectory=".phpunit.cache/code-coverage"
21+
processUncoveredFiles="true">
22+
<include>
23+
<directory suffix=".php">src</directory>
24+
</include>
25+
</coverage>
1626
</phpunit>

src/JsonStream.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ public function isReadable()
261261
*/
262262
public function read($length)
263263
{
264+
if ($this->eof()) {
265+
return '';
266+
}
267+
264268
$length = max(0, (int) $length);
265269
$encoder = $this->getEncoder();
266270

@@ -288,8 +292,12 @@ public function read($length)
288292
*/
289293
public function getContents()
290294
{
295+
if ($this->eof()) {
296+
return '';
297+
}
298+
291299
$encoder = $this->getEncoder();
292-
$output = '';
300+
$output = $this->buffer;
293301

294302
while ($encoder->valid()) {
295303
$output .= $encoder->current();

tests/bootstrap.php

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/classes/SerializableData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct($data)
2323
$this->data = $data;
2424
}
2525

26+
#[\ReturnTypeWillChange]
2627
public function jsonSerialize()
2728
{
2829
return $this->data;

tests/tests/JsonStreamTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,13 @@ public function testPrettyPrintStream()
139139
$stream = new JsonStream($encoder);
140140
$this->assertSame("[\n \"value\"\n]", $stream->getContents());
141141
}
142+
143+
public function testGetRemainingContents()
144+
{
145+
$encoder = (new BufferJsonEncoder(['value']));
146+
$stream = new JsonStream($encoder);
147+
148+
$this->assertSame('["val', $stream->read(5));
149+
$this->assertSame('ue"]', $stream->getContents());
150+
}
142151
}

0 commit comments

Comments
 (0)