Repository navigation
fix(testing): register themes and plugins in every application of a test process - #752
Merged
Merged
Conversation
…est process WordPress includes functions.php and plugin main files once per process, while a test process builds one application per test: only the first one was asked to register the theme and the plugins. The calls of pollora_register() made while WordPress loads are now repeated for each later application, what they hooked into the actions of the load runs again, and the callbacks they replace are unhooked. Under unit tests only. The files of app/inc are now included once per process: a second registration declared their functions again. Fixes #749
added 4 commits
December 3, 2026 22:45
The latest Rector refuses to run on a skip naming a rule that does not exist. Rector 2.8 only warned that both were deprecated and never registered.
Rector 2.9.2 removes them, among them methods the code under test calls or reflects.
A mutant runs only the tests that cover its line: the files that describe a process across ordered tests assert in another test than the one that records.
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.
Fixes #749.
Cause
WordPress includes
functions.phpand plugin main files once per PHP process; a test process builds one application per test. Measured on a throwaway skeleton (composer create-project, SQLite, PHP 8.5) with 13.45.1:functions.phpincludedprobenullview()->exists('index')config('theme.menus')probe-pluginFix
pollora_register()calls made while a test process loads WordPress are remembered (Pollora\Testing\ModuleRegistrations,@internal).require_once wp-settings.phpthat includes nothing, in the recorded order.plugins_loaded,setup_theme,after_setup_theme,widgets_init,initandwp_loadedis run, and only that;did_action()counts are not increased.IsolatesWordPressHooks.app/incfiles are now included once per process. Repeating a registration included them again, which is fatal when one declares a function (reproduced).Production and boot performance
runningUnitTests():Bootstrapis unchanged and drives it throughWordPressLoadRecorder, which it already only calls there.pollora_register()call, one small class autoloaded (once) and one static boolean check.src/Testingis part of the distribution archive.include_onceinapp/inc: no difference for a module registered once. A file already included by other means is now skipped instead of included again.Verified
On the same throwaway project, three consecutive applications, with and without the trait: theme views, configuration (menus, supports, images, sidebars, templates), theme provider, asset container,
app/inc, nav menus, a plugin registered withpollora_register()(config, views, provider, route). With the trait, the callback counts ofafter_setup_themeandnav_menu_link_attributesand the output of a theme#[Filter]stay the same.A child theme (child and parent both calling
pollora_register): child view, parent view and child config present in the second application; on 13.45.1 they are missing.nwidartmodules are discovered byModuleServiceProviderin each application, on 13.45.1 too: a module#[Filter]runs in all three.GET /answers 200 with the theme template in all three applications (on 13.45.1, 200 in applications 2 and 3 as well, but without the theme: a 2.6 kB page against 7.7 kB). This needs shims in the test, see below.Framework tests: 4 of the 6 two-application replay tests fail without the change (four more self-contained tests cover the recording for the mutation gate); without
include_oncethe newModuleAssetManagertest kills the run with "Cannot redeclare".composer qa:fastpasses.composer qa(PHP 8.5, 2G): the two known PHP 8.5 failures only (finfo_close()in PHPStan,Extraction\PublicSurfaceTest); 4161 tests passed otherwise. The public surface gate passes,api-surface.jsonuntouched.Not fixed here: rendering
/from a skeleton testIndependently of this issue, a feature test of a fresh skeleton cannot render
/as a visitor gets it, even in the first application: in consoleWP_USE_THEMESis false (404),SERVER_NAMEis undefined inwp_head(500), and once themes are forced on, the raw-template guard redirects and callsexitunlessSCRIPT_FILENAMEispublic/index.php. The check above set all three from the test.Limits
pollora_register()is repeated. Other code offunctions.php, of a plugin file or ofapp/inc, and a direct call to a registrar, still run once per process.add_theme_support('title-tag')afterwp_loaded: WordPress reports it throughdoing_it_wrong_run; Pollora's logging provider, booted before WordPress, keeps it from raising an error.Documentation (draft, merge at release): Pollora/documentation#150. Rendering a URL from a test is already documented in
testing.md("Why the test loads WordPress itself").Rector 2.9.2 (separate commits, unrelated to #749)
Rector 2.9.2 reached CI during this pull request (
composer.lockis not committed) and failedCode Qualityon files already ondevelop: it refuses to run on the two skips naming rules it no longer ships, and itsRemoveEmptyClassMethodRectorwould delete empty methods of test doubles, some of which are called or reflected.rector.phpdrops the two skips and skips that rule undertests/. Locally only Rector 2.8.5 could be run; 2.9.2 is checked by CI. Split these commits out if you would rather have them apart.