name: Unit testing on: workflow_call: inputs: php: type: string required: true coverage: type: boolean required: false default: false os: type: string required: false default: 'ubuntu-22.04' permissions: contents: read jobs: unit: name: Unit | PHP ${{ inputs.php }}${{ inputs.coverage && ' (with coverage)' || '' }}${{ startsWith( inputs.os, 'windows' ) && ' (Windows)' || '' }}${{ startsWith( inputs.os, 'macos' ) && ' (macOS)' || '' }} runs-on: ${{ inputs.os || 'ubuntu-22.04' }} continue-on-error: ${{ inputs.php == 'nightly' }} steps: - name: Check out source code uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: persist-credentials: false - name: Set up PHP environment uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2 with: php-version: '${{ inputs.php }}' ini-values: zend.assertions=1, error_reporting=-1, display_errors=On extensions: zip, fileinfo coverage: ${{ inputs.coverage && 'xdebug' || 'none' }} tools: composer,cs2pr env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Install Composer dependencies & cache dependencies uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # 4.0.0 env: COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} # PHPUnit 10+ may fail a test run when the "old" configuration format is used. # Luckily, there is a built-in migration tool since PHPUnit 9.3. - name: Migrate PHPUnit configuration for PHPUnit 10+ if: ${{ inputs.php >= 8.2 || inputs.php == 'nightly' }} continue-on-error: true run: composer phpunit -- --migrate-configuration - name: Setup problem matcher to provide annotations for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPUnit with coverage if: ${{ inputs.coverage }} run: | composer phpunit -- --coverage-clover build/logs/unit-coverage.xml - name: Run PHPUnit if: ${{ ! inputs.coverage }} # For example TestBehatTags.php in wp-cli-tests depends on the db type. env: WP_CLI_TEST_DBTYPE: 'sqlite' run: | composer phpunit - name: Upload code coverage report if: ${{ inputs.coverage }} uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 with: directory: build/logs flags: unit token: ${{ secrets.CODECOV_TOKEN }}