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+.
fake() for services, spy() for method calls).mockery/mockery (v2+). The "spying" feature does not integrate with Laravel’s spy() helper or Pest PHP’s spies.Mockery::mock()->shouldReceive()->andReturn(), PHPUnit::spy(), or fake()) already provide spying functionality without legacy constraints. The package offers no unique value for Laravel projects.// Laravel-native spy (preferred)
$spy = Spy::spy(CallableClass::class);
Event::spy(), middleware spying via app()->instance()).Spy class.Spy class or PHPUnit’s spy() but with higher technical debt?Event::spy() or fake()?spy() helper) that achieve the same goal without legacy constraints?mockery/mockery (v2+).Spy class or Pest PHP’s spies.Spy class (via Illuminate/Foundation/Testing) provides equivalent spying:
$spy = Spy::spy(CallableClass::class);
$spy->shouldHaveReceived('__invoke');
spy() method:
$spy = $this->spy(CallableClass::class);
Spy class or PHPUnit’s spy().Spy::spy() or $this->spy().fake() for service spying (e.g., events, queues).assertSpyCalled() or shouldHaveReceived() for assertions.mockery/mockery:1.4.4 and use a composer.json override (same risks as before). The spying feature does not justify this path.Event::spy() instead of mocking closures.app()->instance() or partialMock().Spy objects or Laravel’s spy() helper.Spy::spy() or PHPUnit’s spy().fake() or spy() helpers.Spy class) evolve rapidly.| 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. |
Spy::spy().Spy class for spying.spy() method.How can I help you explore Laravel packages today?