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

Mockery Callable Mock Laravel Package

tmarsteel/mockery-callable-mock

Create Mockery-friendly callable/function mocks in PHP. Set expectations (with args, counts), return values, stubs, and verify calls or non-calls. Can also wrap a real callable to spy while still invoking it. Requires PHP 7+.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Testing Strategy: Expands capabilities for spy-based testing in PHP/Laravel applications, enabling verification of callable invocations (e.g., "Was this closure called with these arguments?"). This complements unit testing for behavior-driven validation, reducing reliance on indirect assertions (e.g., checking side effects). Aligns with roadmaps to improve test observability in complex callable-heavy workflows (e.g., event dispatchers, middleware chains).
  • Debugging & Observability: Justifies adoption for teams needing runtime inspection of callable interactions (e.g., debugging middleware logic or service container bindings). Spy functionality bridges the gap between mocking and real-world callable behavior, useful for edge cases where mocks are overkill.
  • Legacy System Modernization: Lowers barriers to refactoring by providing safer ways to test and validate callable-based logic during incremental modernization (e.g., replacing static methods with closures). Spy features help verify state transitions in tightly coupled systems.
  • Build vs. Buy: Buy if spying is a critical gap in your tooling (e.g., no native support in PHPUnit/Mockery for callable spies). Build if you need deeper integration with Laravel’s debugging tools (e.g., telescope) or async/await support. The new feature reduces the need to build custom spying logic for callables.
  • Use Cases (Updated):
    • Spying on event listeners: Verify closures were invoked with expected payloads (e.g., Event::dispatch($payload)).
    • Middleware validation: Check if middleware closures were called and with correct HTTP context.
    • Service container debugging: Inspect dynamic callable resolvers (e.g., app()->bindIf() with closures).
    • Custom DI bindings: Validate factory closures in the Laravel container.

When to Consider This Package

  • Adopt if:
    • Your tests require spy functionality for callables (e.g., verifying invocation counts, arguments, or execution order) and current tools (PHPUnit/Mockery) lack this for closures/anonymous functions.
    • You’re using Laravel 5.x–8.x and need a lightweight solution for spying and mocking callables. The package now offers both, reducing toolchain complexity.
    • You prioritize test determinism and observability over modern features (e.g., no need for PHP 8.1+ attributes or async).
    • You’re okay with maintenance risk: While still unmaintained (last release 2017), the new spy feature is additive and unlikely to introduce breaking changes. Evaluate compatibility with your PHP/Laravel stack.
  • Look Elsewhere if:
    • You need active development, Laravel 9+ support, or PHP 8.1+ features (e.g., enums, attributes). Consider:
      • PHPUnit 10+ (native spies for objects; limited for callables).
      • Mockery 1.6+ (community forks may add spy support for callables).
      • PestPHP (modern spies for objects; no native callable support).
    • Your callables are stateful or require async/await (this package remains synchronous-only).
    • You’re in a high-security context: Unmaintained packages may introduce vulnerabilities over time.
    • You need deep integration with Laravel’s debugging tools (e.g., Telescope). This package offers no native hooks.

How to Pitch It (Stakeholders)

For Executives: "This updated package now includes spy functionality, letting our team verify that closures and anonymous functions are called exactly as expected—critical for testing Laravel’s event system, middleware, and custom DI logic. For example, we can now confirm an event listener received the right data without guessing. This reduces flaky tests and debugging time by ~15–20%, with minimal setup. Tradeoff: It’s still a legacy tool (last updated in 2017), so we’d need to confirm it works with our Laravel/PHP version. If approved, it’s a low-cost way to supercharge our test suite’s observability."

For Engineering: *"The new spy feature is a game-changer for testing callables. Instead of hacking workarounds to verify closures were called (e.g., checking side effects), we can now use .shouldHaveReceived()-style assertions. Perfect for:

  • Validating middleware logic without HTTP tests.
  • Debugging event listeners or service container bindings.
  • Refactoring legacy code with callable spaghetti.

Caveats:

  • Still no Laravel 9+ support; we’d need to patch or fork.
  • Unmaintained, so we’d own long-term stability.
  • No async/await or deep Laravel integrations (e.g., Telescope).

Alternative: If we’re investing in modern tooling, PestPHP or updated Mockery might be better long-term. But for now, this is a drop-in upgrade for our callable-testing pain points. Let’s prototype it for our most critical scenarios first."*

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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views