name: Unit Tests

on: [push, pull_request]

env:
  SYMFONY_DEPRECATIONS_HELPER: weak

jobs:
  unit-test:
    name: Unit ( PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} )
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        include:
          - php: 7.4
            symfony: 4.4.*
          - php: 7.4
            symfony: 5.4.*
          - php: 8.0
            symfony: 4.4.*
          - php: 8.0
            symfony: 5.4.*
          - php: 8.0
            symfony: 6.0.*
          - php: 8.1
            symfony: 4.4.*
          - php: 8.1
            symfony: 5.4.*
          - php: 8.1
            symfony: 6.0.*
          - php: 8.1
            symfony: 6.1.*
          - php: 8.2
            symfony: 6.2.*

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: intl, opcache, mysql, pdo_mysql, :xdebug

      - name: Get composer cache directory
        id: composercache
        run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: ${{ steps.composercache.outputs.dir }}
          key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json composer.lock') }}
          restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-

      - name: Install Symfony ${{ matrix.symfony }}
        run: composer config extra.symfony.require ${{ matrix.symfony }}

      - name: Install Symfony Flex
        run: |
          composer config --no-plugins allow-plugins.symfony/flex true
          composer require symfony/flex:"^1|^2" --no-update

      - name: Install dependencies
        run: composer update

      - name: Run unit tests
        run: bin/phpunit
