diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..a0a8186 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,83 @@ +name: Test + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + + tests: + name: Unit Tests on PHP ${{ matrix.php-versions }} with ${{ matrix.deps }} dependencies + + strategy: + matrix: + php-versions: + - '8.1' + - '8.2' + - '8.3' + deps: + - 'highest' + - 'lowest' + + env: + extensions: pdo_mysql + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Setup cache Environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ext-cache-v1 + + - name: Cache extensions + uses: actions/cache@v4 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + coverage: pcov + env: + fail-fast: true + + - 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 }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-${{ matrix.deps }}-composer- + + - name: Install dependencies + run: | + if [[ "${{ matrix.deps }}" == "lowest" ]]; then + composer update --prefer-lowest --no-progress --no-suggest --ansi --prefer-dist + else + composer update --prefer-stable --no-progress --no-suggest --ansi --prefer-dist + fi + + - name: Run PHPUnit + run: composer test + + - name: Run PHPStan + run: composer lint