Skip to content

Commit a347f5c

Browse files
authored
Merge pull request #7 from violet-php/separate-github-jobs
Separate GitHub jobs
2 parents 840aa63 + 4443bbf commit a347f5c

File tree

12 files changed

+242
-73
lines changed

12 files changed

+242
-73
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "Setup Composer"
2+
description: "Sets up the composer dependencies"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Get Composer Cache Directory
7+
id: composer-cache
8+
run: |
9+
echo "::set-output name=dir::$(composer config cache-files-dir)"
10+
shell: bash
11+
- uses: actions/cache@v2
12+
with:
13+
path: ${{ steps.composer-cache.outputs.dir }}
14+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
15+
restore-keys: |
16+
${{ runner.os }}-composer-
17+
- name: Install dependencies
18+
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
19+
shell: bash

.github/workflows/main.yml

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11-
tests:
11+
PHPUnit:
1212
strategy:
1313
matrix:
14-
operating-system: [ubuntu-latest]
15-
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
14+
operating-system: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
15+
php-versions: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
1616
runs-on: ${{ matrix.operating-system }}
1717
steps:
1818
- name: Checkout
@@ -22,60 +22,72 @@ jobs:
2222
with:
2323
php-version: ${{ matrix.php-versions }}
2424
coverage: none
25-
- name: Get composer cache directory
26-
id: composer-cache
27-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
28-
- name: Cache composer dependencies
29-
uses: actions/cache@v2
25+
ini-values: error_reporting=E_ALL
26+
- name: Setup Composer
27+
uses: ./.github/actions/setup-composer
28+
- name: Install PHPUnit
29+
run: composer require --dev phpunit/phpunit
30+
- name: Run PHPUnit
31+
run: composer test
32+
PHP_CodeSniffer:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v2
37+
- name: Setup PHP
38+
uses: shivammathur/setup-php@v2
3039
with:
31-
path: ${{ steps.composer-cache.outputs.dir }}
32-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
33-
restore-keys: ${{ runner.os }}-composer-
34-
- name: Install dependencies
35-
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
36-
- name: Setup problem matchers for PHPUnit
37-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
38-
- name: Test with phpunit
39-
run: vendor/bin/phpunit
40-
lint:
40+
php-version: latest
41+
coverage: none
42+
tools: phpcs
43+
- name: Setup Composer
44+
uses: ./.github/actions/setup-composer
45+
- name: Run PHP_CodeSniffer
46+
run: composer phpcs -- --no-cache
47+
PHP-CS-Fixer:
4148
runs-on: ubuntu-latest
4249
steps:
4350
- name: Checkout
4451
uses: actions/checkout@v2
4552
- name: Setup PHP
4653
uses: shivammathur/setup-php@v2
4754
with:
48-
php-version: '7.4'
55+
php-version: latest
4956
coverage: none
50-
tools: cs2pr, php-cs-fixer, phpcs
57+
tools: php-cs-fixer
58+
- name: Setup Composer
59+
uses: ./.github/actions/setup-composer
5160
- name: Run PHP Coding Standards Fixer
52-
run: php-cs-fixer fix --dry-run --using-cache=no --format=checkstyle | cs2pr
53-
- name: Run PHP_CodeSniffer
54-
run: phpcs --standard=PSR12 --exclude=PSR12.Properties.ConstantVisibility -q --report=checkstyle src tests | cs2pr
61+
run: composer php-cs-fixer -- --dry-run --diff --using-cache=no
62+
composer-normalize:
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v2
67+
- name: Setup PHP
68+
uses: shivammathur/setup-php@v2
69+
with:
70+
php-version: latest
71+
coverage: none
72+
tools: composer-normalize
73+
- name: Setup Composer
74+
uses: ./.github/actions/setup-composer
75+
- name: Run composer-normalize
76+
run: composer-normalize --dry-run
5577
coverage:
5678
runs-on: ubuntu-latest
5779
steps:
58-
- name: Checkout
59-
uses: actions/checkout@v2
60-
- name: Setup PHP
61-
uses: shivammathur/setup-php@v2
62-
with:
63-
php-version: '8.0'
64-
coverage: xdebug
65-
- name: Get composer cache directory
66-
id: composer-cache
67-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
68-
- name: Cache composer dependencies
69-
uses: actions/cache@v2
70-
with:
71-
path: ${{ steps.composer-cache.outputs.dir }}
72-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
73-
restore-keys: ${{ runner.os }}-composer-
74-
- name: Install dependencies
75-
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
76-
- name: Setup problem matchers for PHPUnit
77-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
78-
- name: Test with phpunit
79-
run: vendor/bin/phpunit --coverage-clover coverage.xml
80-
- name: Upload coverage
81-
uses: codecov/codecov-action@v1
80+
- name: Checkout
81+
uses: actions/checkout@v2
82+
- name: Setup PHP
83+
uses: shivammathur/setup-php@v2
84+
with:
85+
php-version: latest
86+
coverage: xdebug
87+
tools: phpunit
88+
- name: Setup Composer
89+
uses: ./.github/actions/setup-composer
90+
- name: Run PHPUnit with coverage
91+
run: composer test -- --do-not-cache-result --coverage-clover coverage.xml
92+
- name: Upload coverage
93+
uses: codecov/codecov-action@v1

.gitignore

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

.phpcs.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Project Coding Standard">
3+
<description>The coding standard configuration used for this project</description>
4+
5+
<file>./src/</file>
6+
<file>./tests/</file>
7+
8+
<exclude-pattern>*/vendor/*</exclude-pattern>
9+
<arg name="extensions" value="php" />
10+
11+
<rule ref="PSR12">
12+
<exclude name="PSR12.Properties.ConstantVisibility" />
13+
</rule>
14+
</ruleset>

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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
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"
2323
},
24-
"require-dev": {
25-
"phpunit/phpunit": "^5.7 || ^6.5 || ^9.4"
26-
},
2724
"autoload": {
2825
"psr-4": {
2926
"Violet\\StreamingJsonEncoder\\": "src/"
@@ -34,5 +31,16 @@
3431
"Violet\\StreamingJsonEncoder\\": "tests/tests/",
3532
"Violet\\StreamingJsonEncoder\\Test\\": "tests/classes/"
3633
}
34+
},
35+
"scripts": {
36+
"ci-all": [
37+
"composer test -- --do-not-cache-result",
38+
"composer phpcs -- --no-cache",
39+
"composer php-cs-fixer -- --dry-run --diff --using-cache=no",
40+
"composer normalize --dry-run"
41+
],
42+
"php-cs-fixer": "php-cs-fixer fix -v",
43+
"phpcs": "phpcs -p",
44+
"test": "phpunit"
3745
}
3846
}

composer.lock

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
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+
<exclude>
26+
<file>src/autoload.php</file>
27+
</exclude>
28+
</coverage>
1629
</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.

0 commit comments

Comments
 (0)