name: Unit Tests

on:
  push:
  pull_request:
  schedule:
  - cron: '0 0 * * *'

jobs:
  php-tests:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        php: [8.1, 8.2, 8.3, 8.4, 8.5]
        symfony: [^5.4, ^6.4, ^7.3, ^8.0]
        dependency-version: [prefer-lowest, prefer-stable]
        os: [ubuntu-latest]
        exclude:
          # Symfony 7+ requires PHP 8.2+; see https://symfony.com/releases/7.4
          - symfony: ^7.3
            php: 8.1
          # Symfony 8+ requires PHP 8.4+; see https://symfony.com/releases/8.0
          - symfony: ^8.0
            php: 8.1
          - symfony: ^8.0
            php: 8.2
          - symfony: ^8.0
            php: 8.3

    name: PHP${{ matrix.php }} Symfony${{ matrix.symfony }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

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

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php }}
        extensions: mbstring

    - name: Configure matchers
      uses: mheap/phpunit-matcher-action@v1

    - name: Install dependencies
      run: |
        composer require "symfony/http-foundation:${{ matrix.symfony }}" --no-interaction --no-update
        composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest --with-all-dependencies

    - name: Execute Unit Tests
      run: composer test

    - name: Analyse with PHPStan
      run: composer analyse
      if: matrix.os == 'ubuntu-latest' && matrix.symfony != '^4.4'

    - name: Check PSR-12 Codestyle
      run: composer test
      if: matrix.os == 'ubuntu-latest'
