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

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The package remains highly niche, targeting unit testing scenarios where callable objects (closures, anonymous functions, or callable classes) must be mocked or spied. The new "spying" feature (v2.1.0) adds marginal utility for tracking callable invocations but does not address Laravel’s modern testing paradigms (e.g., fake() for services, spy() for method calls).
  • Laravel Compatibility: Still misaligned with Laravel’s testing ecosystem. The package’s reliance on Mockery v1.x (deprecated) conflicts with Laravel’s default mockery/mockery (v2+). The "spying" feature does not integrate with Laravel’s spy() helper or Pest PHP’s spies.
  • Modern Alternatives: Laravel’s built-in tools (e.g., Mockery::mock()->shouldReceive()->andReturn(), PHPUnit::spy(), or fake()) already provide spying functionality without legacy constraints. The package offers no unique value for Laravel projects.

Integration Feasibility

  • Dependency Conflicts: Unchanged. The package still requires Mockery v1.x, which is incompatible with Laravel 8+. The "spying" feature does not resolve this core conflict.
  • Testing Framework Lock-in: Forces Mockery over PHPUnit or Laravel’s native tools, limiting flexibility. The spying feature is redundant for Laravel users who can leverage:
    // Laravel-native spy (preferred)
    $spy = Spy::spy(CallableClass::class);
    
  • Laravel-Specific Gaps: The spying feature does not address Laravel’s testing patterns (e.g., event spying via Event::spy(), middleware spying via app()->instance()).

Technical Risk

  • Security Risk: Mockery v1.x remains vulnerable to CVEs (e.g., CVE-2019-11043). The new feature does not mitigate this.
  • Maintenance Overhead: The package is still abandoned (last release: 2017, with v2.1.0 likely a stale update). No Laravel version support or bug fixes exist.
  • Testing Fragility: Spying on closures in Laravel often fails due to serialization scope issues. The package does not adapt to Laravel’s container or testing helpers.
  • Performance Impact: Mockery’s reflection-based spying is slower than PHPUnit’s native spies or Laravel’s optimized Spy class.

Key Questions

  1. Why adopt a spying feature that replicates Laravel’s Spy class or PHPUnit’s spy() but with higher technical debt?
  2. What specific use case requires spying on closures that cannot be solved with Event::spy() or fake()?
  3. Is the spying feature tested with Laravel’s service container (e.g., spying on closures in middleware or event listeners)?
  4. What is the migration path if this package is adopted today? (Answer: None—it remains unsustainable.)
  5. Are there modern alternatives (e.g., Pest PHP’s spies, Laravel’s spy() helper) that achieve the same goal without legacy constraints?

Integration Approach

Stack Fit

  • PHP/Laravel Version Compatibility:
    • Still incompatible with Laravel 8+. The spying feature does not resolve the Mockery v1.x dependency.
    • Forced downgrade to Laravel 5.x or PHP 7.1 remains the only option, which is not recommended.
  • Testing Stack:
    • Mockery v1.x is still the only supported version, conflicting with Laravel’s default mockery/mockery (v2+).
    • No integration with Laravel’s Spy class or Pest PHP’s spies.
  • Alternatives in Stack:
    • Laravel’s Spy class (via Illuminate/Foundation/Testing) provides equivalent spying:
      $spy = Spy::spy(CallableClass::class);
      $spy->shouldHaveReceived('__invoke');
      
    • PHPUnit’s spy() method:
      $spy = $this->spy(CallableClass::class);
      

Migration Path

  1. Assessment Phase:
    • Audit test files using this package to identify spying dependencies.
    • Replace with Laravel’s Spy class or PHPUnit’s spy().
  2. Incremental Replacement:
    • Step 1: Replace spying on callables with Spy::spy() or $this->spy().
    • Step 2: Migrate to fake() for service spying (e.g., events, queues).
    • Step 3: Use assertSpyCalled() or shouldHaveReceived() for assertions.
  3. Fallback (Not Recommended):
    • If absolutely necessary, pin mockery/mockery:1.4.4 and use a composer.json override (same risks as before). The spying feature does not justify this path.

Compatibility

  • Laravel Services:
    • Event Listeners: Use Event::spy() instead of mocking closures.
    • Middleware: Spy via app()->instance() or partialMock().
    • Callbacks: Replace with Spy objects or Laravel’s spy() helper.
  • Third-Party Packages:
    • If other packages rely on this, refactor them to use modern spying tools or report the issue upstream.

Sequencing

  1. Phase 1 (Low Risk):
    • Replace spying on callables with Spy::spy() or PHPUnit’s spy().
  2. Phase 2 (Medium Risk):
    • Update tests using this package to use Laravel’s fake() or spy() helpers.
  3. Phase 3 (High Risk):
    • Only if unavoidable: Isolate the package in a separate test suite with pinned dependencies (not recommended for production).

Operational Impact

Maintenance

  • Deprecation Risk: The package remains abandoned, with no future updates. Laravel’s testing tools (e.g., Pest PHP, native Spy class) evolve rapidly.
  • Dependency Bloat: Forces maintenance of an unsupported Mockery version, increasing CI/CD complexity. The spying feature does not reduce this burden.
  • Documentation Gap: No modern guides or Laravel-specific documentation for the spying feature.

Support

  • Debugging Challenges:
    • Errors from Mockery v1.x will not align with Laravel’s error handling. The spying feature adds no diagnostic improvements.
    • Stack traces remain incomprehensible due to version mismatches.
  • Community Support:
    • No active maintainer or Laravel-specific documentation. The spying feature is unlikely to receive updates or fixes.

Scaling

  • Test Suite Bloat:
    • Mockery v1.x’s spying is slower than modern alternatives, increasing test execution time.
    • Large test suites may hit memory limits due to reflection overhead.
  • Team Onboarding:
    • New developers will struggle with legacy Mockery patterns. The spying feature does not align with Laravel’s testing conventions.
    • No clear path to migrate to modern tools (e.g., Pest PHP).

Failure Modes

Failure Scenario Impact Mitigation
Laravel upgrade (v8+) Breaks due to Mockery v2+ requirement. The spying feature does not resolve this. Avoid adoption; migrate to Spy::spy().
Mockery v1.x security vulnerability Exposes project to CVEs. The spying feature adds no security patches. Block via composer.json restrictions.
Test flakiness Spying on closures fails due to serialization issues in Laravel’s container. Use fake() or Spy::spy() instead.
CI/CD pipeline breaks Mockery version conflicts persist in test environments. Isolate in a separate test container (not recommended).
Developer turnover Knowledge of legacy Mockery patterns becomes a bottleneck. Document migration path; train team on Spy class.

Ramp-Up

  • Learning Curve:
    • Developers must unlearn Laravel’s testing patterns to use this package’s spying feature.
    • No ROI: The feature adds zero value over existing tools like Spy::spy().
  • Onboarding Costs:
    • 1-2 weeks to assess and replace usage (if any).
    • Ongoing cost to maintain an unsupported dependency.
  • Recommended Approach:
    • Do not adopt. Instead, invest time in:
      • Laravel’s Spy class for spying.
      • Pest PHP for expressive testing.
      • PHPUnit’s native spy() method.
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