name: PHPUnit with SQLite

on:
  workflow_call:
    inputs:
      os:
        required: true
        type: string
      php-version:
        required: true
        type: string
      extension:
        required: true
        type: string
      dependency-versions:
        required: true
        type: string

jobs:
  phpunit-sqlite:
    runs-on: ${{ inputs.os }}

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

      - name: Remove optional dependencies
        run: composer remove --no-update --dev doctrine/cache
        if: ${{ matrix.dependency-versions == 'minimal' }}

      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ inputs.php-version }}
          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+'
          dependency-versions: ${{ inputs.dependency-versions }}

      - name: Print SQLite version
        run: >
          php -r 'printf("Testing with SQLite version %s\n", (new PDO("sqlite::memory:"))->query("select sqlite_version()")->fetch()[0]);'
        if: ${{ inputs.extension == 'pdo_sqlite' }}

      - name: Print SQLite version
        run: >
          php -r 'printf("Testing with SQLite version %s\n", SQLite3::version()["versionString"]);'
        if: ${{ inputs.extension == 'sqlite3' }}

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

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