phpunitgoodpractices/polyfill
Polyfill library for PHPUnit best practices, providing compatibility helpers and shims to keep test suites consistent across PHPUnit versions. Useful for package maintainers aiming for cleaner, more portable tests without forcing specific PHPUnit upgrades.
Install via Composer:
composer require --dev phpunitgoodpractices/polyfill
No configuration is required. Once installed, polyfills are auto-loaded via Composer’s autoloader — just run phpunit and they activate automatically in the test environment. Start by using newer PHPUnit features (e.g., assertDoesNotAssertAnything() or modern string assertion helpers) in tests; if running on older PHP/PHPUnit versions, the polyfill ensures they work consistently. First use case: write a test using assertArrayNotHasKey() on PHP 7.1 — it will still pass if the polyfill is loaded, even though that method was added in PHPUnit 9.1.
autoload-dev in its composer.json, so it only loads during test runs — zero impact on production. Ideal for libraries targeting PHP 7.4–8.2+ with varying PHPUnit versions.assertJsonStringEqualsJsonString()) or expectations (e.g., expectsOutputFromInput()) without version guards.php:8.0 + phpunit/phpunit:^9 and php:7.4 + phpunit/phpunit:^8) to unify test behavior. No more “works on PHP 8, breaks on 7.4” noise.PHPUnit\Framework or global namespace as appropriate. Ideal for legacy codebases upgrading gradually.composer require phpunitgoodpractices/polyfill:^1.3 and test edge cases).src/ to see exactly which symbols it injects (e.g., assertStringContainsString, assertStringEndsNotWith, assertJsonStringEqualsJsonString).require-dev misconfiguration), PHP will throw a fatal error on double declaration — use --no-dev in production builds.phpunit --filter TestName --verbose and inspect autoloader output via composer dump-autoload --dev -v to confirm polyfill classes are loaded.str_starts_with() for PHP < 8), then replace via repositories in composer.json.How can I help you explore Laravel packages today?