Skip to content

fix(templates): make Services.php + its reset() wiring accessor-conditional (#16, #17) - #14

Merged
akshat009 merged 1 commit into
mainfrom
fix/services-accessor-conditional
Aug 30, 2026
Merged

fix(templates): make Services.php + its reset() wiring accessor-conditional (#16, #17)#14
akshat009 merged 1 commit into
mainfrom
fix/services-accessor-conditional

Conversation

@akshat009

Copy link
Copy Markdown
Owner

Closes re-audit #3's #16 and #17.

What changed

  • fix(templates): nest the REST endpoint so 'schema' survives register_rest_route()'s upgrade step (C) #16src/Services.php now ships only when at least one selected module registers a Services accessor. A zero-accessor build (e.g. --modules shortcode) no longer carries a dead class with nothing but set()/reset() over a permanently empty array.
  • Wired via a new has_services flag in templateFlags (index.js), consumed by templates/tests/Unit/Plugin_TestCase.php through the existing {{#if flag}} template engine — its use Services; import and Services::reset() call in tearDown() are now gated the same way.
  • test(templates): uniform init_hooks() contract test across all 22 module classes (D) #17 — the generated Services_Test accessor test (built in addService()) now also asserts the default construction path (assertInstanceOf on a bare Services::x() call, before any set()), in addition to the memoisation, set()-override, and reset()-clears-the-override paths already covered.

Test suite

Updated tests/generator.test.js to match:

Verification

  • npm test: 69/69 pass.
  • Two ad hoc scaffolds (--modules "" and --modules caching) generated directly via the CLI and inspected — output matches the design; php -l clean on every generated file in both.

🤖 Generated with Claude Code

…tional (#16, #17)

- Services.php now ships only when at least one module registers a
  Services accessor. A zero-accessor build (e.g. --modules shortcode)
  no longer carries a dead class with nothing but set()/reset() over a
  permanently empty array.
- Plugin_TestCase's `use Services;` import and `Services::reset()` call
  in tearDown() are gated on the same has_services flag, via the
  existing {{#if flag}} template engine.
- Services_Test's generated accessor test now covers the default
  construction path (assertInstanceOf on a bare call, before any
  set()) in addition to the memoisation, set()-override, and
  reset()-clears-the-override paths already covered.
- Update the CLI's own test suite to match: the "foundational classes"
  test no longer expects src/Services.php in a zero-module scaffold,
  and the test-isolation test (#14, #15) asserts the has_services
  split and the rewritten Services_Test body.

Closes re-audit #3 items #16 and #17.
@akshat009
akshat009 merged commit baa90c9 into main Aug 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant