name: Unit Tests

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

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

    strategy:
      matrix:
        php: [7.4, 8.0, 8.1]
        symfony: [^4.4, ^5.4, ^6]
        dependency-version: [prefer-lowest, prefer-stable]
        os: [ubuntu-latest]
        exclude:
          - symfony: ^6
            php: 7.4

    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'