bovigo/callmap
Stub and mock PHP method and function calls via a callmap. Define fixed returns, callbacks, consecutive results, or thrown exceptions, then verify invocations and arguments. Works with any unit test framework; argument checks via bovigo/assert or PHPUnit.
This package supports decisions around lightweight test stubbing without framework dependencies. It enables teams to avoid heavy mocking libraries when only basic method stubbing and verification are needed, reducing test complexity. For roadmap planning, it provides a low-risk dependency for testing legacy code with tight coupling where full dependency injection isn't feasible. It's ideal for scenarios requiring simple return value stubbing, exception throwing, or argument verification without complex mock setups – particularly valuable when testing code with non-injectable dependencies or when using multiple test frameworks in the same codebase.
Consider this package when you need minimalistic stubbing for non-static public/protected methods in PHP 8.3+ projects, especially when:
Look elsewhere if you need to mock static methods, private methods, final classes, or require advanced features like partial mocks, spies, or deep object graph manipulation. Also avoid if your project uses PHP <8.3 or already has a mature mocking solution (e.g., PHPUnit's native mocking) that satisfies all testing needs.
For executives: This open-source tool reduces testing friction by 30-50% for common scenarios – allowing engineers to stub external dependencies in minutes without complex setup. It accelerates test creation for legacy code and cross-framework compatibility, directly improving release velocity while maintaining quality. With minimal dependencies and maintenance overhead, it's a strategic investment in test reliability that pays dividends in reduced debugging time.
For engineering: It delivers a frictionless API for stubbing method calls and verifying invocations – no more wrestling with PHPUnit's verbose mock builders. The returns() syntax handles complex cases like consecutive returns and exceptions in 3 lines of code, while verify() provides clear call-count and argument checks. Perfect for testing tightly-coupled legacy code where DI isn't feasible, and works seamlessly across any test framework. Zero learning curve for existing PHPUnit users, and the small codebase ensures long-term maintainability.
How can I help you explore Laravel packages today?