name: Unit

on:
  push:
  pull_request:

permissions:
  contents: read

jobs:
  tests_linux:
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"

    strategy:
      fail-fast: false
      matrix:
        php: ["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]

    name: Linux / PHP ${{ matrix.php }}

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: dom, curl, fileinfo, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, ldap, intl, pspell, enchant
          tools: composer:v2
          coverage: none

      - name: Setup problem matchers
        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Install Aspell/Hunspell
        run: sudo apt-get -y install aspell aspell-en aspell-de hunspell-en-us

      - name: Fix for PHP 8.4
        run: composer config platform.php 8.1
        if: matrix.php >= 8.4

      - name: Execute tests
        run: .ci/run_tests.sh

      - name: Upload artifacts
        uses: actions/upload-artifact@master
        if: failure()
        with:
          name: Logs
          path: logs/errors.log

  tests_windows:
    runs-on: windows-latest
    if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"

    strategy:
      fail-fast: false
      matrix:
        php: ["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]

    name: Windows / PHP ${{ matrix.php }}

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: dom, curl, fileinfo, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, ldap, intl
          tools: composer:v2
          coverage: none

      - name: Execute tests
        run: bash -ex .ci/run_tests.sh

      - name: Upload artifacts
        uses: actions/upload-artifact@master
        if: failure()
        with:
          name: Logs
          path: logs/errors.log
