Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpunit Globals Laravel Package

zalas/phpunit-globals

A lightweight PHPUnit extension that backs up and restores PHP globals between tests so leaked global state can't break your suite. Register the listener, add the trait, and annotate which globals to preserve for clean, predictable test runs.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Test reliability and isolation investment: The package enables per-test declaration of $GLOBALS/superglobals via PHP attributes, so tests depending on global state (legacy bootstrap files, framework constants, $_SERVER/$_ENV) state their environment explicitly rather than inheriting mutations from a shared setUp(). This supports a decision to reduce order-dependent, flaky test suites instead of tolerating them.
  • Test-convention standardization: If the team is standardizing on PHP 8 attributes for test metadata (#[DataProvider], #[TestWith]), this keeps global-state setup in the same declarative style — a codebase-wide convention decision, not just a one-off tool.
  • Build-vs-adopt (dependency policy): This is still essentially a one-file utility. The real PM decision is whether a third-party dependency is warranted for something a team can write in an afternoon — feeding a concrete threshold rule for accepting small, single-maintainer, test-only libraries. v4.2.0 gives us one more data point for that rule: the maintainer is still shipping.
  • Upgrade-path input: For PHP 7→8.1+ and PHPUnit 9→10/11/12/13 modernization, this can serve as an intermediate step that removes hand-rolled global mutation without a full test-suite rewrite. v4.2.0 (PHPUnit 13.0 compatibility) extends the usable horizon of that decision — the package now spans roughly four major PHPUnit generations.
  • Spec for internal tooling: If the conclusion is "adopt the pattern, not the package," this becomes the requirements document for an internal trait/base class — a small, well-scoped backlog item. The v4.2.0 changelog also tells us the maintenance surface of that internal trait: an attribute plus a PHPUnit-extension hook, re-validated each time PHPUnit ships a major.
  • Explicitly not a driver of: user-facing features or product roadmap. This is strictly a developer-productivity and quality lever.

When to Consider This Package

Adopt (or copy the pattern) when:

  • The codebase runs PHP 8.1+ and PHPUnit 10–13, and the package's supported PHPUnit range matches yours (v4.2.0 explicitly adds PHPUnit 13.0 to the matrix — verify the exact range in composer.json before committing).
  • You are on, or planning, a PHPUnit major upgrade: v4.2.0 is evidence of a maintainer who tracks upstream majors, which materially lowers the "abandoned dependency" risk that dominated the prior assessment.
  • Multiple tests genuinely need to vary global/superglobal state per test, and today that logic is scattered across setUp() methods and individual test bodies.
  • The team already uses attributes for test configuration and values consistency.
  • Scope is test-only: a defect produces a wrong test, not a production incident.

Look elsewhere (or vendor/reimplement) when:

  • PHPUnit built-ins suffice: #[BackupGlobals], #[RunInSeparateProcess], or explicit setUp()/tearDown() already cover the cases. Prefer the framework's own mechanism.
  • Dependency posture is conservative: still a single maintainer and low downstream adoption. v4.2.0 improves the maintenance signal but does not change the ecosystem validation signal — there is still little third-party proof it survives real-world suite churn. If policy requires N dependents or org-backed maintenance, this still fails.
  • The need is small: two or three globals is a ~30-line trait. Own the upgrade path instead — though note that owning it means owning PHPUnit-major churn yourself, which is precisely what v4.2.0 just absorbed for us.
  • The real fix is refactoring: making config an explicit dependency of the code under test removes the global state entirely; this package makes globals manageable, not absent.
  • Suite scale is large: attribute reflection on every test has measurable cost across thousands of tests — benchmark before broad adoption.
  • You are pinned below PHPUnit 10: confirm the v4.x line's floor; the newly widened ceiling doesn't help older suites.

How to Pitch It (Stakeholders)

To executives: This is a small MIT-licensed developer-productivity utility for our PHP test suite. It lets engineers declare global test variables in one readable line instead of mutating global state by hand, which means fewer flaky, order-dependent tests, less boilerplate, and a smoother path through our PHP/PHPUnit upgrades. The newly released v4.2.0 adds compatibility with PHPUnit 13, which is a meaningful signal: the maintainer is actively tracking upstream PHPUnit majors, so this dependency is less likely to strand us mid-upgrade than its size suggests. The remaining risk is unchanged — one maintainer and little downstream adoption, so it is not battle-tested by the ecosystem. Recommendation: treat this as a pattern decision rather than a product purchase. Either adopt it pinned/vendored with a scheduled review at each PHPUnit major, or implement the equivalent internally in under a day and accept that we then own that upgrade churn. Direct cost is negligible; the decision should hinge on whether our dependency policy tolerates single-maintainer test-only libraries that demonstrate active maintenance.

To engineering: The package gives declarative, per-test control of $GLOBALS and superglobals through PHP attributes, replacing ad-hoc setUp() mutations and making a test's environmental assumptions visible at the top of the class. It fits naturally if we're already attribute-driven. v4.2.0 only widens the supported PHPUnit range to include 13.0 — no API or behavioral changes are called out, so it should be a drop-in minor bump with low upgrade cost. Caveats that still stand: pin the version and confirm the supported PHPUnit range in composer.json matches ours; reflection overhead is real at suite scale; and #[BackupGlobals] or an internal trait may cover most of the need. My ask is unchanged, with one adjustment: run the one-hour spike comparing this against a ~30-line internal trait, but now explicitly factor in the recurring cost of re-validating that trait against each new PHPUnit major — v4.2.0 is one concrete data point that the package absorbs that cost for us. Then standardize the winner and document it in our testing guidelines.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums