|
| 1 | +name: PHPUnit Test Runner |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + php-version: |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: '8.1' |
| 10 | + description: 'PHP version to test against' |
| 11 | + |
| 12 | +jobs: |
| 13 | + phpunit-test: |
| 14 | + name: PHPUnit tests (PHP ${{ inputs.php-version }}) |
| 15 | + runs-on: ubuntu-22.04 |
| 16 | + |
| 17 | + services: |
| 18 | + mysql: |
| 19 | + image: mysql:8.0 |
| 20 | + env: |
| 21 | + MYSQL_ROOT_PASSWORD: root |
| 22 | + MYSQL_DATABASE: wordpress_test |
| 23 | + ports: |
| 24 | + - 3306:3306 |
| 25 | + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout source code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set up PHP |
| 32 | + uses: shivammathur/setup-php@v2 |
| 33 | + with: |
| 34 | + php-version: ${{ inputs.php-version }} |
| 35 | + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql |
| 36 | + coverage: none |
| 37 | + |
| 38 | + - name: Compute dependency hash |
| 39 | + id: deps-hash |
| 40 | + run: | |
| 41 | + set -euo pipefail |
| 42 | + tmpfile=$(mktemp) |
| 43 | + if [ -f "src/composer.lock" ]; then |
| 44 | + cat "src/composer.lock" >> "$tmpfile" |
| 45 | + fi |
| 46 | + if [ -s "$tmpfile" ]; then |
| 47 | + deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8) |
| 48 | + else |
| 49 | + deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8) |
| 50 | + fi |
| 51 | + echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT" |
| 52 | +
|
| 53 | + - name: Get Composer cache |
| 54 | + id: composer-cache |
| 55 | + uses: actions/cache/restore@v4 |
| 56 | + with: |
| 57 | + path: src/vendor |
| 58 | + key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }} |
| 59 | + restore-keys: | |
| 60 | + ${{ runner.os }}-php-${{ inputs.php-version }}-composer- |
| 61 | +
|
| 62 | + - name: Install Composer dependencies |
| 63 | + if: steps.composer-cache.outputs.cache-hit != 'true' |
| 64 | + run: | |
| 65 | + cd src |
| 66 | + composer install --no-progress --prefer-dist --optimize-autoloader |
| 67 | +
|
| 68 | + - name: Save Composer cache |
| 69 | + if: steps.composer-cache.outputs.cache-hit != 'true' |
| 70 | + uses: actions/cache/save@v4 |
| 71 | + with: |
| 72 | + path: src/vendor |
| 73 | + key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }} |
| 74 | + |
| 75 | + - name: Install WordPress test suite |
| 76 | + run: | |
| 77 | + bash tests/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 latest true |
| 78 | +
|
| 79 | + - name: Run PHPUnit tests |
| 80 | + run: | |
| 81 | + cd src |
| 82 | + vendor/bin/phpunit -c ../phpunit.xml --testdox |
| 83 | +
|
| 84 | + - uses: actions/upload-artifact@v4 |
| 85 | + if: always() |
| 86 | + with: |
| 87 | + name: phpunit-test-results-php-${{ inputs.php-version }} |
| 88 | + path: | |
| 89 | + .phpunit.result.cache |
| 90 | + if-no-files-found: ignore |
| 91 | + retention-days: 2 |
| 92 | + |
0 commit comments