Test isolation: shared base, Commands_Test isolation, real Services_Test (#14, #15) - #13
Merged
Merged
Conversation
…l Services_Test (#14, #15) #14 — static state was leaking between tests. New `tests/Unit/Plugin_TestCase` (abstract, always shipped) resets `Services` and the `Plugin` singleton in tearDown(); every generated `*_Test.php` now extends it instead of PHPUnit's TestCase. `Commands_Test` gets `@runInSeparateProcess` / `@preserveGlobalState disabled` so its `define( 'WP_CLI', true )` can't persist into the rest of the run — `Schema_Test`'s front-end-gate test no longer has to `markTestSkipped`, so the #13 fix is verified again. #15 — `Services_Test` was a tautology + reflection into a private array, because `set( object )` couldn't feed a `\stdClass` back through a typed accessor. Now generated per-accessor from `addService()`: `createMock()` of the real class (satisfies the return type), `Services::set()`, then assert the accessor hands back that instance and the same instance twice, and that `reset()` clears it — all through the public API. `Services_Test` only ships when there's >= 1 accessor. Verified: 68 generator + 13 engine tests; full + minimal scaffolds php -l clean, every unit test extends Plugin_TestCase, Services_Test present only with an accessor.
…repare-dist (#11, #12 revised) Re-audit #2 retracted "drop the */templates/* exclude" — the WC email/My-Account overrides genuinely fail three sniffs (PrefixAllGlobals on core WC hook names + loosely-named locals; EscapeOutput on plain-text bodies that use wp_strip_all_tags). But the blanket path exclude also silenced EscapeOutput on the HTML email template, where escaping does matter. Now: when a woo:email / woo:my-account module ships a templates/ dir, phpcs.xml adds `<file>./templates</file>` and excludes only: - WordPress.NamingConventions.PrefixAllGlobals for */templates/* - WordPress.Security.EscapeOutput for */templates/emails/plain/* only Everything else in templates/ (docblocks, spacing, i18n, the HTML email's escaping) is linted. Gated on a new has_wc_template_overrides flag; a scaffold without those modules has no templates/ reference at all. Also: `composer prepare-dist` = `composer install --no-dev --optimize-autoloader`, so `npm run plugin-zip` doesn't depend on the user reading the release docs.
…ooks() so the CLI test needs no define() (#14)
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.
Re-audit #2 follow-ups.
#14 — static state was leaking between tests
tests/Unit/Plugin_TestCase(abstract, ships in every scaffold):tearDown()callsServices::reset()+Plugin::set_instance( null ). Every generated*_Test.phpnowextends Plugin_TestCaseinstead of PHPUnit'sTestCase.Commands_Testgets@runInSeparateProcess/@preserveGlobalState disabled— itsdefine( 'WP_CLI', true )can no longer persist into later tests.Schema_Test's front-end-gate test drops itsmarkTestSkippedguard, so the Test isolation: shared base, Commands_Test isolation, real Services_Test (#14, #15) #13 fix is verified on every run again.#15 — Services_Test didn't test the contract
Was
assertTrue($ref->isStatic())+ReflectionPropertyinto a private array (becauseset( object )couldn't feed a\stdClassthrough a typed accessor). Now generated per-accessor fromaddService():Services_Testships only when there's >= 1 accessor.#11 / #12 revised (from the audit's own retractions)
*/templates/*exclude is justified (the audit retracted "drop it"), but it over-suppressedEscapeOutputon the HTML email template. Now, when awoo:email/woo:my-accountmodule shipstemplates/, phpcs.xml adds<file>./templates</file>and excludes onlyPrefixAllGlobalsfor*/templates/*andEscapeOutputfor*/templates/emails/plain/*. Gated onhas_wc_template_overrides.composer prepare-dist=composer install --no-dev --optimize-autoloader, soplugin-zipdoesn't depend on reading the release docs.Not in this PR
init_hooks()contract test across 22 modules) — bigger, separate.Verified: 69 generator + 13 engine tests; full/minimal scaffolds
php -lclean, valid phpcs.xml both ways, every unit test extendsPlugin_TestCase.