Weave Code
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 Polyfills Laravel Package

yoast/phpunit-polyfills

Polyfills to write PHPUnit tests compatible across versions. Provides traits, test cases, and utilities that bridge API changes so one test suite can run on PHPUnit 7.5–9 and 11–12. Requires PHP 7.1+.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit: The package is designed as a non-intrusive test-only dependency. It uses PHP traits and TestCase extensions to polyfill PHPUnit functionality without modifying application code. This aligns perfectly with test infrastructure needs and avoids production code contamination. The conditional loading mechanism ensures minimal runtime impact when polyfills aren't needed.

Integration feasibility: High. Composer-based installation with straightforward autoloading requirements. Existing test suites can incrementally adopt polyfills via trait usage or by switching to the provided TestCase class. No significant code restructuring required beyond standard test updates.

Technical risk: Moderate. Known edge cases exist for resource assertions (PHP bugs affecting closed resource checks) and version-specific limitations (e.g., 4.x series excludes PHPUnit 10). While CI pipelines and test coverage are robust, untested combinations of PHPUnit versions and custom test setups could surface issues. Polyfills for removed features (e.g., expectExceptionMessageRegExp()) may behave unexpectedly if dependencies aren't properly version-constrained.

Key questions:

  • How will the team handle PHPUnit version upgrades when polyfills become unnecessary (e.g., when dropping support for older PHPUnit versions)?
  • Are there custom test extensions or third-party PHPUnit plugins that might conflict with polyfill implementations?
  • What is the plan for features deprecated in newer PHPUnit versions that aren't covered by the polyfills (e.g., PHP 8.2+ deprecations)?

Integration Approach

Stack fit: Ideal for any PHP project using PHPUnit for testing, including Laravel applications. Works seamlessly with standard test bootstrapping and composer autoloading. No framework-specific dependencies beyond PHPUnit itself.

Migration path:

  1. Add as --dev dependency via Composer
  2. Replace deprecated PHPUnit methods in tests with polyfill equivalents (e.g., assertContainsOnlyBool() instead of assertContainsOnly('bool', $array))
  3. Gradually migrate existing test classes to use the provided TestCase base class where practical
  4. Remove polyfills entirely after upgrading to a PHPUnit version that natively supports all required features

Compatibility: Requires careful version alignment:

  • PHPUnit 7.5–12.x → Use ^4.0 of the polyfills
  • Avoid mixing polyfills version with unsupported PHPUnit versions (e.g., 4.x polyfills exclude PHPUnit 10)
  • Works with all standard PHPUnit test structures but may require adjustments for custom test runners or third-party extensions

Sequencing:

  • Phase 1: Install polyfills and update new tests to use polyfill methods
  • Phase 2: Refactor legacy tests incrementally during feature work
  • Phase 3: Validate across all supported PHPUnit versions via CI matrix testing
  • Phase 4: Remove polyfills after upgrading to a PHPUnit version where all polyfilled features are natively supported

Operational Impact

Maintenance: Low ongoing effort. The package is actively maintained with CI pipelines, semantic versioning, and clear changelogs. Teams only need to update when adding new PHPUnit features or upgrading PHPUnit versions. No production deployment dependencies.

Support: Strong community backing with Yoast's maintenance history. GitHub issues are actively monitored with detailed documentation. Support burden shifts to the package maintainers for polyfill-specific issues.

Scaling: Zero impact on application performance or scalability. Only affects test execution speed (negligible overhead for trait loading). Test suite size and parallelization remain unaffected.

Failure modes:

  • Incorrect polyfill behavior for edge cases (e.g., resource assertions failing due to PHP bugs)
  • Version mismatch between polyfills and PHPUnit causing silent failures
  • Test failures when using unsupported PHPUnit versions (e.g., 10.x with 4.x polyfills)
  • Custom test helpers conflicting with polyfill trait methods

Ramp-up: Minimal learning curve. Developers only need to understand which polyfill traits to use for specific PHPUnit methods. Documentation provides clear usage examples and version compatibility tables. Existing PHPUnit knowledge transfers directly with minor syntax adjustments.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation