test: add phpunit harness with characterization tests - #10
Conversation
vitormattos
left a comment
There was a problem hiding this comment.
The test suite is going in a good direction.
I like the separation between Unit and Integration, the use of the real WordPress REST server in integration tests, and blocking unexpected external HTTP requests.
I left some comments before merging:
- one workflow file per tool;
- make Unit tests really independent from the WordPress bootstrap and database;
- declare only the WordPress versions we are really testing and supporting;
- when we find a known bug, add a regression test for the correct behavior and fix the bug instead of adding a green characterization test for the wrong behavior.
After these changes I think the test foundation will be much clearer and safer to extend.
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
b01079f to
29699fc
Compare
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
test: add a playwright suite for the account and subscription flows
refactor: move the plugin decisions into src
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
vitormattos
left a comment
There was a problem hiding this comment.
The previous review points are resolved and the CI is green.
I also reviewed the PHP version handling. There is still some duplicated compatibility configuration, but it is not causing a problem in the current PR, so I opened #15 as a follow-up to make composer.json the single source of truth for supported PHP versions.
This PR looks good to merge.
The plugin had no tests. This adds the PHPUnit harness and a characterization suite over the current behaviour, on top of the static analysis setup from #9 (hence the base branch; it retargets to
mainonce #9 is merged).Harness
composer testis all it takes.composer installpulls WordPress itself (roots/wordpress, installed intovendor/wordpress) and the core test suite (wp-phpunit), so the only external requirement is a MySQL/MariaDB server with a database the suite may wipe.tests/wp-tests-config.phpreads everything from the environment (WP_TESTS_DB_*,WP_CORE_DIR), defaulting to the local stack.tests/bootstrap.phpanswers any unexpected HTTP request with aWP_Error, and tests that exercise an outgoing call answer it throughtests/Support/FakeHttp.php, which uses WordPress' ownpre_http_requestfilter instead of a mock object.tests.ymlruns PHPUnit on PHP 8.1 and 8.3 against a MariaDB service, andcode-quality.ymlkeeps one job per check —lint,coding-standardsandstatic-analysis— so a failure names the tool that failed. TheciComposer script still chains all four locally.tests/as well, withphpstan/phpstan-phpunit— among other things it validates the@dataProviderreferences. TheignoreErrorsentry for the salts is gone, sincetests/wp-tests-config.phpdefines them.Tests
143 tests.
tests/mirrors the plugin file by file withTest.phpappended: a file goes toUnit/when it only feeds values to a function and reads the returned value, and toIntegration/when it goes through WordPress — options, hooks, the REST server or the database.Two current behaviours are locked in as they are, each with the reason in the test docblock:
update_option()sanitizes the value and, when the option does not exist yet, hands it toadd_option(), which sanitizes it again. The deploy token and the webhook secret are therefore encrypted twice on the first save and only work from the second one on.libresign_trigger_github_action_on_publish(),&&binds tighter than||, so publishing any post type dispatches a site deploy; the post type is only considered when published content leaves the publish status.WooCommerce is not installed in the suite, so what only exists with it loaded — the root account endpoints, the invoice title, the addresses redirect and the subscription change confirmation — is still uncovered.
Verification
composer ciis green: lint, PHPCS, PHPStan level 5 includingtests/, and 143 tests passing.