# Reusable workflow for PHPUnit testing # without Docker services and databases name: Reusable Serviceless PHPUnit Test on: workflow_call: inputs: job-name: description: Name of the job to appear in GitHub UI type: string required: true php-version: description: The PHP version the workflow should run type: string required: true job-id: description: Job ID to be used as part of cache key and artifact name type: string required: false group-name: description: The @group to test type: string required: false enable-artifact-upload: description: Whether artifact uploading of coverage results should be enabled type: boolean required: false enable-coverage: description: Whether coverage should be enabled type: boolean required: false enable-profiling: description: Whether slow tests should be profiled type: boolean required: false extra-extensions: description: Additional PHP extensions that are needed to be enabled type: string required: false extra-composer-options: description: Additional Composer options that should be appended to the `composer update` call type: string required: false extra-phpunit-options: description: Additional PHPUnit options that should be appended to the `vendor/bin/phpunit` call type: string required: false jobs: tests: name: ${{ inputs.job-name }} runs-on: ubuntu-22.04 steps: - name: Install latest ImageMagick if: ${{ contains(inputs.extra-extensions, 'imagick') }} run: | sudo apt-get update sudo apt-get install --reinstall libgs9-common fonts-noto-mono libgs9:amd64 libijs-0.35:amd64 fonts-urw-base35 ghostscript poppler-data libjbig2dec0:amd64 gsfonts libopenjp2-7:amd64 fonts-droid-fallback fonts-dejavu-core sudo apt-get install -y imagemagick sudo apt-get install --fix-broken - name: Checkout base branch for PR if: github.event_name == 'pull_request' uses: actions/checkout@v4 with: ref: ${{ github.base_ref }} - name: Checkout uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ inputs.php-version }} tools: composer extensions: gd, ${{ inputs.extra-extensions }} coverage: ${{ env.COVERAGE_DRIVER }} env: COVERAGE_DRIVER: ${{ inputs.enable-coverage && 'xdebug' || 'none' }} - name: Setup global environment variables run: | echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV echo "ARTIFACT_NAME=${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}" >> $GITHUB_ENV - name: Cache Composer dependencies uses: actions/cache@v4 with: path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}-${{ hashFiles('**/composer.*') }} restore-keys: | ${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}- ${{ inputs.job-id || github.job }}- - name: Cache PHPUnit's static analysis cache if: ${{ inputs.enable-artifact-upload }} uses: actions/cache@v4 with: path: build/.phpunit.cache/code-coverage key: phpunit-code-coverage-${{ hashFiles('**/phpunit.*') }} restore-keys: | phpunit-code-coverage- - name: Install dependencies run: | composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} composer update --ansi ${{ inputs.extra-composer-options }} - name: Compute additional PHPUnit options run: | echo "EXTRA_PHPUNIT_OPTIONS=${{ format('{0} {1} {2}', env.GROUP_OPTION, env.COVERAGE_OPTION, inputs.extra-phpunit-options) }}" >> $GITHUB_ENV env: COVERAGE_OPTION: ${{ inputs.enable-coverage && format('--coverage-php build/cov/coverage-{0}.cov', env.ARTIFACT_NAME) || '--no-coverage' }} GROUP_OPTION: ${{ inputs.group-name && format('--group {0}', inputs.group-name) || '' }} - name: Run tests run: script -e -c "vendor/bin/phpunit --color=always ${{ env.EXTRA_PHPUNIT_OPTIONS }}" env: TACHYCARDIA_MONITOR_GA: ${{ inputs.enable-profiling && 'enabled' || '' }} TERM: xterm-256color - name: Upload coverage results as artifact if: ${{ inputs.enable-artifact-upload }} uses: actions/upload-artifact@v4 with: name: ${{ env.ARTIFACT_NAME }} path: build/cov/coverage-${{ env.ARTIFACT_NAME }}.cov if-no-files-found: error retention-days: 1