name: Symfony

on:
    push:
        branches: ["master"]
    pull_request:
        branches: ["master"]

permissions:
    contents: read

jobs:
    symfony-tests:
        runs-on: ubuntu-latest

        steps:
            - uses: actions/checkout@v5.0.1
              with:
                  persist-credentials: false

            - name: Setup PHP
              uses: shivammathur/setup-php@2.37.0
              with:
                  php-version: "8.5"
                  extensions: ctype, iconv, pdo_sqlite
                  coverage: none
                  github-token: ${{ secrets.GITHUB_TOKEN }}

            - name: Copy test env
              run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"

            - name: Cache Composer
              uses: actions/cache@v5.0.1
              with:
                  path: vendor
                  key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
                  restore-keys: |
                      ${{ runner.os }}-php-

            - name: Install dependencies
              run: composer install --no-interaction --no-progress --prefer-dist

            - name: Prepare test database
              env:
                  APP_ENV: test
                  DATABASE_URL: sqlite:///%kernel.project_dir%/var/test.db
              run: |
                  rm -f var/test.db
                  php bin/console doctrine:migrations:migrate --no-interaction --env=test

            - name: Run PHPUnit
              env:
                  APP_ENV: test
              run: php bin/phpunit --testdox
