name: PHPUnit with MariaDB

on:
  workflow_call:
    inputs:
      php-version:
        required: true
        type: string
      mariadb-version:
        required: true
        type: string
      extension:
        required: true
        type: string

jobs:
  phpunit-mariadb:
    runs-on: ubuntu-24.04

    services:
      mariadb:
        image: mariadb:${{ inputs.mariadb-version }}
        ports:
          - '3306:3306'
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
          MYSQL_DATABASE: doctrine_tests
        options: >-
          --health-cmd "healthcheck.sh --connect --innodb_initialized || mysqladmin ping --protocol tcp --silent"

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

      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ inputs.php-version }}
          extensions: ${{ inputs.extension }}
          coverage: pcov
          ini-values: zend.assertions=1
        env:
          fail-fast: true

      - name: Install dependencies with Composer
        uses: ramsey/composer-install@v3
        with:
          composer-options: '--ignore-platform-req=php+'

      - name: Run PHPUnit
        run: vendor/bin/phpunit -c ci/github/phpunit/${{ inputs.extension }}${{ inputs.config-file-suffix }}.xml --coverage-clover=coverage.xml

      - name: Upload coverage file
        uses: actions/upload-artifact@v4
        with:
          name: ${{ github.job }}-${{ inputs.mariadb-version }}-php-${{ inputs.php-version }}-${{ inputs.extension }}.coverage
          path: coverage.xml
