Skip to content

Commit

Permalink
Add phpunit in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Nov 18, 2023
1 parent 26d806a commit 9d8eb9a
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 22 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/run-test-suite.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false" colors="true"
backupGlobals="false"
colors="true"
processIsolation="false"
executionOrder="random"
stopOnFailure="false"
Expand All @@ -10,8 +11,8 @@
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Tests">
<directory>tests</directory>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source>
Expand Down
2 changes: 1 addition & 1 deletion tests/FiberTrait.php → tests/Unit/FiberTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Tests;
namespace Buggregator\Trap\Tests\Unit;

trait FiberTrait
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buggregator\Trap\Tests\Traffic\Dispatcher;
namespace Buggregator\Trap\Tests\Unit\Traffic\Dispatcher;

use Buggregator\Trap\Traffic\Dispatcher\Http;
use DateTimeImmutable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Buggregator\Trap\Tests\Traffic\Emitter;
namespace Buggregator\Trap\Tests\Unit\Traffic\Emitter;

use Buggregator\Trap\Handler\Http\Emitter;
use Buggregator\Trap\Test\Mock\StreamClientMock;
use Buggregator\Trap\Tests\FiberTrait;
use Buggregator\Trap\Tests\Unit\FiberTrait;
use Nyholm\Psr7\Response;
use PHPUnit\Framework\TestCase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Tests\Traffic\Message\Multipart;
namespace Buggregator\Trap\Tests\Unit\Traffic\Message\Multipart;

use Buggregator\Trap\Traffic\Message\Multipart\Field;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Tests\Traffic\Message\Multipart;
namespace Buggregator\Trap\Tests\Unit\Traffic\Message\Multipart;

use Buggregator\Trap\Support\StreamHelper;
use Buggregator\Trap\Traffic\Message\Multipart\File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace Buggregator\Trap\Tests\Traffic\Parser;
namespace Buggregator\Trap\Tests\Unit\Traffic\Parser;

use Buggregator\Trap\Test\Mock\StreamClientMock;
use Buggregator\Trap\Tests\FiberTrait;
use Buggregator\Trap\Tests\Unit\FiberTrait;
use Buggregator\Trap\Traffic\Parser;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -88,8 +88,8 @@ public function testPostUrlEncoded(): void

public function testPostMultipartFormData(): 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 = <<<BODY
--Asrf456BGe4h\r
Content-Disposition: form-data; name="Authors"\r
Expand Down Expand Up @@ -152,11 +152,11 @@ public function testPostMultipartFormData(): void

public function testGzippedBody(): void
{
$http = \file_get_contents(__DIR__ . '/../../Stub/sentry.bin');
$http = \file_get_contents(__DIR__ . '/../../../Stub/sentry.bin');

$request = $this->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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(<<<BODY
--Asrf456BGe4h\r
Content-Disposition: form-data; name="Authors"\r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace Buggregator\Trap\Tests\Traffic\Parser;
namespace Buggregator\Trap\Tests\Unit\Traffic\Parser;

use Buggregator\Trap\Test\Mock\StreamClientMock;
use Buggregator\Trap\Tests\FiberTrait;
use Buggregator\Trap\Tests\Unit\FiberTrait;
use Buggregator\Trap\Traffic\Message;
use Buggregator\Trap\Traffic\Parser;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Tests\Traffic\Proto\Server\Version;
namespace Buggregator\Trap\Tests\Unit\Traffic\Proto\Server\Version;

use Buggregator\Trap\Proto\Server\Version\V1;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down

0 comments on commit 9d8eb9a

Please sign in to comment.