-
Notifications
You must be signed in to change notification settings - Fork 108
internal: add phpunit tests #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bb7102d
setup for phpunit tests
louiswol94 770d9a7
fix php setup
louiswol94 03c67f5
add unit test for rest api
louiswol94 78d6861
simplify tests bootstrap
louiswol94 699d42a
simplify WP version detection in install script
louiswol94 82b5d7d
add php 8.4 to phpunit
louiswol94 72b25e8
Update .github/workflows/phpunit-test.yml
louiswol94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| name: PHPUnit Test Runner | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| php-version: | ||
| required: false | ||
| type: string | ||
| default: '8.2' | ||
| description: 'PHP version to test against' | ||
|
|
||
| jobs: | ||
| phpunit-test: | ||
| name: PHPUnit tests (PHP ${{ inputs.php-version }}) | ||
| runs-on: ubuntu-22.04 | ||
|
|
||
| services: | ||
| mysql: | ||
| image: mysql:8.0 | ||
| env: | ||
| MYSQL_ROOT_PASSWORD: root | ||
| MYSQL_DATABASE: wordpress_test | ||
| ports: | ||
| - 3306:3306 | ||
| options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
|
|
||
| steps: | ||
| - name: Checkout source code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up PHP | ||
| uses: codesnippetspro/setup-php@v2 | ||
| with: | ||
| php-version: ${{ inputs.php-version }} | ||
|
|
||
| - name: Compute dependency hash | ||
| id: deps-hash | ||
| run: | | ||
| set -euo pipefail | ||
| tmpfile=$(mktemp) | ||
| if [ -f "src/composer.lock" ]; then | ||
| cat "src/composer.lock" >> "$tmpfile" | ||
| fi | ||
| if [ -s "$tmpfile" ]; then | ||
| deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8) | ||
| else | ||
| deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8) | ||
| fi | ||
| echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Get Composer cache | ||
| id: composer-cache | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: src/vendor | ||
| key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-php-${{ inputs.php-version }}-composer- | ||
|
|
||
| - name: Install Composer dependencies | ||
| if: steps.composer-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| cd src | ||
| composer install --no-progress --prefer-dist --optimize-autoloader | ||
|
|
||
| - name: Save Composer cache | ||
| if: steps.composer-cache.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@v4 | ||
| with: | ||
| path: src/vendor | ||
| key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }} | ||
|
|
||
| - name: Install WordPress test suite | ||
| run: | | ||
| bash tests/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 latest true | ||
|
|
||
| - name: Run PHPUnit tests | ||
| run: | | ||
| cd src | ||
| vendor/bin/phpunit -c ../phpunit.xml --testdox | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: phpunit-test-results-php-${{ inputs.php-version }} | ||
| path: | | ||
| .phpunit.result.cache | ||
| if-no-files-found: ignore | ||
| retention-days: 2 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| name: "(Test): PHPUnit" | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [labeled, synchronize, opened, reopened] | ||
| push: | ||
| branches: | ||
| - 'core' | ||
| - 'pro' | ||
| paths-ignore: | ||
| - '**.md' | ||
| - '**.txt' | ||
| - '.gitignore' | ||
| - 'docs/**' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| actions: read | ||
|
|
||
| concurrency: | ||
| group: phpunit-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| jobs: | ||
| phpunit-php-7-4: | ||
| if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | ||
| uses: ./.github/workflows/phpunit-test.yml | ||
| with: | ||
| php-version: '7.4' | ||
|
|
||
| phpunit-php-8-0: | ||
| if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | ||
| uses: ./.github/workflows/phpunit-test.yml | ||
| with: | ||
| php-version: '8.0' | ||
|
|
||
| phpunit-php-8-1: | ||
| if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | ||
| uses: ./.github/workflows/phpunit-test.yml | ||
| with: | ||
| php-version: '8.1' | ||
|
|
||
| phpunit-php-8-2: | ||
| if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | ||
| uses: ./.github/workflows/phpunit-test.yml | ||
| with: | ||
| php-version: '8.2' | ||
|
|
||
| phpunit-php-8-3: | ||
| if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | ||
| uses: ./.github/workflows/phpunit-test.yml | ||
| with: | ||
| php-version: '8.3' | ||
|
|
||
| phpunit-php-8-4: | ||
| if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | ||
| uses: ./.github/workflows/phpunit-test.yml | ||
| with: | ||
| php-version: '8.4' | ||
|
|
||
| test-result: | ||
| needs: [phpunit-php-7-4, phpunit-php-8-0, phpunit-php-8-1, phpunit-php-8-2, phpunit-php-8-3, phpunit-php-8-4] | ||
| if: always() && (needs.phpunit-php-7-4.result != 'skipped' || needs.phpunit-php-8-0.result != 'skipped' || needs.phpunit-php-8-1.result != 'skipped' || needs.phpunit-php-8-2.result != 'skipped' || needs.phpunit-php-8-3.result != 'skipped' || needs.phpunit-php-8-4.result != 'skipped') | ||
| runs-on: ubuntu-22.04 | ||
| name: PHPUnit - Test Results Summary | ||
| steps: | ||
| - name: Test status summary | ||
| run: | | ||
| echo "PHP 7.4: ${{ needs.phpunit-php-7-4.result }}" | ||
| echo "PHP 8.0: ${{ needs.phpunit-php-8-0.result }}" | ||
| echo "PHP 8.1: ${{ needs.phpunit-php-8-1.result }}" | ||
| echo "PHP 8.2: ${{ needs.phpunit-php-8-2.result }}" | ||
| echo "PHP 8.3: ${{ needs.phpunit-php-8-3.result }}" | ||
| echo "PHP 8.4: ${{ needs.phpunit-php-8-4.result }}" | ||
|
|
||
| - name: Check overall status | ||
| if: | | ||
| (needs.phpunit-php-7-4.result != 'success' && needs.phpunit-php-7-4.result != 'skipped') || | ||
| (needs.phpunit-php-8-0.result != 'success' && needs.phpunit-php-8-0.result != 'skipped') || | ||
| (needs.phpunit-php-8-1.result != 'success' && needs.phpunit-php-8-1.result != 'skipped') || | ||
| (needs.phpunit-php-8-2.result != 'success' && needs.phpunit-php-8-2.result != 'skipped') || | ||
| (needs.phpunit-php-8-3.result != 'success' && needs.phpunit-php-8-3.result != 'skipped') || | ||
| (needs.phpunit-php-8-4.result != 'success' && needs.phpunit-php-8-4.result != 'skipped') | ||
| run: exit 1 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.