From 9d8eb9a6f16b12a3d049889b28a9bf3875dcd6f0 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Sun, 19 Nov 2023 01:01:11 +0400 Subject: [PATCH] Add phpunit in CI --- .github/workflows/run-test-suite.yml | 112 ++++++++++++++++++ .github/workflows/testing.yml | 11 ++ phpunit.xml | 7 +- tests/{ => Unit}/FiberTrait.php | 2 +- .../Traffic/Dispatcher/HttpTest.php | 2 +- tests/{ => Unit}/Traffic/Emitter/HttpTest.php | 4 +- .../Traffic/Message/Multipart/FieldTest.php | 2 +- .../Traffic/Message/Multipart/FileTest.php | 2 +- .../Traffic/Parser/HttpParserTest.php | 12 +- .../Parser/MultipartBodyParserTest.php | 8 +- .../Traffic/Parser/SmtpParserTest.php | 4 +- .../Traffic/Proto/Server/Version/V1Test.php | 2 +- 12 files changed, 146 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/run-test-suite.yml create mode 100644 .github/workflows/testing.yml rename tests/{ => Unit}/FiberTrait.php (96%) rename tests/{ => Unit}/Traffic/Dispatcher/HttpTest.php (93%) rename tests/{ => Unit}/Traffic/Emitter/HttpTest.php (95%) rename tests/{ => Unit}/Traffic/Message/Multipart/FieldTest.php (95%) rename tests/{ => Unit}/Traffic/Message/Multipart/FileTest.php (96%) rename tests/{ => Unit}/Traffic/Parser/HttpParserTest.php (94%) rename tests/{ => Unit}/Traffic/Parser/MultipartBodyParserTest.php (94%) rename tests/{ => Unit}/Traffic/Parser/SmtpParserTest.php (98%) rename tests/{ => Unit}/Traffic/Proto/Server/Version/V1Test.php (94%) diff --git a/.github/workflows/run-test-suite.yml b/.github/workflows/run-test-suite.yml new file mode 100644 index 00000000..10921b4b --- /dev/null +++ b/.github/workflows/run-test-suite.yml @@ -0,0 +1,112 @@ +name: Unit + +on: + workflow_call: + inputs: + test-suite: + required: true + type: string + fail-fast: + required: false + type: boolean + default: true + test-timeout: + required: false + type: number + default: 15 + + pull_request: + paths-ignore: + - 'docs/**' + - 'bin/**' + - 'resources/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - '.editorconfig' + - 'psalm.xml' + + push: + paths-ignore: + - 'docs/**' + - 'bin/**' + - 'resources/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - '.editorconfig' + - 'psalm.xml' + +jobs: + test: + name: (PHP ${{ matrix.php }}, ${{ matrix.os }}, ${{ matrix.dependencies }} deps + runs-on: ${{ matrix.os }} + timeout-minutes: ${{ matrix.timeout-minutes }} + env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' } + strategy: + fail-fast: ${{ inputs.fail-fast }} + matrix: + php: [ 8.1, 8.2 ] + os: [ ubuntu-latest, windows-latest ] + dependencies: [ lowest , highest ] + timeout-minutes: [ '${{ inputs.test-timeout }}' ] + exclude: + - os: windows-latest + php: 8.2 + include: + - os: ubuntu-latest + php: 8.3 + dependencies: highest + timeout-minutes: 40 + steps: + - name: Set Git To Use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + extensions: sockets, curl + + - name: Check Out Code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache Composer Dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: php-${{ matrix.php }}-${{ matrix.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + php-${{ matrix.php }}-${{ matrix.os }}-composer- + + - name: Install lowest dependencies from composer.json + if: matrix.dependencies == 'lowest' + run: composer update --no-interaction --no-progress --prefer-lowest + + - name: Validate lowest dependencies + if: matrix.dependencies == 'lowest' + env: + COMPOSER_POOL_OPTIMIZER: 0 + run: vendor/bin/validate-prefer-lowest + + - name: Install highest dependencies from composer.json + if: matrix.dependencies == 'highest' + run: composer update --no-interaction --no-progress + + - name: Run tests + run: vendor/bin/phpunit --testsuite=${{ inputs.test-suite }} --testdox --verbose diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 00000000..d8e8773b --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,11 @@ +name: Testing + +on: [push, pull_request] + +jobs: + unit: + name: Unit Testing + uses: ./.github/workflows/run-test-suite.yml + with: + fail-fast: false + test-suite: Unit diff --git a/phpunit.xml b/phpunit.xml index d92f77f0..b8fdac85 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,8 @@ - - tests + + tests/Unit diff --git a/tests/FiberTrait.php b/tests/Unit/FiberTrait.php similarity index 96% rename from tests/FiberTrait.php rename to tests/Unit/FiberTrait.php index fb80457c..c7bdf6c4 100644 --- a/tests/FiberTrait.php +++ b/tests/Unit/FiberTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Tests; +namespace Buggregator\Trap\Tests\Unit; trait FiberTrait { diff --git a/tests/Traffic/Dispatcher/HttpTest.php b/tests/Unit/Traffic/Dispatcher/HttpTest.php similarity index 93% rename from tests/Traffic/Dispatcher/HttpTest.php rename to tests/Unit/Traffic/Dispatcher/HttpTest.php index 37f7e03b..6e324c3b 100644 --- a/tests/Traffic/Dispatcher/HttpTest.php +++ b/tests/Unit/Traffic/Dispatcher/HttpTest.php @@ -1,6 +1,6 @@ parseStream($http); - $file = \file_get_contents(__DIR__ . '/../../Stub/sentry-body.bin'); + $file = \file_get_contents(__DIR__ . '/../../../Stub/sentry-body.bin'); self::assertSame($file, $request->getBody()->__toString()); } diff --git a/tests/Traffic/Parser/MultipartBodyParserTest.php b/tests/Unit/Traffic/Parser/MultipartBodyParserTest.php similarity index 94% rename from tests/Traffic/Parser/MultipartBodyParserTest.php rename to tests/Unit/Traffic/Parser/MultipartBodyParserTest.php index 0e804abc..3a16c0ae 100644 --- a/tests/Traffic/Parser/MultipartBodyParserTest.php +++ b/tests/Unit/Traffic/Parser/MultipartBodyParserTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Buggregator\Trap\Tests\Traffic\Parser; +namespace Buggregator\Trap\Tests\Unit\Traffic\Parser; -use Buggregator\Trap\Tests\FiberTrait; +use Buggregator\Trap\Tests\Unit\FiberTrait; use Buggregator\Trap\Traffic\Message\Multipart\Field; use Buggregator\Trap\Traffic\Message\Multipart\File; use Buggregator\Trap\Traffic\Message\Multipart\Part; @@ -50,8 +50,8 @@ public function testParse(): void public function testWithFileAttach(): void { - $file1 = \file_get_contents(__DIR__ . '/../../Stub/deburger.png'); - $file2 = \file_get_contents(__DIR__ . '/../../Stub/buggregator.png'); + $file1 = \file_get_contents(__DIR__ . '/../../../Stub/deburger.png'); + $file2 = \file_get_contents(__DIR__ . '/../../../Stub/buggregator.png'); $body = $this->makeStream(<<