Skip to content

Refactor library to PSR-4, add full unit-test coverage, and CI#6

Merged
Joel-James merged 7 commits into
mainfrom
dev
Jun 3, 2026
Merged

Refactor library to PSR-4, add full unit-test coverage, and CI#6
Joel-James merged 7 commits into
mainfrom
dev

Conversation

@Joel-James

Copy link
Copy Markdown
Member

Summary

Ships v2.0.0 of the library. The pre-refactor codebase had grown around a
static Api singleton and a kitchen-sink Service base class that mixed
HTTP, option storage, caching, and throttling. This PR splits those
responsibilities into focused collaborators, lays the file tree out as
PSR-4, and adds the test + CI infrastructure that has been missing.

Library refactor (v1 → v2)

  • PSR-4 layout under DuckDev\Freemius\…class-*.php filename
    prefixes are gone; each class lives in a file matching its name.
  • No more singletons. Api::get_instance() /
    Api::get_auth_instance() are replaced by an ApiFactory that hands
    out fresh clients per call. This fixes a latent credential-leak bug
    where two callers with different credentials could share state.
  • API layer split into Client (unsigned HTTP), SignedClient
    (auth headers), and RequestSigner (pure HMAC signing, no WP coupling).
  • Persistence and caching extracted out of the old Service base
    class into ActivationRepository (option-backed) and TransientCache
    (per-plugin scoped cache + throttle), both behind interfaces so they
    can be swapped in tests.
  • Activation data hardened into an immutable Activation value
    object with with() / with_scrubbed_license() mutators. Previously
    every service reached into the same loose string keys — a typo in any
    of them silently broke licensing.
  • Plugin, ApiKeys, SiteIdentity introduced as small focused
    collaborators. Hook registration moved out of constructors into
    boot() so wiring the container has no side effects.

Tests

  • 109 unit tests / 210 assertions covering every class under
    src/.
  • PHPUnit 9.6 + Brain\Monkey for WordPress function mocking; minimal
    WP_Error stub in tests/Stubs/.
  • Strict mode (failOnRisky, deprecations-as-exceptions).

CI / tooling

  • .github/workflows/tests.yml — PHPUnit matrix on PHP 7.4, 8.0,
    8.1, 8.2, 8.3.
  • .github/workflows/phpcs.yml — WPCS lint with PR annotations
    via cs2pr.
  • .github/workflows/release.yml — auto-generates a GitHub Release
    from commits when a v* tag is pushed; tags containing - (e.g.
    v2.0.0-beta1) are marked as pre-releases.
  • phpcs.xml.dist — WPCS ruleset with PSR-4 exemptions
    (WordPress.Files.FileName, ValidVariableName) and per-file
    exclusions for {@inheritDoc} interface methods and the HMAC
    base64_encode call.
  • composer.json — bumped to 2.0.0, PSR-4 autoload + autoload-dev,
    dev deps for PHPUnit/Brain\Monkey/WPCS/PHPCompatibility, scripts
    (composer test, composer phpcs).
  • README updated with the new namespace, factory wiring, and quickstart.

Breaking changes

This is a major version bump. Host plugins need to update their
integration:

  • Namespaces moved (DuckDev\Freemius\Services\Service
    DuckDev\Freemius\Services\AbstractService, etc.).
  • Freemius::get_instance() keeps the same call signature but the
    collaborator graph it composes is entirely new.
  • Direct callers of the old Api singletons must move to
    ApiFactory::make_public() / make_signed() /
    make_for_plugin() / make_for_install().
  • Activation arrays are now wrapped in the Activation value object;
    reach for ->install_id(), ->license_key(), etc. instead of
    array keys.

Test plan

  • composer test — 109/109 tests pass locally on PHP 8.x
  • composer phpcs — 0 errors, 0 warnings
  • CI matrix green across PHP 7.4–8.3
  • Smoke-test integration in a host plugin against the
    activate.json / deactivate.json / updates/latest.json
    endpoints
  • Tag v2.0.0 after merge and confirm the release workflow
    publishes notes

@Joel-James Joel-James merged commit 865955d into main Jun 3, 2026
12 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