Add PHPUnit integration tests and CI - #17
Merged
Merged
Conversation
Covers the button only rendering when more pages exist, the next page for a valid token, rejection of malformed tokens and pages, the expired feed response, and remote failures returned as escaped errors that are not cached.
Pull request branches were building twice, once for the push and once for the pull request.
With random ordering, admin_init could run WordPress update checks and make a real HTTP request when another test class ran first.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a PHPUnit integration suite that runs the plugin inside the real WordPress test framework, plus a GitHub Actions workflow. No runtime code changes.
What is tested
64 tests. HTTP is faked with
pre_http_request, so no test reaches a remote feed.x-wp-totalpagesis above 1, with its stored token context.wp_ajax_nopriv_andwp_ajax_hooks with WordPress's AJAX die handler. Covers the next page for a valid token, page caching,has_moreon the last page, malformed tokens and pages rejected before any HTTP request, unknown tokens reported as expired, a page past the last one returned as an error, and remote failures returned as escaped errors that are not cached. The handler has no nonce by design (page-cached HTML would carry an expired nonce), so the test checks that it works for logged-out visitors without one.Mutation results
The original review broke the code by hand and confirmed the suite fails for each of these:
wp_safe_remote_get()swapped forwp_remote_get()The same check for the new Load More tests, one break at a time, restored afterwards:
x-wp-totalpages> 1wp_send_json_success()Before these tests, all three breaks passed the suite.
Running locally
See CONTRIBUTING.md. In short:
Use a disposable database. The test framework creates and drops tables in it.
CI
PHP 7.4 with WordPress 6.8, and PHP 8.3 and 8.4 with the latest WordPress, each against its own MySQL service. Composer downloads are cached, keyed on
composer.lock. Push builds run onmainonly, so PR branches build once.Known gaps
excerpt_length="invalid"resolves to 0 (no limit) andcount="-3"becomes 3. The tests lock in current behavior; this PR does not change it.