name: PHPUnit with Oracle

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

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

    services:
      oracle:
        image: gvenzl/oracle-${{ inputs.oracle-version < 23 && 'xe' || 'free' }}:${{ inputs.oracle-version }}
        ports:
          - '1521:1521'
        env:
          ORACLE_PASSWORD: oracle
        options: >-
          --health-cmd healthcheck.sh
          --health-interval 20s
          --health-timeout 10s
          --health-retries 10

    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.oracle-version < 23 && '-21' || '' }}.xml --coverage-clover=coverage.xml

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