name: Coverage

on:
  push:
    branches: [ '**' ]
  pull_request:
    branches: [ '**' ]

jobs:
  ubuntu:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        php: ['8.2']

    name: Coverage

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: curl, imagick, json, mbstring, pcntl, pdo, pdo_sqlite, sqlite, zip
          tools: composer:v2
          coverage: xdebug

      - name: Get Composer Cache Directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

      - name: Set PHPUnit version
        if: matrix.php >= 8.1
        run: composer require --no-update phpunit/phpunit:^9.5.20 --no-interaction --dev

      - name: Install Composer Dependencies
        run: composer update --prefer-dist --no-progress --prefer-stable

      - name: PHPUnit
        run: ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
