name: backend tests
defaults:
  run:
    working-directory: projects/backend

on:
  workflow_call:
  push:
    branches-ignore:
      - main
    paths:
      - "projects/backend/**"
      - ".github/workflows/backend_*.yaml"
  pull_request:
    branches-ignore:
      - main
    paths:
      - "projects/backend/**"
      - ".github/workflows/backend_*.yaml"
jobs:
  functional:
    name: phpunit
    runs-on: ubuntu-latest
#    services:
#      mysql:
#        image: mariadb:10.11.11
#        env:
#          MYSQL_ALLOW_EMPTY_PASSWORD: false
#          MYSQL_ROOT_PASSWORD: root
#          MYSQL_DATABASE: root
#        ports:
#          - 3306/tcp
#        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    strategy:
      matrix:
        php: [8.4]
      fail-fast: false
    steps:
      -   name: Checkout
          uses: actions/checkout@v4

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

      -   name: Setup cache
          run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

      -   name: Cache dependencies installed with composer
          uses: actions/cache@v4
          with:
            path: ${{ env.COMPOSER_CACHE_DIR }}
            key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
            restore-keys: |
              php${{ matrix.php }}-composer-latest-
      -   name: Update composer
          run: composer self-update

      -   name: Install dependencies with composer
          run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

#      -   name: Setup mysql
#          run: sudo systemctl start mysql

      -   name: Run functional tests
          run: composer app:test
          env:
            APP_ENV: test
#            DATABASE_URL: mysql://root:root@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/app_test
