Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improvements #3

Merged
merged 6 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .github/workflows/phpstan.yml

This file was deleted.

84 changes: 66 additions & 18 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ on:
pull_request:

jobs:
build-test:
unittests:
runs-on: ubuntu-latest

strategy:
matrix:
php-version: ["8.0", "8.1", "8.2", "8.3"]

name: PHP ${{ matrix.php-version }} tests
steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
extensions: brotli zstd zlib
php-version: ${{ matrix.php-version }}
extensions: brotli, zstd, zlib
tools: composer

- name: Get composer cache directory
Expand All @@ -31,25 +38,66 @@ jobs:

- name: Install dependencies
run: |
composer install --prefer-dist
sudo apt-get install brotli zstd gzip -y
composer install --prefer-dist
sudo apt-get update -y
sudo apt-get install brotli zstd gzip -y

- run: php -m

- name: Start the server
working-directory: tests
run: nohup php -S localhost:8000 &

- name: Test gzip
- name: Test with content encoding
run: |
output=$(curl localhost:8000 -s -H "Accept-Encoding: gzip" | gzip -d -)
if [ ! "$output" == "Hello, world!" ]; then exit 1; fi
for encoding in gzip brotli zstd; do
echo "Testing ${encoding}:"
if [ "$encoding" == "brotli" ]; then
output=$(curl localhost:8000 -s -H "Accept-Encoding: br" | brotli -d -)
else
output=$(curl localhost:8000 -s -H "Accept-Encoding: ${encoding}" | ${encoding} -d -)
fi
if [ ! "$output" == "Hello, world!" ]; then
echo "Encoding: ${encoding} did not work correctly."
exit 1
fi
done

- name: Test brotli
- name: Test identity
run: |
output=$(curl localhost:8000 -s -H "Accept-Encoding: br" | brotli -d -)
if [ ! "$output" == "Hello, world!" ]; then exit 1; fi

# TODO: zstd appears to not be installed / loaded in PHP
#- name: Test zstd
# run: |
# output=$(curl localhost:8000 -s -H "Accept-Encoding: zstd" | zstd -d -)
# if [ ! "$output" == "Hello, world!" ]; then exit 1; fi
output=$(curl localhost:8000 -s -H "Accept-Encoding: *")
if [ ! "$output" == "Hello, world!" ]; then exit 1; fi

output=$(curl localhost:8000 -s -H "Accept-Encoding: identity")
if [ ! "$output" == "Hello, world!" ]; then exit 1; fi

phpstan:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
extensions: brotli, zstd, zlib
tools: composer

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Run PHPStan
run: php vendor/bin/phpstan analyse src --level 9
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

/vendor
.php-cs-fixer.cache
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![PHPStan Level](https://img.shields.io/badge/PHPStan-level%209-brightgreen)
[![Unit Tests](https://github.com/HostByBelle/CompressionBuffer/actions/workflows/unittest.yml/badge.svg)](https://github.com/HostByBelle/CompressionBuffer/actions/workflows/unittest.yml)
![Packagist Downloads](https://img.shields.io/packagist/dt/HostByBelle/CompressionBuffer)
![Packagist Version](https://img.shields.io/packagist/v/HostByBelle/CompressionBuffer)

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"sort-packages": true
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.53",
"phpstan/phpstan": "^1.10"
}
}
Loading