dg/bypass-finals
DG\BypassFinals lets you bypass PHP’s final classes and methods at runtime so you can mock, extend, or patch code that’s otherwise locked down—useful for testing legacy dependencies. Lightweight, Composer-ready, and works with popular test frameworks.
final classes/methods in vendor libraries (e.g., Symfony, Laravel core, or legacy codebases) without forking or refactoring, directly supporting testability as a non-functional requirement.final constructs in integration tests, reducing false negatives in pipelines and improving release velocity.eval() hacks or test-specific code branches) that introduce technical debt and maintenance overhead.final keywords from legacy code, aligning with strategic debt reduction.final classes in Laravel’s core (e.g., Illuminate\Foundation\Application) or third-party packages (e.g., spatie/laravel-permission).final methods in payment gateways (e.g., Stripe SDK) or authentication providers during unit testing.final classes block dependency injection in tests.final classes/methods in vendor code or legacy systems, preventing mocking or dependency injection.final, making them untestable without this tool.final keywords.final constructs are causing regression risks or delayed releases.final keywords via clean code reviews or PRs, prioritize that over runtime bypasses (this package is a temporary solution).readonly properties in PHP 8+).final dependencies.*"This package resolves a critical bottleneck in our testing pipeline: unmockable final classes in third-party libraries and legacy code are blocking test coverage for key integration points. By enabling mocking without altering vendor code, we can:
*"This solves a painful but common problem: testing code that depends on final classes (e.g., Symfony’s Request, Laravel’s Application, or vendor SDKs). Here’s how we’ll use it:
composer.json as a dev dependency and configure it in phpunit.xml or tests/bootstrap.php.final classes like any other, e.g., $mock = $this->createMock(FinalClass::class).final keywords, this lets us test today and clean up later.
Tradeoff: Minimal CI overhead (~5–10% slower tests) for unblocked test coverage—worth it for critical paths."**"Key considerations:
testing).final behavior differing from production).readonly quirks), we’ll reassess.final dependencies in phases.
Proposal: Pilot with 1–2 high-impact test suites (e.g., payment gateway integration) before rolling out broadly."*How can I help you explore Laravel packages today?